PDA

View Full Version : Line Drawing Problem



djavan
03-18-2003, 12:24 AM
Hi Everyone
I'm drawing some colored QUADS with their edges in black but my problem is that the lines (i.e. edges) are NOT QUITE CLEAR AND SMOOTH (in some areas). My "primitive" guess is the PixelFormat!?!?

The code for setting up the PixelFormat is :

Dim pfd As PIXELFORMATDESCRIPTOR
Dim PixelFormat As Long

pfd.nSize = Len(pfd)
pfd.nVersion = 1
pfd.dwFlags = PFD_SUPPORT_OPENGL Or PFD_DRAW_TO_WINDOW Or PFD_DOUBLEBUFFER Or PFD_TYPE_RGBA
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 24
pfd.cDepthBits = 16
pfd.iLayerType = PFD_MAIN_PLANE

PixelFormat = ChoosePixelFormat(lhDC, pfd)
If PixelFormat = 0 Then FatalError "Could not retrieve pixel format!"

SetPixelFormat lhDC, PixelFormat, pfd

Also, the code for drawing QUADS and Edges is

glColor3ub r, g, b
glBegin bmQuads
glVertex3f W(1, 0), W(1, 1), W(1, 2)
glVertex3f W(2, 0), W(2, 1), W(2, 2)
glVertex3f W(3, 0), W(3, 1), W(3, 2)
glVertex3f W(4, 0), W(4, 1), W(4, 2)
glEnd

glColor3ub 0, 0, 0
glBegin bmLineLoop
glVertex3f W(1, 0), W(1, 1), W(1, 2)
glVertex3f W(2, 0), W(2, 1), W(2, 2)
glVertex3f W(3, 0), W(3, 1), W(3, 2)
glVertex3f W(4, 0), W(4, 1), W(4, 2)
glEnd

With my highest appreciation for your help and advise.

JustHanging
03-18-2003, 12:55 AM
Hi,

Your pixel format is ok (propably, didn't look...), your problem is z-fighting. This happens because the lines and the quads have almost the same depth values, therefore some pixels pass the depth test and others don't. This can be fixed by applying polygon offset to the quads. There's an example of this at the end of this thread: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/011688.html

-Ilkka

djavan
03-18-2003, 08:08 AM
I thank you from bottom of my heart. It worked great!!