I’m having an issue I’ve tried googling away, but I can’t find anyone complaining of the same issue. This makes me think it’s a problem with my code that I’m overlooking.
I’ve enabled GL_LINE_SMOOTH and GL_BLEND, and specified the blend function to be glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
When I draw my lines, they mostly look right, but as I move the camera farther away they begin to flicker. Looking more closely, there are black pixels around some of the lines, and when I zoom out they begin to take up a larger part of the lines at some camera distances, causing the lines to flicker. The polygons rendering behind the lines are not black. I’m at a complete loss as to what could be causing this. Here is the relevant code:
Here’s the code that sets all the opengl stuff up:
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable (GL_LINE_SMOOTH);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth (1.5);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
GLfloat none[]={0,0,0,1};
GLfloat all[]={1,1,1,1};
GLfloat some[]={0.2,0.2,0.2,0};
glLightfv(GL_LIGHT0,GL_AMBIENT,none);
glLightfv(GL_LIGHT0,GL_DIFFUSE,all);
glLightfv(GL_LIGHT0,GL_SPECULAR,all);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,none);
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,none);
Here’s how I draw the polygons behind the lines:
glBegin(GL_POLYGON);
glColor3f(color.x,color.y,color.z);
for (int i=0;i<numPoints;i++) {
glNormal3f(normal.x,normal.y,normal.z);
glVertex3f(points[i]->x,points[i]->y,points[i]->z);
}
glEnd();
And here’s the code to draw the lines themselves:
glBegin(GL_LINES);
glColor3f(0.8,0.8,1);
vector3f raised1=*(points[0])-(normal*0.2);
vector3f raised2=*(points[1])-(normal*0.2);
vector3f raised3=*(points[2])-(normal*0.2);
glVertex3f(raised1.x,raised1.y,raised1.z);glVertex3f(raised2.x,raised2.y,raised2.z);
glVertex3f(raised2.x,raised2.y,raised2.z);glVertex3f(raised3.x,raised3.y,raised3.z);
glVertex3f(raised3.x,raised3.y,raised3.z);glVertex3f(raised1.x,raised1.y,raised1.z);
glEnd();
The array of pointers to points referenced in each piece of rendering code is the same.