类型 | 说明 |
GL_POINTS | 单个顶点集 |
GL_LINES | 多组双顶点线段 |
GL_POLYGON | 单个简单填充凸多边形 |
GL_TRAINGLES | 多组独立填充三角形 |
GL_QUADS | 多组独立填充四边形 |
GL_LINE_STRIP | 不闭合折线 |
GL_LINE_LOOP | 闭合折线 |
GL_TRAINGLE_STRIP | 线型连续填充三角形串 |
GL_TRAINGLE_FAN | 扇形连续填充三角形串 |
GL_QUAD_STRIP | 连续填充四边形串 |
几何图元类型说明
代码效果
代码
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix //移动是相对当前位置移动(第一次移动相对与屏幕中心0,0,0下一次再移动时相对的就是本次移动后的位置了)
//向屏幕内移动18.9个单位,这样1个单位(1米)对应480/(2*tan(22.5)*(18.9+0.1)= 30像素
glTranslatef(0.0f,0.0f,-18.9f); // 绘制不连续线段,把屏幕分成9部分
glBegin(GL_LINES);
// 横线
glVertex3f( -21.0f, 3.0f, 0.0f);
glVertex3f(21.0f, 3.0f, 0.0f);
glVertex3f( -21.0f, -3.0f, 0.0f);
glVertex3f( 21.0f, -3.0f, 0.0f);
// 竖线
glVertex3f( -3.0f, 8.0f, 0.0f);
glVertex3f(-3.0f, -8.0f, 0.0f);
glVertex3f( 3.0f, 8.0f, 0.0f);
glVertex3f( 3.0f, -8.0f, 0.0f);
glEnd(); // 绘制点
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);// 设置当前色为红色
glVertex3f( -8.0f, 5.5f, 0.0f);
glVertex3f( -7.5f, 5.5f, 0.0f);
glVertex3f( -7.0f, 5.5f, 0.0f);
glEnd(); // 绘制不闭合折线
glBegin(GL_LINE_STRIP);
glColor3f(1.0f,1.0f,0.0f);// 设置当前色为黄色
glVertex3f( -2.0f, 5.5f, 0.0f);
glVertex3f( 2.0f, 5.5f, 0.0f);
glVertex3f( -2.0f, 4.0f, 0.0f);
glVertex3f( 2.0f, 4.0f, 0.0f);
glEnd(); // 绘制闭合折线
glBegin(GL_LINE_LOOP);
glColor3f(0.0f,0.0f,1.0f);// 设置当前色为蓝色
glVertex3f( 6.0f, 6.0f, 0.0f);
glVertex3f( 4.0f, 4.0f, 0.0f);
glVertex3f( 8.0f, 4.0f, 0.0f);
glEnd(); // 绘制多组独立填充三角形(以下绘制2个三角形)
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);// 设置当前色为红色
glVertex3f( -9.0f, 1.0f, 0.0f);
glVertex3f(-8.0f,-1.0f, 0.0f);
glVertex3f( -10.0f,-1.0f, 0.0f); glVertex3f( -6.0f, 1.0f, 0.0f);
glVertex3f(-5.0f,-1.0f, 0.0f);
glVertex3f( -7.0f,-1.0f, 0.0f);
glEnd(); // 绘制三角形带
glBegin(GL_TRIANGLE_STRIP);//(以下绘制3个连续三角形) //第一个三角形由点123逆时针构成
//第二个三角形由点324逆时针构成
//第三个三角形由点345逆时针构成 glColor3f(1.0f,0.0f,0.0f);// 设置当前色为红色
glVertex3f( -2.0f,-1.0f, 0.0f);//点1
glVertex3f(0.0f,-1.0f, 0.0f);//点2
glVertex3f( -1.0f, 1.0f, 0.0f);//点3
glColor3f(0.0f,1.0f,0.0f);// 设置当前色为绿色
glVertex3f( 1.0f,1.0f, 0.0f);//点4
glColor3f(0.0f,0.0f,1.0f);// 设置当前色为蓝色
glVertex3f(2.5f,2.5f, 0.0f);//点5 glEnd(); return TRUE; // Everything Went OK
}