glGenerateMipmap is showing no texture

Hi I wanted to put a texture on a cube, so I used this:

My load function:


void LoadTEX()
{	
	unsigned int texture;  
	HBITMAP GLtex;
	BITMAP tex;
	byte Texture=TEX;

	GLtex= (HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(Texture), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
	GetObject(GLtex,sizeof(tex), &tex);
	glGenTextures(1, &texture);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, tex.bmWidth);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	glBindTexture( GL_TEXTURE_2D, texture );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.bmWidth, tex.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
	glActiveTexture(GL_TEXTURE0);
	glGenerateMipmap(GL_TEXTURE_2D);
	// gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, tex.bmWidth, tex.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
	DeleteObject(GLtex);		
}

My display function:


		 glEnable(GL_TEXTURE_2D);
		 glBindTexture( GL_TEXTURE_2D, texture );
		 drawTexObject();

If I uncomment gluBuild2DMipmaps and comment glGenerateMipmap the texture is on the cube. Why this what I’am trying is not working with GenerateMinimap ? The window is not even shown. I just can’t work out this.

The texture is loaded from resource file and it is a BMP 512x512 24bpp BGR. I got OpenGL 3.1 support on ATI card.

hi,

i can´t give the propper answer right now, but 2 things.

  1. whenever you have a opengl call not working as expected: check for glErrors !!! It really helps so mutch
extern void CheckGLErrors( int x )
{
  GLenum err ;
 
  while ( (err = glGetError()) != GL_NO_ERROR )
    fprintf( stderr, "
 %i ) OpenGL Error : %i ,  %s
", x ,err,  gluErrorString ( err ) );
};
  1. You should just rearrange your code… that may help, some stuff is nit needed there:

void LoadTEX() 
{
         unsigned int texture;
         HBITMAP GLtex;
         BITMAP tex;
         byte Texture=TEX;
         GLtex= (HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(Texture), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
         GetObject(GLtex,sizeof(tex), &tex);

     glGenTextures(1, &texture);
     glPixelStorei(GL_UNPACK_ROW_LENGTH, tex.bmWidth);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
     glBindTexture( GL_TEXTURE_2D, texture );

     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.bmWidth, tex.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);

     glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
     glGenerateMipmap(GL_TEXTURE_2D);

     // gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, tex.bmWidth, tex.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
     DeleteObject(GLtex);
  }

hope you find it…