在opengl环境下绘球形

在opengl环境下绘球形

ID:12379263

大小:33.00 KB

页数:6页

时间:2018-07-16

在opengl环境下绘球形_第1页
在opengl环境下绘球形_第2页
在opengl环境下绘球形_第3页
在opengl环境下绘球形_第4页
在opengl环境下绘球形_第5页
资源描述:

《在opengl环境下绘球形》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、此程序在OpenGL环境下绘制球体以及填充的矩形。并对球体进行光照效果处理;对矩形进行运动化处理,当矩形与窗口的四边相撞时,程序中的TimerFunction(intvalue)函数可以控制其跳离窗口边缘,改变运动方向。该程序的源代码:#include"stdafx.h"#include#include//InitialsquarepositionandsizeGLfloatx1=100.0f;GLfloaty1=100.0f;GLsizeirsize=50;//Stepsizein

2、xandydirectionsGLfloatxstep=1.0f;GLfloatystep=1.0f;//KeeptrackofwindowschangingwidthandheightGLfloatwindowWidth;GLfloatwindowHeight;//CalledtodrawscenevoidRenderScene(void){glClear(GL_COLOR_BUFFER_BIT

3、GL_DEPTH_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glutSolidSphere(50.0f

4、,200,200);//SetcurrentdrawingcolortoredglColor3f(1.0f,0.0f,0.0f);//DrawafilledrectanglewithcurrentcolorglRectf(x1,y1,x1+rsize,y1+rsize);//FlushdrawingcommandsglutSwapBuffers();}//CalledbyGLUTlibrarywhenidle(windownotbeing//resizedormoved)voidTimerFunction(intvalue){

5、//Reversedirectionwhenyoureachleftorrightedgeif(x1>windowWidth-rsize

6、

7、x1<-windowWidth)xstep=-xstep;//Reversedirectionwhenyoureachtoporbottomedgeif(y1>windowHeight-rsize

8、

9、y1<-windowHeight)ystep=-ystep;//Checkbounds.Thisisincasethewindowismade//smallerandtherectanglei

10、soutsidethenew//clippingvolumeif(x1>windowWidth-rsize)x1=windowWidth-rsize-1;if(y1>windowHeight-rsize)y1=windowHeight-rsize-1;//Actuallymovethesquarex1+=xstep;y1+=ystep;//RedrawthescenewithnewcoordinatesglutPostRedisplay();glutTimerFunc(33,TimerFunction,1);}//Setupt

11、herenderingstatevoidSetupRC(void){staticfloatred_light[4]={1.0,0.0,0.0,1.0};//定义红色光源staticfloatred_pos[4]={1.0,1.0,1.0,0.0};staticfloatblue_light[4]={0.0,0.0,1.0,1.0};//定义绿色光源staticfloatblue_pos[4]={-1.0,-1.0,-1.0,0.0};glLightfv(GL_LIGHT0,GL_DIFFUSE,red_light);glLig

12、htfv(GL_LIGHT0,GL_POSITION,red_pos);glLightfv(GL_LIGHT1,GL_DIFFUSE,blue_light);glLightfv(GL_LIGHT1,GL_POSITION,blue_pos);/*Enabledrawingfeaturesthatweneed...*/glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_LIGHT1);//Setclearcolortoblue

13、glClearColor(0.5f,0.5f,1.0f,1.0f);}//CalledbyGLUTlibrarywhenthewindowhaschanagedsizevoidChangeSize(GLsizeiw,GLsizeih){//Preventadividebyze

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。