from texture to pixel

B0e1b5c32bafd8286f9caf1d8d3949a3
0
jeffreytest 101 Jan 28, 2005 at 05:36

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.

4 Replies

Please log in or register to post a reply.

2b97deded6213469bcd87b65cce5d014
0
Mihail121 102 Jan 28, 2005 at 05:52

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!

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Jan 28, 2005 at 07:03

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 ?

7543b5c50738e23b200e69fe697ea85a
0
NomadRock 101 Jan 29, 2005 at 19:12

Dont use OpenGL. Use SDL or some other library that lets you blit directly to the screen.

Db7c6256c6650d0a94ac64a980503733
0
MA_Mestre 101 Feb 14, 2005 at 09:16

@anubis

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 ? [snapback]15486[/snapback]

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

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