• Advertisement

Archived

This topic is now archived and is closed to further replies.

I have problem using more than 1 texture

This topic is 6000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ! I''m quite new to openGL and I want to apply 2 textures on a cube. But it seems the second textures I load overwrite the first one and my cube is half white and half textured when I render it. this is my code where I load the 2 textures : if( !LoadTexture( "metal.bmp", m_tabTexture[0] ) ) { return false; } if( !LoadTexture( "space.bmp", m_tabTexture[1] ) ) { return false; } And this is my LoadTexture() Function : bool C3DObject::LoadTexture( string strFileName, GLuint &objTexture ) { int Status = FALSE; AUX_RGBImageRec* ptrTextureImage = NULL; FILE* ptrFile = NULL; ptrFile = fopen( strFileName.c_str(), "r" ); if( ptrFile ) { fclose( ptrFile ); ptrTextureImage = auxDIBImageLoad( strFileName.c_str() ); } if( ptrTextureImage ) { glGenTextures(1, &objTexture); glBindTexture(GL_TEXTURE_2D, objTexture); glTexImage2D(GL_TEXTURE_2D, 0, 3, ptrTextureImage->sizeX, ptrTextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, ptrTextureImage->data); } if( ptrTextureImage ) { if( ptrTextureImage->data ) { free( ptrTextureImage->data ); } free( ptrTextureImage ); } return true; } And I render my cube this way : glBindTexture(GL_TEXTURE_2D, GetTexture(0)); glBegin(GL_QUADS); // Front Face glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face glNormal3f( 0.0f, 0.0f,-1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Face glNormal3f( 0.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, GetTexture(1)); glBegin(GL_QUADS); // Bottom Face glNormal3f( 0.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face glNormal3f( 1.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Left Face glNormal3f(-1.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); So as I said only the second texture ( space.bmp ) is rendered correctly. The other one is all white I tried them alone and both of them is rendered correctly but If I try to put both texture on the cube it doesn''t work. Help please. Hope My problem is clear. Thanks alot !

Share this post


Link to post
Share on other sites
Advertisement
You probably think I want to use multiple textures for blending on a same face
But what I want to do is draw a texture on 3 faces and another texture on the other 3 faces of the cube
Can you help ? someone ? hehe

Share this post


Link to post
Share on other sites
Try changing declaration of LoadTexture function
from LoadTexture(string strFileName, GLint &objtexture) to
LoadTexture(string strFileName, GLint objTexture). Maybe this will help.

K.

Share this post


Link to post
Share on other sites

  • Advertisement