PDA

View Full Version : Simple BMP loader doesn't work



991060
07-20-2004, 12:15 AM
This is how I implemented a simple image loader:

type unsigned int TextureID;
void LoadTexture(const char* filename, TextureID* texture)
{
AUX_RGBImageRec* pTextureImage = auxDIBImageLoad(filename);

if( pTextureImage != NULL )
{
glGenTextures( 1, texture );

glBindTexture(GL_TEXTURE_2D, *texture);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3, pTextureImage->sizeX, pTextureImage->sizeY, 0,
GL_RGB, GL_UNSIGNED_BYTE, pTextureImage->data);
}

if( pTextureImage )
{
if( pTextureImage->data )
free( pTextureImage->data );

free( pTextureImage );
}
}
And to set a texture to a particular texture mapping unit, I use:

void SetTexture(UINT textureUnit, TextureID texture)// tex unit starts from zero
{
UINT targetTexUnit = GL_TEXTURE0_ARB + textureUnit;
glActiveTextureARB( targetTexUnit );
glBindTexture( GL_TEXTURE_2D, texture);
glEnable( GL_TEXTURE_2D );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);

wglGetLastError();
} The SetTexture() function works fine on a texture generated from pbuffer, so I assume it's correct. The problem is that when I want to load a texture from file and use it, the content is completely while dots. I've checked in debug mode, seems the file is loaded(any TextuerID sent into LoadTexture() function will have a non-zero value after the call). What do you think is the problem?

Relic
07-20-2004, 01:56 AM
For texture target GL_TEXTURE_2D the image width and height need to be power of two values.
Min filters set to _MIPMAP_ needs a complete mipmap chain or the texture is inconsistent and the texture unit will be disabled
If you want to auto-generate mipmaps, you need to enable it before you modify the LOD 0 of the texture (i.e. call glTexImage)