PDA

View Full Version : Why is my loaded BMP background white?



jiangerlai
03-13-2003, 11:26 PM
My program is as following:
GLuint LoadGLTextures(const char *filename)
{
int status=FALSE;
AUX_RGBImageRec *TextureImage=NULL;
GLuint texture=0;
ZeroMemory(&TextureImage,sizeof(void*)*1);
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if ( TextureImage=LoadBMP( filename ) )
{ status=TRUE;
glGenTextures( 1,&texture);

// Typical Texture Generation Using Data From The Bitmap
glBindTexture( GL_TEXTURE_2D, texture );
glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


if ( TextureImage) {
if (TextureImage -> data) {
free( TextureImage-> data );
};

free( TextureImage);
};

};


glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D,texture);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0f,0.0f,-0.2f);
glBegin(GL_POLYGON);
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -0.6f, -0.5f, 0.5f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 0.6f, -0.5f, 0.5f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 0.6f, 0.5f, 0.5f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -0.6f, 0.5f, 0.5f );
glEnd();
glLoadIdentity();


return texture;


}

AUX_RGBImageRec * LoadBMP(const char *Filename)
{
FILE *File = NULL;
if ( !Filename ) {
return NULL;
};

File = fopen( Filename,"r" );

if ( File ) {
fclose( File );
return auxDIBImageLoad( Filename );
};

return NULL;
}

Deiussum
03-14-2003, 05:32 AM
Do you have an OpenGL context created at the time you call your texture loading routines?

Relic
03-14-2003, 05:39 AM
Are texture sizes powers of two?

jiangerlai
03-14-2003, 05:44 AM
Thank you for your help
I have solved the problem;