Sign in to follow this  
ARB1130

How to get texture u v value?

Recommended Posts

Hi! I have a simple question: I set a texture in 2x2 size. I want to get the u v value.In fact,it should be 0.0,0.5 and 1.0 in uv but I got 0.25 and 0.75 Please tell me how to get them or some tip! thank you! ^_^ my code is: ////////////////////////////////// //my fragment void main() { float u=gl_TexCoord[0].x; gl_FragColor =vec4(u,u,u,u); } ////////////////////////////////// //texture parameter set glGenTextures(1, &_iTexture); glBindTexture(GL_TEXTURE_2D, _iTexture); glTexParameteri(GL_TEXTURE_RETANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RETANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RETANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RETANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_RETANGLE_NV, 0,GL_FLOAT_RGBA32_NV,_iWidth,_iHeight,0, GL_RGBA, GL_FLOAT, 0); ///////////////////////////////// //Viewport-Sized Quad = Data Stream Generator glBegin(GL_QUADS); { glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f); glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f); } glEnd(); //////////////////////////////// //1:1 pixel to texture mapping glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1, 1, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ////////////////////////////////

Share this post


Link to post
Share on other sites
Where do you "get" any value at all? Right now, all I can see is some rendering code. What specific spot do you want to "get" the values from?

In OpenGL, both display pixels and texture pixels (texels) are measured with 0,0 at the edge. Thus, the center of a texel is at 0.25 and 0.75 in a two-pixel texture, and the center of a display pixel is at 0.5 and 1.5 in a two-pixel display area. Texture sampling is done at the center of each pixel, so if you draw a rectangle from 0 to 2, it will sample at 0.5 and 1.5.

Share this post


Link to post
Share on other sites
Thank you for your response!

So if I ues the glReadPixels( 0, 0, 2, 2, GL_RED, GL_FLOAT, array );

I can get two values about the center of the texels.

0.25 and 0.75 .

so if I use the "vec4 c = texture2D(texUnit, texCoord.st);"

I can get the value which is interpolated near two value replacing ,is it

right?

^_^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this