View Full Version : Array for glReadPixels

David Doria
03-18-2009, 10:07 AM
If I make an array like this

GLubyte bufImage[Width][Height][3];

I can pass bufImage as the 'pixels' parameter of glReadPixels and then get the values using:

r = bufImage[im_x][im_y][0];
g = bufImage[im_x][im_y][1];
b = bufImage[im_x][im_y][2];

However, if I don't know Width and Height at runtime, this does not work. I tried to do this:

GLubyte * bufImage = new GLubyte[Width*Height*3];

and access them with

r = bufImage[im_x * Width + im_y * Height];
g = bufImage[im_x * Width + im_y * Height + 1];
b = bufImage[im_x * Width + im_y * Height + 2];

but I must be misunderstanding how these pixels are expected to be ordered... can anyone clarify this?