Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Simple BMP loader doesn't work

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2004
    Posts
    24

    Simple BMP loader doesn't work

    This is how I implemented a simple image loader:
    Code :
    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:
    Code :
    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?

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Simple BMP loader doesn't work

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •