PDA

View Full Version : from texture to pixel


jeffreytest
01-27-2005, 10: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.

Mihail121
01-27-2005, 10:52 PM
If you are texturing an object in 3D space you can't! Yes, you can probably use mipmaps to correct the sampling problems but you can never be sure that one texel corresponds to one pixel!

anubis
01-28-2005, 12:03 AM
set up an orthogonal projection matrix and render a quad from 0 -> width and 0 -> height with texture coordinates from 0 -> 1. make sure you disable all filtering options in your driver settings. that might not be perfect either but is the best you can get in opengl. alternatively you can use the opengl raster functions like glBitmap. that will give you the right result, allthough it's obviously a lot slower.
anyway, why do you need it this exact ?

NomadRock
01-29-2005, 12:12 PM
Dont use OpenGL. Use SDL or some other library that lets you blit directly to the screen.

MA]Mestre
02-14-2005, 02:16 AM
set up an orthogonal projection matrix and render a quad from 0 -> width and 0 -> height with texture coordinates from 0 -> 1. make sure you disable all filtering options in your driver settings. that might not be perfect either but is the best you can get in opengl. alternatively you can use the opengl raster functions like glBitmap. that will give you the right result, allthough it's obviously a lot slower.
anyway, why do you need it this exact ?
15486


great anubis !!! but i'll always exists drift, as u comment.

I'm curious to kwon, why u need this feature ? ( printscreen ? )