How can I use ARGB color in opengl/SDL?

岁酱吖の 提交于 2019-12-01 05:20:49
Andon M. Coleman

Judging by your Tux example code, you can skip SDL completely and feed OpenGL the pixel data manually using 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 the pixel data and the GL_UNSIGNED_INT_8_8_8_8_REV data type (this reverses the order of the channels 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 portable you may want to convert the pixel data to RGBA or BGRA yourself...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!