iphone上的glreadPixels问题

时间:2011-01-15 16:14:15

标签: iphone c++ opengl-es

我在屏幕上绘制纹理没有问题但是从内存中打印时我无法获得正确的像素。我有一个4x4 png图像,有4个黑色像素,我正在尝试打印它们。这就是我的工作:

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;
}

但我得到所有随机值而不是我期望的值。谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:1)

glReadPixels从帧缓冲区读取,而不是纹理。要检索纹理对象的内容,请使用glGetTexImage:http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml