View Full Version : Question of texture coordinates in shader

04-05-2011, 01:03 AM
//Read texture coordinates
"vec2 texCoord = gl_TexCoord[0].xy;"
//Read value of texture of current pixel
"vec4 original_value = texture2DRect(texture,texCoord);"

The gl_TexCoord[0].xy will return the coordinates (x,y) of the texture[0] to the vec2 texCoord right?
Eg: if (x,y) = (1,2);
texCoord = (1,2) right?

Q2: I only have one component on each pixels of the texture. So, texture2DRect(texture,texCoord) will return 4 values to the original_value.
Eg: If the texture value is 2, the original_value = (2,0,0,0)?
The rest of the value will be zero or how?

Alfonse Reinheart
04-05-2011, 01:55 AM
One by one, you're basically asking, "how does OpenGL work?" You should stop asking questions and start doing research. For example, the answer to both (http://www.opengl.org/wiki/GLSL_Types#Swizzling) of theses questions (http://www.opengl.org/wiki/Textures#Sampling_results) can be found on the OpenGL Wiki (http://www.opengl.org/wiki/Main_Page).

While the OpenGL Specification can get rather technical in places, the GLSL spec is quite readable and would have answered your first question easily.