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_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, 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?