Jump to content
  • Advertisement
Sign in to follow this  
crunch

OpenGL Bluish textures. Whats wrong here?

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

Hey! When I load and apply textures to my 3d-object in opengl, the texture appears blueish when I run my program. The strange thing is that this texture that I am using, is actually yellow. What Could be causing this? Could the error be in the texture parameters ? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); Or in this function: glTexImage2D(GL_TEXTURE_2D, 0 ,GL_RGB, loadedImage->w, loadedImage->h, 0, GL_RGB, GL_UNSIGNED_BYTE, loadedImage->pixels); ? Do you have a clue whats causing this blueish color on my textures? thanks for your help:)

Share this post


Link to post
Share on other sites
Advertisement

Here is a picture that shows exactly what I mean: http://www.fotothing.com/photos/aa6/aa66d4c8606f6003ed6f73c1397b677f_70a.jpg

Share this post


Link to post
Share on other sites
You've probably messed up the RGB order of the colors. You might get more help if you show us how you're loading the image.

Share this post


Link to post
Share on other sites
Ah, I am guessing you are running on a PowerPC, SPARC or other big-endian processor and loading binary data made in a little-endian (x86) format.

Share this post


Link to post
Share on other sites
Do you use BMP-format for the image? BMP stores pixels in BGR-format, so exactly the other way around. In that case, specify GL_BGR as the input format instead of GL_RGB.

Share this post


Link to post
Share on other sites
I also think that you've messed up the color order. Assuming that you're a Windows programmer, .bmp files and so on use BGR order. OpenGL, however, uses RGB order. It looks so thrustworthy because of the original and texture colors (original is yellow=red+green, but your texture appears somewhat aqua=blue+green, which looks exactly like BGR<->RGB problem).

If you're lazy (you're a programmer so you should be :-), then you can use GL_BGR instead of GL_RGB. Hovewewer, this format is natively supported by older OpenGL versions, so it is possible that it won't work.

And ... yes, your loading code would be of a much help.

Share this post


Link to post
Share on other sites

thanks! :).

I load the textures with SDL and then "copy" them to opengl ...
I tried to change GL_RGB to GL_BGR, but I it wouldn`t work with that..
-----------------------------------------------------------------------
SDL_Surface *loadedImage = NULL;
int texture_id;
glGenTextures(1, (GLuint*)&texture_id);
loadedImage = IMG_Load("rusty1.bmp");

if(loadedImage == NULL)
{
printf("%s", SDL_GetError());
SDL_Quit();
return 1;
}

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glBindTexture(GL_TEXTURE_2D, texture_id);
glTexImage2D(GL_TEXTURE_2D, 0 ,GL_RGB, loadedImage->w, loadedImage->h, 0, GL_BGR, GL_UNSIGNED_BYTE, loadedImage->pixels);
SDL_FreeSurface(loadedImage);
-------------------------------------------------------------------------------
do see from this code whats making my textures blueish?

--anyways, thanks a lot!;-)

Share this post


Link to post
Share on other sites
Umm i dunno if I am correct but

glTexImage2D(GL_TEXTURE_2D, 0 ,GL_RGB, loadedImage->w, loadedImage->h, 0, GL_BGR, GL_UNSIGNED_BYTE, loadedImage->pixels);

The first GL_RGB is suppose to be bytes per pixel ie 1,3,4 ... (most probably 3)
and i do use GL_RGB on windows only and yet get the right colours, I think so for I use SDL for images.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrCoolSanta
glTexImage2D(GL_TEXTURE_2D, 0 ,GL_RGB, loadedImage->w, loadedImage->h, 0, GL_BGR, GL_UNSIGNED_BYTE, loadedImage->pixels);

The first GL_RGB is suppose to be bytes per pixel ie 1,3,4 ... (most probably 3)


It was changed in a later revision of the spec (maybe even 1.2) to accept GL_ constants there instead of numbers; unfortunately everyones texturing code seems to be built of old old old examples which still use the 1,3,4 setup [sad]

Share this post


Link to post
Share on other sites
^ I dint know that, got my code from tutorials. :)

To crunch:
Why use .bmp actually, try raw format or anything like that. But you problem still seems strange. Why not check if you colour the object you put the texture on?

show the whole code that loads textures and draws the object. This might just be helpful :)

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!