I try to render my image in RGBA4444 without converting to RGBA8888,but....
// Define vertices
float vertices[] = {-1.f, 1.f, 0.f, 0.f, 1.f, // left top
1.f, 1.f, 0.f, 1.f, 1.f, // right top
-1.f, -1.f, 0.f, 0.f, 0.f, // left bottom
1.f, -1.f, 0.f, 1.f, 0.f}; // right bottom
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, image.width, image.height, 0, GL_BGRA,
GL_UNSIGNED_SHORT_4_4_4_4_REV, image.pixels.data());
CodePudding user response:
By default OpenGL assumes that the start of each row of an image is aligned to 4 bytes. This is because the GL_UNPACK_ALIGNMENT
parameter by default is 4. Since a pixel of an image with the format GL_UNSIGNED_SHORT_4_4_4_4_REV
only needs 2 bytes, the size of a row of the image may not be aligned to 4 bytes.
When the image is loaded to a texture object and 2*image.width
is not divisible by 4, GL_UNPACK_ALIGNMENT
has to be set to 2, before specifying the texture image with glTexImage2D
:
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, image.width, image.height, 0, GL_BGRA,
GL_UNSIGNED_SHORT_4_4_4_4_REV, image.pixels.data());