Sign in to follow this  
znanue

Texture Problems in Lesson 7

Recommended Posts

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! :) an image of my texture problem Link to Image I am using mostly the glaux replacement code I downloaded recently from nehe.gamedev.net Here is some source...
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;
}
I love these tutorials and would appreciate any attention I could get regarding this embarrassing texture problem. Z

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this