Jump to content


from texture to pixel


4 replies to this topic

#1 jeffreytest

    New Member

  • Members
  • Pip
  • 1 posts

Posted 28 January 2005 - 05:36 AM

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.

#2 Mihail121

    Senior Member

  • Members
  • PipPipPipPip
  • 1050 posts

Posted 28 January 2005 - 05:52 AM

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!

#3 anubis

    Senior Member

  • Members
  • PipPipPipPip
  • 2225 posts

Posted 28 January 2005 - 07: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 ?
If Prolog is the answer, what is the question ?

#4 NomadRock

    Senior Member

  • Members
  • PipPipPipPip
  • 785 posts

Posted 29 January 2005 - 07:12 PM

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

#5 MA-Mestre

    New Member

  • Members
  • PipPip
  • 14 posts

Posted 14 February 2005 - 09:16 AM

anubis said:

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 ?

View Post


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

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users