Sign in to follow this  
Kaezin

Using the same texture coordinate for all vertices

Recommended Posts

Kaezin    158
I'm using a texture to implement fake phong shading, but I've come across a problem. I'll avoid the nitty gritty of what the phong shading is doing, since it is irrelevant to the what's going on. This is an example of what is happening when certain conditions are met:
glTexCoord2f(0,0);  glVertex3f(x1, y1, z1);
glTexCoord2f(0,0);  glVertex3f(x2, y2, z2);
glTexCoord2f(0,0);  glVertex3f(x3, y3, z3);
I originally thought that the color at texture coordinate (0,0) would be used to texture the entire image, but I guess that's not the case. On my texture, the pixel at (0,0) is black and yet when I texture a triangle with that coordinate, I get an ugly grey result. When the texture isn't the same for all vertices, everything looks fine. Is this because the behavior in this case is generally undefined, or could there be something else wrong with my code?

Share this post


Link to post
Share on other sites
z80    134
Yeah, that is what i think too.

Try

glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

or

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);

Share this post


Link to post
Share on other sites
Kaezin    158
Thanks guys, changing the texture parameters fixed it. There was no ambient or specular light set, only diffuse so I could keep things simple. I was using some old code and so my textures were set to repeat instead of clamp, which explains why I was getting the grey shade. Thanks again.

[Edited by - Kaezin on March 14, 2006 1:27:34 PM]

Share this post


Link to post
Share on other sites
z80    134
You probably dont have to set the texture-coordinates for every vert btw.

I think you can do the same thing like this (OpenGL will use the current value if no value is specified):

glTexCoord2f(0, 0);
glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);
glVertex3f(x3, y3, z3);

Share this post


Link to post
Share on other sites
Kaezin    158
That's true, but I don't know in advance if all the vertices use the same texture coordinate since my light direction is constantly changing. Thanks though.

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