Jump to content
  • Advertisement
Sign in to follow this  
deavik

OpenGL openGL textures missing color channels after using SDL_LoadBMP

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

Hello guys! I am using opengl with SDL and using SDL_LoadBMP to load in some textures, and put them on a spinning cube. However, it seems like only the BLUE channel from the bitmap has been read in. Now I have read other topics where using GL_BGR instead of GL_RGB in glTexImage2D seems to work, but here all of the RED and GREEN color information seems to be missing! Here are my bitmaps (original texture, what it looks like):    

As you can see, the white portion of the image also appears blue: even if channels were swapped, white would still be white, right? I created the bitmap with GIMP if that helps. And my code:

//
//

    tex[0] = SDL_LoadBMP(filename);
    
    if (tex[0])
    {
       loaded = 1;
       
       glGenTextures(1, &texture[0]);
       glBindTexture(GL_TEXTURE_2D, texture[0]);
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex[0]->w, tex[0]->h, 0, GL_RGB, GL_UNSIGNED_BYTE, tex[0]->pixels);    
       glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
       glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    }    
    if (tex[0])
       SDL_FreeSurface(tex[0]);
    
//
//
I created the BMP with GIMP if that helps. Thanks for your help, in advance.

Share this post


Link to post
Share on other sites
Advertisement
Make sure the primary color is white (ie: call glColor3f(1.0f, 1.0f, 1.0f) right before you render the cube). If you're texture environment mode is set to modulate (the default) the texture's color is multiplied with the primary color.

If that's not the problem post your rendering code as well (between source tags if it is somewhat long).

Share this post


Link to post
Share on other sites
You could try to use GL_BGR instead of GL_RGB in the glTexImage2D function call. SDL uses a slightly odd way regarding the bitmap loading.

Share this post


Link to post
Share on other sites
Kalidor, you hit on it the first time! I am a dumbass, I did some drawing with blue, and later while texturing forgot to remove that line! But this could be a nice way to tint the textures, couldn't it?

Having said that I am still getting blue for red as everyone else does. GL_BGR, GL_BGR_EXT don't work - they are undefined in the opengl headers I am using. I'm on Microsoft Windows, and they stopped updating their opengl dev package after opengl v1.1, and they introduced the GL_BGR aftter v1.2

So do I have any other way out except maybe fiddling with color channels in my texture image and reversing them. I tried using SDL_ConvertSurface, but I just get gibberish textures using that. Could anyone help me with using SD_ConvertSurface to swap the channels?

Share this post


Link to post
Share on other sites
Quote:
Original post by deavik
So do I have any other way out except maybe fiddling with color channels in my texture image and reversing them.
Include glext.h. You'll probably have to download it from somewhere though. This is probably the most up-to-date one.

EDIT: And you can download glxext.h and wglext.h from the same place here.

Share this post


Link to post
Share on other sites
Thank you Kalidor! I had never read about glext.h in any forum I have come across before this - so I have to say ou really know this stuff!

Thank you everyone who posted a reply to this thread. Now as I go deeper and deeper into game programming, I am sure I will keep having complex issues. But one thing's for sure: I'll know which forums to come to!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!