简体   繁体   English

glReadPixels失败,格式为GL_ALPHA

[英]glReadPixels failed with format GL_ALPHA

I wanna draw font on the android game by the freetype library. 我想通过freetype库在android游戏上绘制字体。 Get the glyph texture by the library and upload to the FBO, which i used to rendering the string label; 通过库获取字形纹理,并将其上传到FBO,这是我用来渲染字符串标签的;

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? 但是,当我将格式更改为GL_ALPHA后,它在Android设备上始终返回0,并且gl错误日志:错误:0x500,所以这意味着我无法通过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 (...). 在调用glReadPixels (...).仅要求OpenGL ES支持2种格式/数据类型对glReadPixels (...).

  1. GL_RGBA , GL_UNSIGNED_BYTE (you already know this one) GL_RGBAGL_UNSIGNED_BYTE (您已经知道这一点)
  2. Query: GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE 查询: GL_IMPLEMENTATION_COLOR_READ_FORMATGL_IMPLEMENTATION_COLOR_READ_TYPE

You have discovered unfortunately that GL_ALPHA , GL_UNSIGNED_BYTE is NOT the second supported format / data type pair. 不幸的是,您发现GL_ALPHAGL_UNSIGNED_BYTE 不是第二个受支持的格式/数据类型对。

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. 您将不得不相应地调整代码,因为这是C语言,并且您正在使用Java ...但是您明白了。

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 . 考虑到没有扩展名GL_EXT_texture_rg ,就没有单通道颜色可渲染的格式,那么您的实现不具有可与glReadPixels (...)一起使用的单通道格式的GL_EXT_texture_rg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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