資源描述:
《vc環(huán)境下的OpenGL編程.ppt》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、vc環(huán)境下OpenGL編程:Win32應(yīng)用編程OpenGL學(xué)習(xí)資源網(wǎng)站:nehe.gamedev.net百度nehe教程一、程序主流程程序主進(jìn)程:WinMain創(chuàng)建窗口CreateGLWindow進(jìn)入主窗口消息循環(huán)退出二、OpenGL窗口創(chuàng)建及初始化程序主進(jìn)程:WinMain創(chuàng)建窗口CreateGLWindow進(jìn)入主窗口消息循環(huán)退出注冊窗口類:RegisterClass顯示設(shè)置:ChangeDisplaySettings調(diào)整窗口大?。篈djustWindowRectEx創(chuàng)建:CreateWindow
2、Ex選擇像素格式:ChoosePixelFormat設(shè)置像素格式:SetPixelFormat創(chuàng)建OpenGL渲染上下文:wglCreateContext激活OpenGL渲染上下文:wglMakeCurrent顯示窗口:ShowWindow調(diào)整OpenGL視口大?。篟eSizeGLSceneOpenGL繪制選項(xiàng)初始化:InitGLHDChDC=NULL;//基本圖形設(shè)備接口上下文,選擇和設(shè)置像素格式時(shí)使用HGLRChRC=NULL;//永久渲染上下文,創(chuàng)建和激活OpenGL渲染上下文時(shí)使用HWNDh
3、Wnd=NULL;//窗口句柄HINSTANCEhInstance;//應(yīng)用實(shí)例句柄三、調(diào)整OpenGL視口glViewport(0,0,width,height);//設(shè)置當(dāng)前視口大小glMatrixMode(GL_PROJECTION);//選擇投影矩陣模式glLoadIdentity();//重置投影矩陣//計(jì)算OpenGL觀察窗口參數(shù):視角、寬高比、近裁剪面、//遠(yuǎn)裁剪面gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.
4、0f);glMatrixMode(GL_MODELVIEW);//選擇模型矩陣模式glLoadIdentity();//重置模型矩陣四、OpenGL繪制選項(xiàng)初始化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:當(dāng)前深度值小于或等于深度緩存中的深度值時(shí)進(jìn)行繪制glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);//高質(zhì)量投影計(jì)算五、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