bool NeHeLoadBitmap(LPTSTR szFileName, GLuint &texid, GLuint params1, GLuint params2) // Creates Texture From A Bitmap File
{
HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure
glGenTextures(1, &texid); // Create The Texture
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if (!hBMP) // Does The Bitmap Exist?
return FALSE; // If Not Return False
GetObject(hBMP, sizeof(BMP), &BMP); // Get The Object
// hBMP: Handle To Graphics Object
// sizeof(BMP): Size Of Buffer For Object Information
// &BMP: Buffer For Object Information
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // Pixel Storage Mode (Word Alignment / 4 Bytes)
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texid); // Bind To The Texture ID
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, params1); // Linear Min Filter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, params2); // Linear Mag Filter
if(params1 == GL_LINEAR_MIPMAP_NEAREST || params2 == GL_LINEAR_MIPMAP_NEAREST)
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_RGB, GL_UNSIGNED_BYTE, BMP.bmBits);
else
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, BMP.bmBits);
DeleteObject(hBMP); // Delete The Object
return TRUE; // Loading Was Successful
}
bool LoadGLTextures() {
if (!NeHeLoadBitmap("Data/Crate.bmp", texture[0], GL_NEAREST, GL_NEAREST)) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE ( NEW )
}
if (!NeHeLoadBitmap("Data/Crate.bmp", texture[1], GL_LINEAR, GL_LINEAR)) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE ( NEW )
}
if (!NeHeLoadBitmap("Data/Crate.bmp", texture[2], GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST)) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE ( NEW )
}
return true;
}
🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Texture Problems in Lesson 7
So, I have a silly texture problem which is best shown by a screen cap, eh? So here it is.
Here's one face of the cube. Notice the psychedelic color scheme and the fact that the texture repeats, and only on a small part of it? ugh! :)
Link to Image
I am using mostly the glaux replacement code I downloaded recently from nehe.gamedev.net
Here is some source...
I love these tutorials and would appreciate any attention I could get regarding this embarrassing texture problem.
Z
Okay, so I think my problem basically was that the image was an 8 bit color image that the glaux replacement code wasn't very fond of. Plus, the bits that I was passing into the mipmapping and 2d texture functions were expecting a BGR format (since the bitmap loader was little endian).
soooo I wrote my own loading function which took into account that it was 8 bit, found the palette, and made a 24 bit big-endian RGB bottom row to top row bitfield to pass into these functions, and wallah! it works, the image looks great, yaddah yaddah yaddah.
However, if I used this code to load a lot of bitmaps, I imagine it would be quite slow. Is there hardware accelerated support for turning color indexed bitfields into truecolor bitfields that are big-endian? How would that look?
Anyway, the replacement code needs a lot of help if lesson 7 is going to throw curveballs with 8 bit images that the code doesn't work well with. (unless I was just doing something horribly wrong).
Z
soooo I wrote my own loading function which took into account that it was 8 bit, found the palette, and made a 24 bit big-endian RGB bottom row to top row bitfield to pass into these functions, and wallah! it works, the image looks great, yaddah yaddah yaddah.
However, if I used this code to load a lot of bitmaps, I imagine it would be quite slow. Is there hardware accelerated support for turning color indexed bitfields into truecolor bitfields that are big-endian? How would that look?
Anyway, the replacement code needs a lot of help if lesson 7 is going to throw curveballs with 8 bit images that the code doesn't work well with. (unless I was just doing something horribly wrong).
Z
I guess the code was designed to load simple bmp images, probably not 8bit palette ones.
If it works with your code then you probably did the right thing [wink], if you want to have an easy to use alternative for loading any kind of texture try SOIL a Simple OpenGL Image Library.
Cheers
If it works with your code then you probably did the right thing [wink], if you want to have an easy to use alternative for loading any kind of texture try SOIL a Simple OpenGL Image Library.
Cheers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement