PDA

View Full Version : Can't get rid of gluBuild2DMipmaps (solved)



Mr.Byteside
08-25-2010, 05:29 AM
I'm using gluBuild2DMipmaps simply because glTexImage2D does not want to work. I tried everything. I followed this: http://www.opengl.org/wiki/Common_Mistakes

I have 24bpp .bmp in my windows form and load them this way:

GLuint texture[3]; // Storage For 3 Textures

void LoadGLTextures() // Creates Textures From Bitmaps In The Resource File
{
HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

// The ID Of The 3 Bitmap Images We Want To Load From The Resource File
byte Texture[]={ IDB_FONT_NORMAL_1, IDB_FONT_LARGE_1 };

glGenTextures(sizeof(Texture), &texture[0]); // Generate 3 Textures (sizeof(Texture)=3 ID's)
for (int loop=0; loop<sizeof(Texture); loop++) // Loop Through All The ID's (Bitmap Images)
{
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKE INTRESOURCE(Texture[loop]), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
if (hBMP) // Does The Bitmap Exist?
{ // If So...
GetObject(hBMP,sizeof(BMP), &amp;BMP); // Get The Object
// hBMP: Handle To Graphics Object
// sizeof(BMP): Size Of Buffer For Object Information
// Buffer For Object Information
glPixelStorei(GL_UNPACK_ALIGNMENT,4); // Pixel Storage Mode (Word Alignment / 4 Bytes)
glBindTexture(GL_TEXTURE_2D, texture[loop]); // Bind Our Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

// Generate Mipmapped Texture (3 Bytes, Width, Height And Data From The BMP)
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR, GL_UNSIGNED_BYTE, BMP.bmBits);
//glTexImage2D(GL_TEXTURE_2D,0,3,BMP.bmWidth,BMP.bmH eight,0,GL_BGR,GL_UNSIGNED_SHORT,BMP.bmBits);

DeleteObject(hBMP); // Delete The Bitmap Object
}
}
}

Help?

Dark Photon
08-25-2010, 05:40 AM
I'm using gluBuild2DMipmaps simply because glTexImage2D does not want to work.
Nowadays, I believe it is preferrable to use glGenerateMipmapEXT(GL_TEXTURE_2D) instead to tell the driver/GPU to build MIPmaps.

However, let's see how you were trying to populate the MIP levels of the texture via glTexImage2D. Then you won't even need the MIPmap gen.

ZbuffeR
08-25-2010, 05:49 AM
What do you mean "with does not want to work" exactly ?
Why do you want to do without gluBuild2DMipmaps, if you can not find a way to replace it ?
Did you check that bmWidth and bmHeight are within allowed bounds for your hardware ?
Do you check if your hardware accept NPOT textures ?

Read again the documentation about gluBuild2DMipmaps, to be sure to re-implement everything needed :
http://www.opengl.org/sdk/docs/man/xhtml/gluBuild2DMipmaps.xml

ZbuffeR
08-25-2010, 05:50 AM
[quote=Mr.Byteside]However, let's see how you were trying to populate the MIP levels of the texture via glTexImage2D. Then you won't even need the MIPmap gen.

He does not need mipmap gen, as GL_NEAREST is already used for minification filter.

Mr.Byteside
08-25-2010, 06:43 AM
see below

Mr.Byteside
08-25-2010, 06:56 AM
Edit, I found it myself. It was this:

glTexImage2D(GL_TEXTURE_2D,0,3,BMP.bmWidth,BMP.bmH eight,0,GL_BGR,GL_UNSIGNED_SHORT,BMP.bmBits);

To:

glTexImage2D(GL_TEXTURE_2D,0,3,BMP.bmWidth,BMP.bmH eight,0,GL_BGR,GL_UNSIGNED_BYTE,BMP.bmBits);

Sorry, for all the trouble. :(