PDA

View Full Version : Vertex Color Shading Shananigan



gl_rogue
05-06-2004, 06:25 PM
Hey, I've come across a problem that I've no idea how to solve, let alone, where to start. What happens is that I draw a quad as usual, and I assign either the color value 1, 1, 1 or 0, 0, 0 to each vertex. This, obviously, gives the polygon an effect of a nice black to white shade. However, if three verteces are white and one is black or vice-versa, what happens is that the shading of the polygon looks correct until one of the verteces is off the visible screen. Then the shading become horribly off, like the vertex color is clipped/ignored WITH THE VERTEX! Here is the code I've used:

disp_test_object(float x, float y, float z, float gam, int texture_index){
float high_light = 1, low_light = 0;

float base_size = 1;
float half_size = base_size / 2;
float verteces[] = {0 - half_size, 0 - half_size, 0,
0 + half_size, 0 - half_size, 0,
0 + half_size, 0 + half_size, 0,
0 - half_size, 0 + half_size, 0};

glPushMatrix();
glTranslatef(x, y, z);
glRotatef(gam, 0, 1, 0);

glDisable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, texture_index);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glColor4f(high_light, high_light, high_light, 1);
glVertex3f(verteces[0], verteces[1], verteces[2]); //Down Left
glTexCoord2f(1, 0); glColor4f(high_light, high_light, high_light, 1);
glVertex3f(verteces[3], verteces[4], verteces[5]); //Down Right
glTexCoord2f(1, 1); glColor4f(low_light, low_light, low_light, 1);
glVertex3f(verteces[6], verteces[7], verteces[8]); //Up Right
glTexCoord2f(0, 1); glColor4f(high_light, high_light, high_light, 1);
glVertex3f(verteces[9], verteces[10], verteces[11]); //Up Left
glEnd();
glPopMatrix();
glEnable(GL_TEXTURE_2D);
}//END DISPLAY TEST OBJECT FUNCTION

If anyone knows why this happens, or better yet, how to solve it, I would greatly appreciate an answer.

If there's any more information that could be relavent to this problem, please, feel free to ask me for it. I can also take snapshots of this and post it upon request. Thanks alot.

05-07-2004, 10:56 AM
'Fraid I've not got time to look through the code, but from what you've said it sounds rather like a driver bug.

What's your hardware, OS and driver version?

gl_rogue
05-10-2004, 06:46 PM
I have a Radeon 7000, win 98 se, and I'm not sure about the driver version.
Regardless, you just confirmed my suspicion. I assumed that with such simple code, this had to be a problem either with my vid-card or another imperfection in OpenGl. Anyway, I tested it out on another computer and it displayed fine, although rather slowly. So, I'm still not quite sure how to solve this to make this feature more compatible. But anyway, I just want to say thanks alot for helping me!

plasmonster
05-10-2004, 07:04 PM
gl_rogue,

you might find this thread interesting.
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_to pic;f=3;t=011912 (http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=011912)

There seems to be a pattern emerging with ATI cards and interpolation issues.

That being said, I would make sure that glShadeModel( GL_SMOOTH ) is set.

JustHanging
05-11-2004, 01:28 AM
Try replacing the quad with a triangle fan, I bet that'll do it.

The thing is, that when using quads, all per-vertex parameters should be planar to ensure artifact-free rendering. For position this is obvious, but it also applies for colors. If you have three white corners and one black, the colors aren't planar anymore. You can picture this by imagining that the colors represent the "height" of the vertex from it's original position. The resulting quad wouldn't be planar anymore. That's why it doesn't get rendered properly on all HW.

-Ilkka

05-11-2004, 01:45 AM
Vertex colors are always linearly interpolated, regardless of the geometric primitive. If drawing a triangle fan fixes the problem, then you have a driver/hardware problem.