我在屏幕上绘制纹理没有问题,但我无法从内存中打印出正确的像素。我有一张有4个黑色像素的4x4 png图像,我正在尝试打印它们。这就是我要做的:
glBindTexture(GL_TEXTURE_2D, m_textureId);
const int size = m_width * m_height * 4;
GLubyte pixels[size];
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
if(glGetError() != GL_NO_ERROR)
assert(false && "opengl error");
for(int index = 0; index < size; index+=4)
{
cout << "red " << (unsigned)pixels[index+0] << endl;
cout << "green " << (unsigned)pixels[index+1] << endl;
cout << "blue " << (unsigned)pixels[index+2] << endl;
}
但我得到的都是随机值,而不是我期望的值。有没有人看到我做错了什么?
发布于 2011-01-15 17:25:18
glReadPixels从帧缓冲区读取,而不是纹理。要检索纹理对象的内容,请使用glGetTexImage:http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml
https://stackoverflow.com/questions/4700641
复制