I have problem using more than 1 texture

Started by
2 comments, last by Evil-Dog 22 years, 8 months ago
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 !
Programmer :Device that converts caffeine into code.
Advertisement
Hey, you have to use multitexturing (NeHe has a tutorial on it over at http://nehe.gamedev.net), so go check it out..... NOW!

------------------------------
Trent (ShiningKnight)
E-mail me
Shining Darkness- A division of Chromesphere Studios
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
Programmer :Device that converts caffeine into code.
Try changing declaration of LoadTexture function
from LoadTexture(string strFileName, GLint &objtexture) to
LoadTexture(string strFileName, GLint objTexture). Maybe this will help.

K.

This topic is closed to new replies.

Advertisement