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.