jeffreytest
01-27-2005, 09:36 PM
what could I do to ensure one point in texture is correspond one pixel in window. Because I want to get the same RGBA value from every pixel in window with RGBA of the point in texture. I use following code. But when I read the pixel, there are alway some drift from the original RGBA value of the texture.
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
...
glBindTexture(GL_TEXTURE_2D, _tID);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f( -1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0, 1.0);
glVertex3f( -1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0, 1.0);
glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glReadPixels(0,0,WIDTH,HEIGHT,
GL_RGBA,GL_FLOAT,pData);
...
}
The RGBA value in pData is different from the original RGBA value in bmp file.
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
...
glBindTexture(GL_TEXTURE_2D, _tID);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f( -1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0, 1.0);
glVertex3f( -1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0, 1.0);
glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glReadPixels(0,0,WIDTH,HEIGHT,
GL_RGBA,GL_FLOAT,pData);
...
}
The RGBA value in pData is different from the original RGBA value in bmp file.