Sign in to follow this  

Enlight me with the strange way Readpixels() stores data...

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i'm totally consufed with the way readpixels() stores data in a buffer. Let's say we have a frame buffer such as: 0 1 2 3 <-- this is the top of your screen 4 5 6 7 8 9 A B C D E F <-- this is the bottom of your screen pretty easy a 4x4 pixels window... now the tricky part, we call readpixels(4, 4, RGB, buffer); How buffer is organized? 1) C D E F 8 9 A B 4 5 6 7 0 1 2 3 2) C 8 4 0 D 9 5 1 E A 6 2 F B 7 3 3) 3 7 B F 2 6 A E 1 5 9 D 0 4 8 C 4) ??? I'm pretty sure it would be 3, but anytime I use it... uhmm i don't know... any idea?

Share this post


Link to post
Share on other sites
In OpenGL (and most other graphics APIs, as well as image file formats) images are vertically flipped, that includes textures as well as the framebuffer.

What you need to do is swap your data row by row.

Share this post


Link to post
Share on other sites
Well, yes I know OpenGL uses column mayor order but considering that the origin is at the lower-left corner makes things harder... I've tried just to flip but somehow does not work.

What I usually do is

for (x=0; x<width; x++)
{
for (y=height-1; y>=0; y--) {
buffer[y][x] //something like this
}
}



but sometimes i'm just not 100% sure...

Share this post


Link to post
Share on other sites
it's not a 2D array. It's a 1D array interpreted as a 2D array (actually exactly like a 2D array declared on the stack, but without the compiler there to give you the ability to do array[x][y]).

to access:


buffer[ x + y*width ];



where x & y are the correct indices for however the data is organized.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by remdul
In OpenGL (and most other graphics APIs, as well as image file formats) images are vertically flipped, that includes textures as well as the framebuffer.

What you need to do is swap your data row by row.


By saying flipped, there is a hidden asumption about the orientation. You are assumpting an image is reading from top-down. However, this is really not a good idea to consider opengl like this.

You should consider an image starts reading from bottom-left corner. And, scaning each pixel from left to right; each row bottom-up. Then, everything will be aligned perfectly with the natural memory ordering.

[Edited by - ma_hty on September 19, 2007 8:56:31 PM]

Share this post


Link to post
Share on other sites

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this