View Full Version : Getting pixel color !
How can i get pixel color?.
I've try to get with glReadPixels and glReadBuffer but i did'nt success.
Please help me..
glReadPixels is what you need. Show us what you do with it, cause if it doesn't work, you're doing something wrong with it.
Here is the simple example:
reshape(int w, int h)
glViewport(0, 0, w, h);
gluOrtho2D(0, w, h, 0);
In this example i want to get only one pixel color.That is lower left corner of quad.
But i get this value on c.
r g b
0.945 0.843 0.94354
why i can not take right value?
sorry i mean RGB.(not RGBA)
09-30-2002, 04:07 PM
Check your pixel storage mode (set with glPixelStore*).
I've try all the mode but i can't get right values.What i have to use?
Is there anybody who will write simple executable code for me?That is very important for me.
10-01-2002, 04:15 AM
Are you trying to get the pixel of the scene previously drawn here? Because that's what you're going to get. Until you call glutSwapBuffers, your scene is in the back buffer, but you said to read from the front buffer.
10-01-2002, 06:00 AM
Call glPixelStorei(GL_PACK_ALIGNMENT, 1). The default for this parameter is 4, which means it will always write a multiple of 4 bytes to each row. In the example you gave, this would write beyond the end of the array c.
The default for this parameter is 4, which means it will always write a multiple of 4 bytes to each row.
No, it means that each row starts on 4 byte boundary. If you read, say, 5 bytes per row, you have 3 unused bytes in the end of the row.
10-01-2002, 08:21 AM
You're right. Well, technically PACK_ALIGNMENT=4 doesn't mean that each row will start on a 4-byte boundary; it means that each row will start on a 4-byte boundary _relative_ to the pointer passed to glReadPixels. If you read more than one row, and you're not expecting this, it will write beyond the end of the array. But with reading just one pixel, this certainly wouldn't be a problem. Sorry. I think the problem is probably the buffer swapping thing.
I usually set the PACK_ALIGNMENT to 1 anyways to avoid confusion and simplify my code.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.