在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;
}
最佳答案
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);
关于opengl-es - opengl es 2.0 android c++ glGetTexImage替代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53993820/