PDA

View Full Version : A new question of glReadPixels()



peng530
12-31-2008, 01:36 AM
#include <windows.h>
#include <gl\GL.h>
#include <glut.h>
#include <gl\glu.h>
#include <stdio.h>


void DrawRegion();
void myInit(void);
void myDisplay(void);

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("test");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();

return 0;
}
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
DrawRegion();
//glFlush();
glutSwapBuffers();
}
void DrawRegion(void)
{
GLubyte Pixel = 0;
glColor3ub(0, 0, 0);
//for(GLint i = 500; i > 100; i--)
//{
// glBegin(GL_POINTS);
// glVertex2i(i, 50);
// glEnd();
// glReadPixels(i + 1, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
// printf("%d ", Pixel);
//}
glBegin(GL_POINTS);
glVertex2i(50, 50);
glEnd();
glReadPixels(50, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
printf("%d ", Pixel);
glReadPixels(49, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
printf("%d ", Pixel);
glReadPixels(50, 49, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
printf("%d ", Pixel);
glReadPixels(49, 49, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &amp;Pixel);
printf("%d ", Pixel);
glFlush();
}

This is my test code. I get the result "255 0 255 255" on my computer.In the past, I considered glReadPixels(50, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &Pixel) get the value of pixel(50,50).
But, according to the result, glReadPixels(49, 50, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &Pixel) get the value of pixel(50,50).

V-man
01-01-2009, 12:11 PM
Officially, the bottom left corner is 0, 0
so I think you want to read 49, 49
If it is not correct, send a bug report to the company.

peng530
01-01-2009, 07:30 PM
Is it a bug? Dose somebody else get the same result? Can it has relations to my computer?