GL划线
glBegin(GL_LINES);//start to draw something
glVertex3f(0.0f, 0.0f, -10.0f);
glVertex3f(-5.0f, 0.0f, -10.0f);
glVertex3f(-5.0f, 0.0f, -10.0f);
glVertex3f(-5.0f, -2.0f, -10.0f);
glBegin(GL_LINE_STRIP);//start to draw something
glVertex3f(0.0f, 0.0f, -10.f);
glVertex3f(-5.0, 0.0f, -10.f);
glVertex3f(-5.0f, -2.0f, -10.f);
glBegin(GL_LINE_LOOP);//start to draw something
glVertex3f(0.0f, 0.0f, -10.f);
glVertex3f(-5.0, 0.0f, -10.f);
glVertex3f(-5.0f, -2.0f, -10.f);
glBegin(GL_LINE_LOOP);//start to draw something
glColor4ub(255, 0, 0, 255);
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(-5.0, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(-5.0f, -2.0f, -10.f);
glEnd(); //end
GL画三角形
glBegin(GL_TRIANGLES);//start to draw something
glColor4ub(255, 0, 0, 255);
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(-5.0, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(-5.0f, -2.0f, -10.f);
glEnd(); //end
glEnable(GL_CULL_FACE);//擦除背面 顺时针背面, 逆时针正面 摄像机点如何连接的
//front face:cow :ccw-> counter clock wind
glFrontFace(GL_CULL_FACE);
//将顺时针,逆时针互换
glBegin(GL_TRIANGLES);//start to draw something
glColor4ub(255, 0, 0, 255);
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(-5.0f, -2.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(-5.0, 0.0f, -10.f);
glEnd(); //end
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(-5.0, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(-5.0f, -2.0f, -10.f);
glColor4ub(255, 0, 0, 255);
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(5.0, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(5.0f, -2.0f, -10.f);
glEnd(); //end
glBegin(GL_TRIANGLE_STRIP);//start to draw something
//遇到奇数点 -> n+1- >n+2 顺序连接 遇到偶点 n+1->n->n+2 画n-2个三角形
glColor4ub(255, 0, 0, 255);
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(-5.0, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(-5.0f, -2.0f, -10.f);
glColor4ub(255, 0, 0, 255);
glVertex3f(5.0f, 0.0f, -10.f);
glColor4ub(0, 255, 0, 255);
glVertex3f(0.0, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(0.0f, -2.0f, -10.f);
三角形扇
glBegin(GL_TRIANGLE_FAN);//start to draw something
glColor4ub(255, 0, 0, 255);
glVertex3f(0.0f, 0.0f, -10.f);
glColor4ub(0, 0, 255, 255);
glVertex3f(-5.0, -2.0f, -10.f);
glColor4ub(0, 255, 0,255);
glVertex3f(-3.0f, -2.0f, -10.f);
glColor4ub( 0, 0, 255,255);
glVertex3f(-1.0f, -2.0f, -10.f);