Jump to content
  • Advertisement
Sign in to follow this  
mike74

OpenGL smooth shading a quad

This topic is 4765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a quad in OpenGL, and I want it shaded with white on the top that gradually blends into blue on the bottom. I'm using smooth shading, and it looks fine when I view it head on. However, when the quad is rotated, there is a visible seam between the two triangles that comprise it (probably due to the way Gouraud shading works). Is there any way to eliminate this seam? Thanks. mike http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Advertisement
When you say you have a quad, is it an actual quad? Or two triangles put together to make a quad? If it's the later (2 triangles), you need to do a couple things to get them to align just right. Let's say you have something like:

1---2
| /|
| / |
|/ |
3---4


The verticies at points 2 and 3 must be exactly the same. If there's any floating point fuzziness, you'll probably see a seam. Also, if triangle A goes 1, 2, 3, triangle B must go in the direction of 4, 3, 2. In other words, if triangle A goes from vertex 2 to vertex 3, triangle B must go from vertex 3 to vertex 2 if you want a seemless connection. I believe this is a requirement in the OpenGL spec.

Someone please correct me if I'm wrong.

If you're actually using a quad, and getting a seam within the quad itself... post a picture of it.

Share this post


Link to post
Share on other sites
There's a pic at http://www.coolgroups.com/badmaze.jpg

My guess is that OpenGL is using the 2d coordinates of the triangles for the Gouraud interpolation.

Anyone know how to fix this?

Share this post


Link to post
Share on other sites
Mike, are you sure that ALL of the top vertices are white, and all of the bottom vertices are blue? From the screenshot it seems that only the top left vertex is white and the bottom right vertex is blue.

EDIT: Opengl does not do Gouraud shading on it's own as far as I know. If you are using glShadeModel(GL_SMOOTH), that just means that vertex colours are interpolated across the polygon.

Share this post


Link to post
Share on other sites
Yes, I'm sure the top vertices are white, and the bottom are blue.

What's the difference between Gouraud shading and having the colors interpolated
across the polygon?

mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Colors interpolated means (I'm assuming) what you think is Gouraud shading. Say you have a poly with 4 vertices having 4 different colors. With interpolation on, the color of the polygon surface will have a smooth transition to each of the 4 vertices. Like you see in your own program. Gouraud shading is: well the shading of a 3d surface. It uses color interpolation, yes, but there is more to it. I suggest you read this: wiki article.

About your problem, could you please post your setup and drawing code?

Share this post


Link to post
Share on other sites
I'm not using lighting.

mike
http://www.coolgroups.com/

Quote:
Original post by Mantear
Check your normals. Make sure they're normalized and pointing in the correct direction.


Share this post


Link to post
Share on other sites
setup:

/* enable OpenGL for the window */
EnableOpenGL (hWnd, &hDC, &hRC);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

/*******************
* Enable OpenGL
*
*******************/

void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;

/* get the device context (DC) */
*hDC = GetDC (hWnd);

/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);

/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}



drawing code:

glBegin(GL_QUADS);
while (i2 != thepoints.end())
{
glColor3f(0, 0, 1);
Point &p = *i2;
glVertex3f(p.seg.x0, 0, p.seg.y0);
glVertex3f(p.seg.x1, 0, p.seg.y1);

glColor3f(1, 1, 1);
glVertex3f(p.seg.x1, 1, p.seg.y1);
glVertex3f(p.seg.x0, 1, p.seg.y0);
++i2;
}
glEnd();

mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!