vc环境下的OpenGL编程

上传人:fgh****35 文档编号:253041524 上传时间:2024-11-27 格式:PPT 页数:11 大小:42KB
返回 下载 相关 举报
vc环境下的OpenGL编程_第1页
第1页 / 共11页
vc环境下的OpenGL编程_第2页
第2页 / 共11页
vc环境下的OpenGL编程_第3页
第3页 / 共11页
点击查看更多>>
资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,*,*,vc,环境下,OpenGL,编程:,Win32,应用编程,OpenGL,学习资源网站:,百度,nehe,教程,一、程序主流程,程序主进程:,WinMain,创建窗口,CreateGLWindow,进入主窗口消息循环,退出,二、,OpenGL,窗口创建及初始化,程序主进程:,WinMain,创建窗口,CreateGLWindow,进入主窗口消息循环,退出,注册窗口类:,RegisterClass,显示设置:,ChangeDisplaySettings,调整窗口大小:,AdjustWindowRectEx,创建:,CreateWindowEx,选择,像素格式,:ChoosePixelFormat,设置,像素格式,:,SetPixelFormat,创建,OpenGL,渲染上下文:,wglCreateContext,激活,OpenGL,渲染上下文:,wglMakeCurrent,显示窗口:,ShowWindow,调整,OpenGL,视口大小:,ReSizeGLScene,OpenGL,绘制选项初始化:,InitGL,HDC,hDC,=NULL;,/,基本图形设备接口上下文,选择和设置,像素格式,时,使用,HGLRC,hRC,=NULL;,/,永久渲染上下文,创建和激活,OpenGL,渲染上下文时使用,HWND,hWnd,=NULL;/,窗口句柄,HINSTANCE,hInstance,;/,应用实例句柄,三、调整,OpenGL,视口,glViewport(0,0,width,height);/,设置当前视口大小,glMatrixMode(GL_PROJECTION,);/,选择投影矩阵模式,glLoadIdentity,();/,重置投影矩阵,/,计算,OpenGL,观察窗口参数:视角、宽高比、近裁剪面、,/,远裁剪面,gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.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_LEQUAL,:,当前深度值小于或等于深度缓存中的深度值时进行绘制,glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);/,高质量投影计算,五、,OpenGL,图形绘制,glClear(GL_COLOR_BUFFER_BIT,|GL_DEPTH_BUFFER_BIT);/,初始化颜色缓存和深度缓存,glLoadIdentity,();glTranslatef(-1.5f,0.0f,-6.0f);glRotatef(rtri,0.0f,1.0f,0.0f);,glBegin(GL_TRIANGLES,);/,绘制四菱锥,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,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);,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(rquad,1.0f,1.0f,1.0f);,glBegin(GL_QUADS,);,glColor3f(0.0f,1.0f,0.0f);,glVertex3f(1.0f,1.0f,-1.0f);glVertex3f(-1.0f,1.0f,-1.0f);,glVertex3f(-1.0f,1.0f,1.0f);glVertex3f(1.0f,1.0f,1.0f);,glColor3f(1.0f,0.5f,0.0f);,glVertex3f(1.0f,-1.0f,1.0f);glVertex3f(-1.0f,-1.0f,1.0f);,glVertex3f(-1.0f,-1.0f,-1.0f);glVertex3f(1.0f,-1.0f,-1.0f);,glColor3f(1.0f,0.0f,0.0f);,glVertex3f(1.0f,1.0f,1.0f);glVertex3f(-1.0f,1.0f,1.0f);,glVertex3f(-1.0f,-1.0f,1.0f);glVertex3f(1.0f,-1.0f,1.0f);,glColor3f(1.0f,1.0f,0.0f);,glVertex3f(1.0f,-1.0f,-1.0f);glVertex3f(-1.0f,-1.0f,-1.0f);,glVertex3f(-1.0f,1.0f,-1.0f);glVertex3f(1.0f,1.0f,-1.0f);,glColor3f(0.0f,0.0f,1.0f);,glVertex3f(-1.0f,1.0f,1.0f);glVertex3f(-1.0f,1.0f,-1.0f);,glVertex3f(-1.0f,-1.0f,-1.0f);glVertex3f(-1.0f,-1.0f,1.0f);,glColor3f(1.0f,0.0f,1.0f);,glVertex3f(1.0f,1.0f,-1.0f);glVertex3f(1.0f,1.0f,1.0f);glVertex3f(1.0f,-1.0f,1.0f);glVertex3f(1.0f,-1.0f,-1.0f);,glEnd,();,/,调整旋转角度,rtri,+=0.2f;,rquad,-=0.15f;,return TRUE;,/,绘制结束,六、主窗口消息循环,程序主进程:,WinMain,创建窗口,CreateGLWindow,进入主窗口消息循环,退出,主窗口消息处理,OpenGL,场景绘制,切换缓存:,SwapBuffers,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 机械制造 > 工业自动化


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!