1

I've written a routine to read all pixel values from inside a BMP file to an array which I want to feed to glTexImage2D of openGL to turn it into a texture. Doing this I realised that the actual format of pixels inside BMP file is BGR and not RGB, so my array contains blue, green, red. As a result my final texture has its blue and red channels swapped comparing to the original bitmap.

This is how I call it:

glTexImage2D(GL_TEXTURE_2D, 0, 3, imgdata->width, imgdata->height, 0, GL_RGB, GL_UNSIGNED_BYTE, imgdata->pixdata);

Any workaround for this situation/wrong argument I'm passing? Only solution I can find right now is manually swap the RB values inside my array using a loop.

2 Answers 2

3

Why not change the format of glTexImage2D to GL_BGR.

4
  • 1
    Specifies the format of the pixel data. The following symbolic values are accepted: GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA.
    – user1944441
    Feb 23, 2013 at 18:29
  • I see it in the link you provided, but as I was reading from the red book, it wasn't in the list. Indeed, I set GR_BGR and it is marked as undeclared identifier
    – Tsaras
    Feb 23, 2013 at 18:30
  • Ahh, of course... , always look in multiple sources. Anyway did it work?
    – user1944441
    Feb 23, 2013 at 18:31
  • 1
    I see, dunno, maybe you have an old version of something.
    – user1944441
    Feb 23, 2013 at 18:34
1

I set GR_BGR and it is marked as undeclared identifier

Then you're not using a proper library for getting at OpenGL. OpenGL's system-provided headers may or may not contain up-to-date functions and enumerators. So instead, you need to use one of those libraries to get at OpenGL. You should use these instead of GL/gl.h.

Once you're accessing OpenGL properly, the rest is simple. Use GL_RGB as your pixel transfer format.

1
  • could you help me understand what those Loading Libraries do? are they just a higher level interface to calling the openGL core, do they add functionality and which is the most up to date?
    – Tsaras
    Feb 24, 2013 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.