> VS2012下基于Glut OpenGL GL_TRIANGLE_FAN示例程序:
VS2012下基于Glut OpenGL GL_TRIANGLE_FAN示例程序:
相关推荐:直线可以被画成虚线,而多边形则可以进行镂空。首先,使用glEnable(GL_POLYGON_STIPPLE);来启动镂空模式(使用glDisable(GL_POLYGON_STIPPLE)可以关闭之)。然后,使用glPolygonStipple来设置镂空的样式。void glPolygonStipple(const GLubyte *m
在VS2012下使用glut GL_TRIANGLE_FAN绘制三角形示例程序,绘制的是多个三角形,效果如下图所示,按PC的UP,DOWN,LEFT,RIGHT按键可以从不同的角度查看该图形:GL_TRIANGLE_FAN对序列点生成三角形的处理方式参考下图与http://blog.csdn.net/yearafteryear/article/details/9059795就可以看得很清楚:源代码:// GlutTriangleFanDemo.cpp : 定义控制台应用程序的入口点。//#include &stdafx.hinclude &gl/glut.hinclude &math.h&//圆周率宏#define GL_PI 3.1415f//获取屏幕的宽度GLint SCREEN_WIDTH=0;GLint SCREEN_HEIGHT=0;//设置程序的窗口大小GLint windowWidth=400;GLint windowHeight=300;//绕x轴旋转角度GLfloat xRotAngle=0.0f;//绕y轴旋转角度GLfloat yRotAngle=0.0f;//显示回调函数void renderScreen(void){GLfloat x,y,z,//把整个窗口清理为当前清理颜色:黑色glClear(GL_COLOR_BUFFER_BIT);//将当前Matrix状态入栈glPushMatrix();//坐标系绕x轴旋转xRotAngleglRotatef(xRotAngle,1.0f,0.0f,0.0f);//坐标系绕y轴旋转yRotAngleglRotatef(yRotAngle,0.0f,1.0f,0.0f); //进行平滑处理glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH,GL_NICEST); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH,GL_NICEST); //使用白色绘制坐标系 glColor3f(1.0f,1.0f,1.0f); //绘制坐标系 glBegin(GL_LINES);glVertex3f(-80.0f,0.0f,0.0f);glVertex3f(80.0f,0.0f,0.0f);glVertex3f(0.0f,-80.0f,0.0f);glVertex3f(0.0f,80.0f,0.0f);glVertex3f(0.0f,0.0f,-80.0f);glVertex3f(0.0f,0.0f,80.0f); glEnd(); glPushMatrix(); glTranslatef(80.0f,0.0f,0.0f); glRotatef(90.0f,0.0f,1.0f,0.0f); glutWireCone(3,6,10,10); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,80.0f,0.0f); glRotatef(-90.0f,1.0f,0.0f,0.0f); glutWireCone(3,6,10,10); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f,0.0f,80.0f); glRotatef(90.0f,0.0f,0.0f,1.0f); glutWireCone(3,6,10,10); glPopMatrix(); //坐标系平移到(-50.0f,0.0f,00.0f) glPushMatrix(); glTranslatef(-50.0f,0.0f,00.0f); //白色绘制五个顶点 glColor3f(1.0f,1.0f,1.0f); glPointSize(5.0f); glBegin(GL_POINTS);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(25.0f,25.0f,0.0f);glVertex3f(0.0f,50.0f,0.0f);glVertex3f(-25.0f,25.0f,0.0f);glVertex3f(-25.0f,0.0f,0.0f); glEnd(); //GL_FLAT使用单色模式填充三角形//GL_SMOOTH使用颜色平滑变换模式填充三角形glShadeModel(GL_FLAT); //使用GL_TRIANGLE_FAN绘制三角形 glBegin(GL_TRIANGLE_FAN);//使用红色绘制第一个三角形glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(25.0f,25.0f,0.0f);glVertex3f(0.0f,50.0f,0.0f);//使用绿色绘制第二个三角形glColor3f(0.0f,1.0f,0.0f);glVertex3f(-25.0f,25.0f,0.0f);//使用蓝色绘制第三个三角形glColor3f(0.0f,0.0f,1.0f);glVertex3f(-25.0f,0.0f,0.0f); //结束GL_TRIANGLE_FAN绘制三角形 glEnd(); glPopMatrix();//坐标系平移到(50.0f,0.0f,00.0f) glPushMatrix(); glTranslatef(50.0f,0.0f,00.0f); //白色绘制五个顶点 glColor3f(1.0f,1.0f,1.0f); glPointSize(5.0f); glBegin(GL_POINTS);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(25.0f,25.0f,0.0f);glVertex3f(0.0f,50.0f,0.0f);glV相关推荐:模板测试是把像素存储在模板缓冲区的值与一个参考值进行比较。根据测试的结果,对模板缓冲区中得这个值进行相应的修改。Note:模板测试只有在存在模板缓冲区的情况下才会执行,如果不存在模板缓冲区,模板测试能够通过。模板测试最常用的用途就是屏蔽掉屏ertex3f(-25.0f,25.0f,0.0f);glVertex3f(-25.0f,0.0f,0.0f); glEnd(); //GL_FLAT使用单色模式填充三角形//GL_SMOOTH使用颜色平滑变换模式填充三角形glShadeModel(GL_SMOOTH); //使用GL_TRIANGLE_FAN绘制三角形 glBegin(GL_TRIANGLE_FAN);//使用红色绘制第一个三角形glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(25.0f,25.0f,0.0f);glVertex3f(0.0f,50.0f,0.0f);//使用绿色绘制第二个三角形glColor3f(0.0f,1.0f,0.0f);glVertex3f(-25.0f,25.0f,0.0f);//使用蓝色绘制第三个三角形glColor3f(0.0f,0.0f,1.0f);glVertex3f(-25.0f,0.0f,0.0f); //结束GL_TRIANGLE_FAN绘制三角形 glEnd(); glPopMatrix();//恢复压入栈的MatrixglPopMatrix();//交换两个缓冲区的指针glutSwapBuffers();}//设置Redering State void setupRederingState(void){//设置清理颜色为黑色glClearColor(0.0f,0.0,0.0,1.0f);//设置绘画颜色为绿色glColor3f(0.0f,1.0f,0.0f);}//窗口大小变化回调函数void changSize(GLint w,GLint h){//横宽比率GL//设置坐标系为x(-100.0f,100.0f)、y(-100.0f,100.0f)、z(-100.0f,100.0f)GLfloat coordinatesize=100.0f;//窗口宽高为零直接返回if((w==0)||(h==0))//设置视口和窗口大小一致glViewport(0,0,w,h);//对投影矩阵应用随后的矩阵操作glMatrixMode(GL_PROJECTION);//重置当前指定的矩阵为单位矩阵glLoadIdentity();ratio=(GLfloat)w/(GLfloat)h;//正交投影if(w&h)glOrtho(-coordinatesize,coordinatesize,-coordinatesize/ratio,coordinatesize/ratio,-coordinatesize,coordinatesize);elseglOrtho(-coordinatesize*ratio,coordinatesize*ratio,-coordinatesize,coordinatesize,-coordinatesize,coordinatesize);//对模型视图矩阵堆栈应用随后的矩阵操作glMatrixMode(GL_MODELVIEW);//重置当前指定的矩阵为单位矩阵glLoadIdentity();}//按键输入处理回调函数void specialKey(int key,int x,int y){if(key==GLUT_KEY_UP){xRotAngle-=5.0f;}else if(key==GLUT_KEY_DOWN){xRotAngle+=5.0f;}else if(key==GLUT_KEY_LEFT){yRotAngle-=5.0f;}else if(key==GLUT_KEY_RIGHT){yRotAngle+=5.0f;}//重新绘制glutPostRedisplay();}int main(int argc, char* argv[]){//初始化glutglutInit(&argc,argv);//使用双缓冲区模式glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);//获取系统的宽像素SCREEN_WIDTH=glutGet(GLUT_SCREEN_WIDTH);//获取系统的高像素SCREEN_HEIGHT=glutGet(GLUT_SCREEN_HEIGHT); //创建窗口,窗口名字为OpenGL TriAngleFan DemoglutCreateWindow(&OpenGL TriAngleFan Demo&);//设置窗口大小glutReshapeWindow(windowWidth,windowHeight);//窗口居中显示glutPositionWindow((SCREEN_WIDTH-windowWidth)/2,(SCREEN_HEIGHT-windowHeight)/2);//窗口大小变化时的处理函数glutReshapeFunc(changSize);//设置显示回调函数glutDisplayFunc(renderScreen);//设置按键输入处理回调函数glutSpecialFunc(specialKey);//设置全局渲染参数setupRederingState();glutMainLoop();return 0;}
相关推荐:
Glut下提供了一些现成的绘制立体的API,如glutWireSphere绘制球,glutWireCone绘制椎体,glutWireCube绘制立体,glutWireTorus绘制甜圈,glutWireTeapot绘制茶壶,glutWireOctahedron绘制八面体。
Demo程序利用这些API绘制相应的立体,单击鼠标右键
在VS2012下使用glut GL_TRIANGLE_FAN绘制三角形示例程序,绘制的是多个三角形,效果如下图所示,按PC的UP,DOWN,LEFT,RIGHT按键可以从不同的角度查看该图形:GL_TRIANGLE_FAN对序列点生成三角...
------分隔线----------------------------
相关阅读排行