Jump to content
  • Advertisement
Sign in to follow this  
Antonym

OpenGL Error Creating Texture

This topic is 3086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have two textures NeHe.bmp and Crate.bmp, the only difference I could notice between the two is that in photoshop (RGB/8) is appended to the name of Nehe.bmp while (Index) to Crate.bmp. I've used the following piece of code with both but I get an error at gluBuild2DMipmaps with Crate.bmp. I am new to OpenGL and loading textures and am trying to follow Nehe's Lesson 7 without rellying on glaux.

Any help is much appreciated.



bool NeHeLoadBitmap(LPTSTR szFileName, GLuint &texid) // Creates Texture From A Bitmap File
{
HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

glGenTextures(3, &texture[0]); // 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)

// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW )
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW )
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

// Create Linear Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW )
//ERROR
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits); // ( NEW )

DeleteObject(hBMP); // Delete The Object

return TRUE; // Loading Was Successful
}


Share this post


Link to post
Share on other sites
Advertisement
If Photoshop is putting (Index) after the name of crate.bmp instead of (RGB/8) it must mean that the image is not in RGB format, but rather it has a palette. This will mean that you either have to convert the image data to RGB in your program, or tell OpenGL you're using a different pixel format. Although I'm sure I read today somewhere that OpenGL doesn't support palette textures.

In reality, the easiest option is probably to save it as an RGB/8 bitmap using Photoshop, requiring no change to your code.

Sorry if this is badly worded/unclear. It's 5:30am...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!