Get pixel info from texture in GLSL [SOLVED]

Started by
3 comments, last by zaneski13 14 years, 2 months ago
So I'm implementing deferred shading in my app and I need to access pixel information directly from a texture. So if I had to get the pixel information from a texture at (46,78) how would I get that specific color data? [Edited by - zaneski13 on February 16, 2010 10:56:45 PM]
Advertisement
You would have to use texture coordinates instead of pixel coordinates with texture2D function. eg you have to devide (46,78) by width and height of your image.
http://www.lighthouse3d.com/opengl/glsl/index.php?texture
There's also texelFetch that takes integer coordinates, if you're using GLSL 1.3 or later.
There are some GLSL functions added I think for 1.40 or 1.50 for sampling a texture with pixel coordinates. I think they start with texture2DFetch or something like that. Check the spec.
Of course, it is only for DX10 level GPUs.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thanks Guys!
http://www.lighthouse3d.com/opengl/glsl/index.php?texture Excellent source, I learned a lot today

This topic is closed to new replies.

Advertisement