vc环境下的OpenGL编程.ppt

vc环境下的OpenGL编程.ppt

ID:51489212

大小:42.00 KB

页数:11页

时间:2020-03-24

vc环境下的OpenGL编程.ppt_第1页
vc环境下的OpenGL编程.ppt_第2页
vc环境下的OpenGL编程.ppt_第3页
vc环境下的OpenGL编程.ppt_第4页
vc环境下的OpenGL编程.ppt_第5页
资源描述:

《vc环境下的OpenGL编程.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、vc环境下OpenGL编程:Win32应用编程OpenGL学习资源网站:nehe.gamedev.net百度nehe教程一、程序主流程程序主进程:WinMain创建窗口CreateGLWindow进入主窗口消息循环退出二、OpenGL窗口创建及初始化程序主进程:WinMain创建窗口CreateGLWindow进入主窗口消息循环退出注册窗口类:RegisterClass显示设置:ChangeDisplaySettings调整窗口大小:AdjustWindowRectEx创建:CreateWindow

2、Ex选择像素格式:ChoosePixelFormat设置像素格式:SetPixelFormat创建OpenGL渲染上下文:wglCreateContext激活OpenGL渲染上下文:wglMakeCurrent显示窗口:ShowWindow调整OpenGL视口大小:ReSizeGLSceneOpenGL绘制选项初始化:InitGLHDChDC=NULL;//基本图形设备接口上下文,选择和设置像素格式时使用HGLRChRC=NULL;//永久渲染上下文,创建和激活OpenGL渲染上下文时使用HWNDh

3、Wnd=NULL;//窗口句柄HINSTANCEhInstance;//应用实例句柄三、调整OpenGL视口glViewport(0,0,width,height);//设置当前视口大小glMatrixMode(GL_PROJECTION);//选择投影矩阵模式glLoadIdentity();//重置投影矩阵//计算OpenGL观察窗口参数:视角、宽高比、近裁剪面、//远裁剪面gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.

4、0f);glMatrixMode(GL_MODELVIEW);//选择模型矩阵模式glLoadIdentity();//重置模型矩阵四、OpenGL绘制选项初始化glShadeModel(GL_SMOOTH);//打开平滑阴影:glClearColor(0.0f,0.0f,0.0f,0.5f);//黑色背景glClearDepth(1.0f);//深度缓存初始化glEnable(GL_DEPTH_TEST);//打开深度测试glDepthFunc(GL_LEQUAL);//深度测试类型,GL_LEQ

5、UAL:当前深度值小于或等于深度缓存中的深度值时进行绘制glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);//高质量投影计算五、OpenGL图形绘制glClear(GL_COLOR_BUFFER_BIT

6、GL_DEPTH_BUFFER_BIT);//初始化颜色缓存和深度缓存glLoadIdentity();glTranslatef(-1.5f,0.0f,-6.0f);glRotatef(rtri,0.0f,1.0f,0.0f);glBegin(GL_T

7、RIANGLES);//绘制四菱锥glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,1.0f,0.0f);glColor3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,1.0f);glColor3f(0.0f,0.0f,1.0f);glVertex3f(1.0f,-1.0f,1.0f);glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,1.0f,0.0f);glColor3f(0.0f,0.0f,

8、1.0f);glVertex3f(1.0f,-1.0f,1.0f);glColor3f(0.0f,1.0f,0.0f);glVertex3f(1.0f,-1.0f,-1.0f);glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,1.0f,0.0f);glColor3f(0.0f,1.0f,0.0f);glVertex3f(1.0f,-1.0f,-1.0f);glColor3f(0.0f,0.0f,1.0f);glVertex3f(-1.0f,-1.0f,-1.0f)

9、;glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,1.0f,0.0f);glColor3f(0.0f,0.0f,1.0f);glVertex3f(-1.0f,-1.0f,-1.0f);glColor3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,1.0f);glEnd();//绘制立方体glLoadIdentity();glTranslatef(1.5f,0.0f,-7.0f);glRotatef

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

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

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