GL画线-画三角形方法

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);

GL画收尾相接的线

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);

GL画线收尾相接的环

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);//擦除正面->逆时针

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);


你可能感兴趣的:(===OpenGL===,openGL)