资源描述:
《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