tekord's picture

Color4 endian

Got a problem with color endian. How can I swap it? When I pass array of Color4 into GL.ColorPointer and draw objects it takes colors in wrong sequence. Red becomes Alpha, Green becomes Blue, ect. Does OpenGL supports endian swapping?

Have any ideas about solution?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tekord's picture

I was looking for solution on this forum and found a node with same problem that don't have answares. (but have a pictures).

the Fiddler's picture

OpenGL is supposed to store color components in RGBA order - the same as Color4. As far as I know, endianness does not change this: it only affects the order of the bytes within a single color component, e.g. R, if it happens to be larger than 1 byte.

What video card and driver are you using? Which OS & CPU? Does the issue appear on different video cards?

You can work around this issue in one of two ways:

  • Swap the order of the components to match what you expect (or create a different Color struct entirely)
  • Write a shader that decodes the vertex attributes in the correct way.

OpenGL does not offer a way to set the order of components in GL.ColorPointer, since it is always expected to be RGBA. It offers functions to set the endianness and component order of texture data via the GL.PixelStore family of functions.

(Edit) This extension looks promising: http://www.opengl.org/registry/specs/EXT/vertex_array_bgra.txt

tekord's picture

I using Windows 7, but I can't test program on other cards. Thanks for answare, now I have some ideas :).

c2woody's picture

x86 and x64 are both little endian and Color4 works definitely correctly there. Why do you assume you have a problem with endianness?

tekord's picture
c2woody wrote:

x86 and x64 are both little endian and Color4 works definitely correctly there. Why do you assume you have a problem with endianness?

I code whole day and tired :). Problem not in endian, just in color format.