1

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?

keaukraine
  • 5,315
  • 29
  • 54
codeplay
  • 620
  • 1
  • 6
  • 19

1 Answers1

2

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.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • many thanks,btw, i am using c and objc, and i have developing android game, so i should use some java... – codeplay Nov 26 '13 at 05:54