problem of drawing line

i draw a line with points (10,10),(100,10) first
,then draw a triangle with points as (10,10),
(100,10),(100,100).Does the triangle cover the line? i have tested this on different cards and had different results.On intel 82865 card the line draws beside the triangle, and on sis(*) card the line is covered with the triangle.how to resolve this difference?
hope you understood my question and give me help.
thanks.

wexuv,
Your question is more likely programming. You may get better answer from coding forum.

The problem you describe is z-fighting (depth conflict), which means OpenGL cannot determine which primitive is drawn in front of the other.

Actually, they are both same distance from view point. Therefore, sometimes the line is shown front, but sometime, the triangle is shown first.
Worse, it looks in and out.

In order to avoid this problem, you can force to set different distance for each primitive.

For example, if you want the line is in front of the triangle;

// draw a line at z=0
glBegin(GL_LINES);
glVertex3f(10, 10, 0);
glVertex3f(100, 10, 0);
glEnd();

// draw a triangle at z=-1
glBegin(GL_TRIANGLES);
glVertex3f(10, 10, -1);
glVertex3f(100, 10, -1);
glVertex3f(100, 100, -1);
glEnd();

I assumed viewing direction is -Z axis, which is default.

Other methods are using glPolygonOffset() or using glDepthFunc(GL_EQUAL).
==song==