PDA

View Full Version : texture mapping using multibitmaps



kashif saeed
05-06-2003, 10:49 PM
hello friends
i am presently workng in opengl application where i am drawing some shapes like triangle etc on a window then using keyboard inerface i am switching to texture mapping that is loading one texture then using another key say "B" i am texture mapping another bitmap. hte problem i am encountring is that when i load my first bitmap using mipmap tchnique and then goes back to my original drawing where i have drawn trianges etc. its ok but when i load 2nd texture to display it on hte screen and goes back to main drwing it makes the draing dull that is it becoes black . i have tried to figure the problem but of no vain. can u help me out
here is small code

opening file .............here


memset(TextureImage,0,sizeof(void *)*2);


then i am loading 2 textures 1.bmp and 2,bmp .

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if ((TextureImage[0]=LoadBMP("1.bmp")) &&
(TextureImage[1]=LoadBMP("2.bmp")))
{
Status=TRUE;

glGenTextures(2, &texture[0]);

for (int loop = 0; loop < 2; loop++)
{
// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
}
}


for (int loop = 0; loop < 2; loop++)
{
if (TextureImage[loop]) // If Texture Exists
{
if (TextureImage[loop]->data) // If Texture Image Exists
{
free(TextureImage[loop]->data); // Free The Texture Image Memory
}

free(TextureImage[loop]); // Free The Image Structure
}
}


in drawing function i am loading texture 1 using following code

GLvoid func1(GLvoid)
{
glTranslatef(0.0f,0.0f,-5.0f);
glColorMaterial(GL_FRONT,GL_AMBIENT);
glBindTexture(GL_TEXTURE_2D, texture[0]); // Select A Texture Based
glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,1.0f);
glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, -1.5f, 1.0f); // Point 1 (Front)
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.5f, -1.5f, 1.0f); // Point 2 (Front)
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.5f, 1.5f, 1.0f); // Point 3 (Front)
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.5f, 1.5f, 1.0f); // Point 4 (Front)
glEnd();
}


similar in another function i am loading second texture

GLvoid func2(GLvoid)
{
glTranslatef(0.0f,0.0f,-5.0f);
glColorMaterial(GL_FRONT,GL_AMBIENT);
glBindTexture(GL_TEXTURE_2D, texture[1]); // Select A Texture Based
glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,1.0f);
glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, -1.5f, 1.0f); // Point 1 (Front)
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.5f, -1.5f, 1.0f); // Point 2 (Front)
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.5f, 1.5f, 1.0f); // Point 3 (Front)
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.5f, 1.5f, 1.0f); // Point 4 (Front)
glEnd();
}


then based upon keyboard events says key input "m" and "s" i switching over to function 1 and 2 respectively
ofcourse main drawing is cleared.
but when i load bitmap 1 and switch back to main drawing its ok the main drawing is same as it has to be bur when
i load bitmap 2.bmp using keyboard input "s" it is loaded but when i goes back to
main drawing the drawing becomes dull that is blackend somewhat. i have tried to load only bitmap 2.bmp but it is
giving me the problem but bitmap 1.bmp is not giving me such problem. using both together makes my main drawing dull
but when i load bitmap 1.bmp and switch back it becomes ok . i think its the problem with bitmap
i am sending bitmaps to u please help me out.

dorbie
05-08-2003, 01:59 PM
OpenGL will continue to texture with the last texture coordinate used until you issue a glDisable for GL_TEXTURE_2D.

I suspect all subsequent geometry just happens to be textured with the texel color at glTexCoord2f(0.0f, 1.0f), because that's the last coordinate you issued. It shows with one and not the other because one texture is white at that location and the other isn't.

For many reasons it is a good idea to disable texturing when you are done with using it.