PDA

View Full Version : gl_TexCoord[0]



The Ordinary
12-11-2008, 02:49 AM
I am struggling here.

I have problems with the accuracy of the call to gl_TexCoord[0].
I am using GLSL and the GLUT architecture.

in my vertex shader, i have the code:

void main() {
gl_TexCoord[0]=gl_MultiTexCoord0;
gl_Position=ftransform();
}

My Fragment Shader takes in a nxn texture and a nx1 texture.
These two are multiplied together,
but when i do multiply them together, then it doesnt take the exact coordinates (as my results arent the same through the fragment shader as through doing the calculation on the CPU)

dletozeun
12-11-2008, 03:39 AM
I do not understand how you want to multiply the nxn texture by the nx1 one. Can you elaborate a bit more what you are trying to do? The fragment shader code would be helpful too.

The Ordinary
12-11-2008, 09:23 AM
thanks for the further request.
im looking to make a Jacobi Iteration on the GPU using GLSL.

the fragment shader looks like this:

uniform sampler2D input_A;
uniform sampler2D input_x;

void main(void)
{
float A_Value,
x_Value;

A_Value = texture2D(input_A,vec2(gl_TexCoord[0].x, 1.0-gl_TexCoord[0].y)).x;
x_Value = texture2D(input_x,vec2(0.5,1.0-gl_TexCoord[0].y)).x;

gl_FragColor = vec4(A_Value*x_Value);
}

Komat
12-11-2008, 01:49 PM
How do you calculate the texture coordinates and what filtering mode is set on those textures? It is possible that you sample different texels or even combination of them (if filtering is enabled).

The Ordinary
12-11-2008, 02:03 PM
The filtering on all of the Textures is: GL_NEAREST

And the Coordinates are set in:



//Render Screen Aligned Quad
glMatrixMode(GL_PROJECTION); //select the Projection matrix
glPushMatrix(); //save the current projection matrix
glLoadIdentity();
glOrtho(0.0,float(window_Width),0.0,float(window_H eight),-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//glBindTexture(GL_TEXTURE_2D,test_Texture/*output_Texture.getTexID()*/);
//Render Quad
glBegin(GL_QUADS);
glTexCoord2f(1.0f,0.0f); glVertex3f(render_Width,render_Height, 0.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f( 0.0f,render_Height, 0.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f,1.0f); glVertex3f(render_Width, 0.0f, 0.0f);
glEnd();
//Return to Normal Projection
glMatrixMode(GL_PROJECTION);
//Load the previous Projection matrix (Generaly, it is a Perspective projection)
glPopMatrix();
//Select the Modelview matrix stack
glMatrixMode(GL_MODELVIEW);
//Load the previous Modelview matrix
glPopMatrix();