How can I use ARGB color in opengl / SDL?

I am using SVG using Cairo. Cairo's output format is ARGB. Then I put the image in SDL_Surface, so I can use it as an openGL texture.

The resulting image looked just fine when I directly use SDL_Surface. But I had to use the surface as a texture in openGL because I needed the openGL function. The problem is that the whole color turned upside down. OpenGL uses RGBA, not ARGB.

I was wondering if anyone could help me convert ARGB to SDL_Surface to RGBA.

Helpful information:
I used this tutorial to render my SVG. http://tuxpaint.org/presentations/sdl_svg_svgopen2009_kendrick.pdf
My software is written in C.

EDIT: I used this tutorial to use SDL_Surface as an openGL texture.
http://www.sdltutorials.com/sdl-tip-sdl-surface-to-opengl-texture

Both the rendering process and the opengl texture are the same as the tutorials.

+4
source share
1 answer

Judging by your example Tux code, you can skip SDL completely and manually load OpenGL data with the following code:

GLuint tex; glGenTextures (1, &tex); glBindTexture (GL_TEXTURE_2D, tex); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image); 

The important details here are the GL_BGRA format for pixel data and the GL_UNSIGNED_INT_8_8_8_8_REV data type (this overrides the channel order during pixel transfer operations). OpenGL will take care of converting the pixel data into the appropriate texel format for you. OpenGL ES, on the other hand, will not do this; to make this transfer, you may want to convert the pixel data to RGBA or BGRA yourself ...

+11
source

Source: https://habr.com/ru/post/1500625/


All Articles