【问题标题】:opengl es 2.0 android c++ glGetTexImage alternativeopengl es 2.0 android c++ glGetTexImage 替代
【发布时间】:2019-05-28 08:41:30
【问题描述】:

在 Windows 上测试时,代码按预期工作,但在 android 上,glGetTexImage api 不存在,是否有其他方法可以在创建纹理之前从 OpenGL 获取所有像素而不缓存它们?

这是代码:

void Texture::Bind(int unit)
{
    glActiveTexture(GL_TEXTURE0 + unit);
    glBindTexture(GL_TEXTURE_2D, mTextureID);
}

GLubyte* Texture::GetPixels()
{
    Bind();

    int data_size = mWidth * mHeight * 4;

    GLubyte* pixels = new GLubyte[mWidth * mHeight * 4];

    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

    return pixels;
}

【问题讨论】:

    标签: opengl-es opengl-es-2.0 opengl-es-3.0


    【解决方案1】:

    glGetTexImage 在 OpenGL ES 中不存在。
    在 OpenGL ES 中,您必须将纹理附加到帧缓冲区并通过 glReadPixels 从帧缓冲区中读取颜色平面

    Bind();
    int data_size = mWidth * mHeight * 4;
    GLubyte* pixels = new GLubyte[mWidth * mHeight * 4];
    
    GLuint textureObj = ...; // the texture object - glGenTextures  
    
    GLuint fbo;
    glGenFramebuffers(1, &fbo); 
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureObj, 0);
    
    glReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glDeleteFramebuffers(1, &fbo);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多