[GLSL] Simple Texturing problem

Hi. I have been working on very simple app that map a texture on quad. When used with fixed pipeline texture is mapped quite nice, but when i rewrote it to use shaders texture looks like it’s blurred (like wrong coord’s). I use linux with mesa 6.5.2
ATI XPress200M fglrx drivers. Here is drawing code


void drawGLScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glTranslatef(0.0f,0.0f,-1.1f);	
	glActiveTexture(GL_TEXTURE0);
       tekstura.bind_texture(0); //glBindTexture(GL_TEXTURE_2D, texture[0]);
	int texture_location = glGetUniformLocation(p, "tex");
	glUniform1iARB(texture_location, 0);
	glBegin(GL_QUADS);						
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);				
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-1.0f,1.0f, 0.0f);
		glTexCoord2f(0.0f, 0.0f);	
		glVertex3f(-1.0f,-1.0f, 0.0f);				
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(1.0f,-1.0f, 0.0f);	
	glEnd();
}

Vertex Shader

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

Pixel Shader


uniform sampler2D tex;
void main()
{
	gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
}

Could somebody tell me where bug is ?

Looks correct to me. Could you post comparison screenshots so we could see what the error looks like?

OK i dont quite no why this is working but its working :). This is CW version
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);

Why CCW version didnt work ? It’s natural way of drawing…

You don’t happen to have backface culling enabled (not that I think it should cause this, but it’s the only thing I can think of that where winding would matter)?

glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);

it’s all right, it only should start with 0.0f, 0.0f… i think so…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.