开发者

problem with glreadPixels on iphone

I have no problem drawing a texture to the screen but I cant get the right pixels when printing them from memory. I have a 4x4 png image with 4 black pixels and I am trying to print them. This is what I do:

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_ERRO开发者_如何学运维R)
    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;
}

But I get all random values and not the one I expect. Can anyone see what I am doing wrong?


glReadPixels reads from framebuffers, not textures. To retrieve the contents of a texture object use glGetTexImage: http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜