简体   繁体   中英

glReadPixels failed with format GL_ALPHA

I wanna draw font on the android game by the freetype library. Get the glyph texture by the library and upload to the FBO, which i used to rendering the string label;

when i run this code, it would be ok, and i get the excepted data, the font shows ok,

    for (int j = 0; j < height; j ++) {
            glReadPixels ( 0, j, width, 1,
                           GL_RGBA, GL_UNSIGNED_BYTE, data + j*bytesPerRow);
    }

But after i change the format to GL_ALPHA, it is always return 0 on the android device, and the gl error log: got error: 0x500, so it means ,i can't read the pixels by GL_ALPHA? the wrong code as:

    for (int j = 0; j < height; j ++) {
            glReadPixels ( 0, j, width, 1,
                           GL_ALPHA, GL_UNSIGNED_BYTE, data + j*bytesPerRow);
    }

i don't know why, any help?

OpenGL ES is only required to support 2 format / data type pairs in a call to glReadPixels (...).

  1. GL_RGBA , GL_UNSIGNED_BYTE (you already know this one)
  2. Query: GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE

You have discovered unfortunately that GL_ALPHA , GL_UNSIGNED_BYTE is NOT the second supported format / data type pair.

To figure out what the second supported pair is, consider the following code:

GLint imp_fmt, imp_type;

glGetIntegerv (GL_IMPLEMENTATION_COLOR_READ_FORMAT, &imp_fmt);
glGetIntegerv (GL_IMPLEMENTATION_COLOR_READ_TYPE,   &imp_type);

printf ("Supported Color Format/Type: %x/%x\n", imp_fmt, imp_type);

You will have to adjust the code accordingly, since this is C and you are using Java... but you get the idea.

Chances are very good that your implementation does not have a single-channel format for use with glReadPixels (...) considering there is no single-channel color-renderable format without the extension: GL_EXT_texture_rg .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM