Jump to content
  • Advertisement
Sign in to follow this  
I_Smell_Tuna

OpenGL Why is my texture tinted blue?

This topic is 4115 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

Okay, I'm working with SDL and OpenGL on Win32 using Dev-C++. I'm trying to alter lesson 31 of the NeHe tutorials because it is designed to only load BMP textures, I want to use SDL_Image so I can load textures of various file types. But when I change the code to use SDL_LoadBMP() or IMG_LOAD() the texture will load, and it looks normal except that its blue. Below is the code, any ideas what I might be doing wrong? The original code...
	AUX_RGBImageRec *pImage;
	pImage = LoadBMP( filename );									// Loads The Bitmap Specified By filename

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if ( pImage != NULL && pImage->data != NULL )					// If Texture Image Exists
	{
		glGenTextures(1, &texture);									// Create The Texture

		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, pImage->sizeX, pImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

		free(pImage->data);											// Free The Texture Image Memory
		free(pImage);												// Free The Image Structure
	}
	return texture;	

New broken code...
	SDL_Surface *img;
	img = SDL_LoadBMP(filename);

	glGenTextures(1, &texture);									// Create The Texture

	glBindTexture(GL_TEXTURE_2D, texture);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB, GL_UNSIGNED_BYTE, img->pixels);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	return texture;

Share this post


Link to post
Share on other sites
Advertisement
I don't use SDL to load my textures but what order does SDL load the color in? RGB or BGR? Not sure if that is the problem but it's a start.

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
I don't use SDL to load my textures but what order does SDL load the color in? RGB or BGR? Not sure if that is the problem but it's a start.
Yeah, my money's on an RGB <-> BGR switch as well.

Share this post


Link to post
Share on other sites
EDIT: Heh, beaten to the punch...I reckon it's an RGB <-> BGR problem too. Bitmap files are stored in BGR order. Try exchanging GL_RGB for GL_BGR in glTexImage2D, see if that makes any difference.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!