OpenGL的填充属性函数————
线框图中消除选定边
这个较为简单,只需将该位标志设为关,从而使在这个顶点之后的边不被显示。
程序代码为:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,1.0,0.0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0,1.0);
glBegin(GL_TRIANGLES);
glVertex2i(50,50);
glVertex2i(150,50);
glVertex2i(75,150);
glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
glColor3f(1.0,0.0,0.0);
glPolygonMode(GL_FRONT,GL_LINE);//多边形的前面仅显示它的边
glLineWidth(4.0);//为了看着方便,可以设置一定线宽
glBegin(GL_TRIANGLES);
glVertex2i(50,50);
glEdgeFlag(GL_FALSE);
glVertex2i(150,50);
glEdgeFlag(GL_TRUE);
glVertex2i(75,150);
glEnd();
glFlush ();
}
void myinit (void)
{
glClearColor (0.0, 0.0, 0.0, 1.0);
glMatrixMode (GL_PROJECTION); // Set projection parameters.
gluOrtho2D (0.0, 400.0, 0.0, 150.0);
//glShadeModel (GL_FLAT);
}
int main(int argc, char** argv)
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInit (&argc, argv);
//glutInitPosition
glutInitWindowPosition(0, 0);
glutInitWindowSize (450, 350);
glutCreateWindow ("An Example OpenGL Program");
//glutInitWindow (argv[0]);
myinit();
glutDisplayFunc(display);
glutMainLoop();
}