Skip to main content
gamedev.net
🔒 Locked

texture loading problem

Started by Asuralm Mar 31, 2009 at 7:57 AM 0 replies 750+ views
Original Post
Asuralm
Asuralm
Hi all: I met a problem when I am trying to load the textures. Here is my code:

GLuint	texture[3];		

/// here I use SOIL to load images.
texture[0] = SOIL_load_OGL_texture
            (
             (PICTUREPATH + "snowing.jpg").c_str(),
             SOIL_LOAD_AUTO,
             SOIL_CREATE_NEW_ID,
             SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
            );
    texture[1] = SOIL_load_OGL_texture
            (
             (PICTUREPATH + "office-13.jpg").c_str(),
              SOIL_LOAD_AUTO,
              SOIL_CREATE_NEW_ID,
              SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
            );
    
    texture[2] = SOIL_load_OGL_texture
            (
             (PICTUREPATH + "soft-green.jpg").c_str(),
              SOIL_LOAD_AUTO,
              SOIL_CREATE_NEW_ID,
              SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
            );


The above are the initializations and loading images. The problem occurs at the texture generation step.

/// here comes to the problem
glGenTextures(3, texture);

/// the rest are as usual
// texture 1 (poor quality scaling)
    glBindTexture(GL_TEXTURE_2D, texture[0]);   // 2d texture (x and y size)

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); 

    
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
    
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 


glBindTexture(GL_TEXTURE_2D, texture[0]);   // choose the texture to use.

    glBegin(GL_QUADS);		                // begin drawing a cube
    
    // Front Face (note that the texture's corners have to match the quad's corners)
    glNormal3f( 0.0f, 0.0f, 1.0f);                              // front face points out of the screen on z.
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
    
    // Back Face
    glNormal3f( 0.0f, 0.0f,-1.0f);                              // back face points into the screen on z.
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
	
    glEnd();


So the problem is that if I use glGenTextures(3, texture), then the texture is not probably sticked on the surface. However, it works if I use glGenTextures(0, texture); In this code, I meant to generate 3 textures instead of 0. Although the latter one works, it confused me. Can someone point out the error I made or what's really going on please? Thanks
Asura
HuntsMan
HuntsMan
glGenTextures(n, pointer) creates n texture id's on the array pointed by pointer, so when you call glGenTextures(3, texture), it creates 3 id's, overwriting what was on the array before.

So, then you bind each ID, set filtering parameters, then render. You forgot to specify pixel data with glTexImage2D(), so no texture render, as they're incomplete.

AFAIK, SOIL_load_OGL_texture loads the texture and also creates the ID, so you don't need to create 3 more ids, just load the textures, and bind the ids to render each them.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.