OpenGL绘制的几类三维实体.DOC

上传人:天*** 文档编号:901442 上传时间:2018-11-05 格式:DOC 页数:5 大小:43KB
下载 相关 举报
OpenGL绘制的几类三维实体.DOC_第1页
第1页 / 共5页
OpenGL绘制的几类三维实体.DOC_第2页
第2页 / 共5页
OpenGL绘制的几类三维实体.DOC_第3页
第3页 / 共5页
OpenGL绘制的几类三维实体.DOC_第4页
第4页 / 共5页
OpenGL绘制的几类三维实体.DOC_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、OpenGL 绘制的几类三维实体EXAM304_H/防止重复嵌入#if !defined _EXAM304_H_#define _EXAM304_H_/指定嵌入文件#include#include/宏#define RADIUS 50.0f#define SIZE 100.0f#define CONE 1#define TETRAHEDRON 2#define CUBE 3#define DODECAHEDRON 4#define ICOSAHEDRON 5#define OCTAHEDRON 6#define SPHERE 7#define TORUS 8#define TEAPOT 9#d

2、efine WIRED 10/全局变量GLboolean bWire=false;GLint nSelected=CONE;/函数原型void OnDisplay(void);void OnReshape(int,int);void OnMenu(int value);void CreateMenu();void SetupLights();#endifEXAM304.cpp#include “EXAM304.H“void main(int argc,char *argv)glutInit(glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH)

3、;glutInitWindowSize(640,480);glutInitWindowPosition(10,10);glutCreateWindow(“EXAM304“);glutCreateMenu(OnMenu);glutDisplayFunc(OnDisplay);glutReshapeFunc(OnReshape);CreateMenu();SetupLights();glutMainLoop();void OnDisplay(void)glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glEnable(GL_DEPTH_TEST);g

4、lPushMatrix();glColor3f(0.0f,1.0f,1.0f);glEnable(GL_NORMALIZE);switch(nSelected)case(CONE):if(bWire)glutWireCone(RADIUS,2*RADIUS,30,30);elseglutSolidCone(RADIUS,2*RADIUS,30,30);break;case(TETRAHEDRON):glPushMatrix();glScalef(RADIUS,RADIUS,RADIUS);if(bWire)glutWireTetrahedron();elseglutSolidTetrahedr

5、on();glPopMatrix();break;case(CUBE):if(bWire)glutWireCube(1.5*RADIUS);elseglutSolidCube(1.5*RADIUS);break;case(DODECAHEDRON):glPushMatrix();glScalef(RADIUS/2,RADIUS/2,RADIUS/2);if(bWire)glutWireDodecahedron();elseglutSolidDodecahedron();glPopMatrix();break;case(ICOSAHEDRON):glPushMatrix();glScalef(R

6、ADIUS,RADIUS,RADIUS);if(bWire)glutWireIcosahedron();elseglutSolidIcosahedron();glPopMatrix();break;case(OCTAHEDRON):glPushMatrix();glScalef(RADIUS,RADIUS,RADIUS);if(bWire)glutWireOctahedron();elseglutSolidOctahedron();glPopMatrix();break;case(SPHERE):if(bWire)glutWireSphere(RADIUS,30,30);elseglutSol

7、idSphere(RADIUS,30,30);break;case(TORUS):if(bWire)glutWireTorus(RADIUS/2,RADIUS,30,30);elseglutSolidTorus(RADIUS/2,RADIUS,30,30);break;case(TEAPOT):if(bWire)glutWireTeapot(RADIUS);elseglutSolidTeapot(RADIUS);glPopMatrix();glutSwapBuffers();/窗口尺寸变化后的回调函数void OnReshape(int w,int h)glViewport(0,0,w,h);

8、glMatrixMode(GL_PROJECTION);glLoadIdentity();float aspect=(float)h/(float)w;if(w=h)glOrtho(-SIZE,SIZE,-SIZE*aspect,SIZE*aspect,-SIZE,SIZE);elseglOrtho(-SIZE/aspect,SIZE/aspect,-SIZE,SIZE,-SIZE,SIZE);gluLookAt(10.0f,20.0f,25.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);void OnMenu(int value)if(value=WIRED)bWire

9、=!bWire;elsenSelected=value;glutPostRedisplay();void CreateMenu()glutAddMenuEntry(“圆锥体“,CONE);glutAddMenuEntry(“四面体“,TETRAHEDRON);glutAddMenuEntry(“正方体“,CUBE);glutAddMenuEntry(“正十二面体“,DODECAHEDRON);glutAddMenuEntry(“正二十面体“,ICOSAHEDRON);glutAddMenuEntry(“正八面体“,OCTAHEDRON);glutAddMenuEntry(“球体“,SPHERE

10、);glutAddMenuEntry(“圆环体“,TORUS);glutAddMenuEntry(“茶壶“,TEAPOT);glutAddMenuEntry(“线框或实体“,WIRED);glutAttachMenu(GLUT_RIGHT_BUTTON);void SetupLights()GLfloat ambientLight=0.2f,0.2f,0.2f,1.0f;GLfloat diffuseLight=0.9f,0.9f,0.9f,1.0f;GLfloat specularLight=1.0f,1.0f,1.0f,1.0f;GLfloat lightPos=50.0f,100.0f,

11、80.0f,1.0f;glEnable(GL_LIGHTING);glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight);glLightfv(GL_LIGHT0,GL_POSITION,lightPos);glEnable(GL_LIGHT0);glEnable(GL_COLOR_MATERIAL);glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);glMaterialfv(GL_FRONT,GL_SPECULAR,specularLight);glMateriali(GL_FRONT,GL_SHININESS,100);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 重点行业资料库 > 1

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。