資源描述:
《opengl初探部分代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、將Onsize代碼替換成如下的代碼,使前述的平行投影變成透視投影voidCMyOpenGLView::OnSize(UINTnType,intcx,intcy){glViewport(0,0,cx,cy);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45,(float)cx/(float)cy,0.1,15);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}以下是修改Draw方法的代碼,以實現(xiàn)不同的功
2、能//2D圖形繪制glClearColor(0,0,0,1);glClear(GL_COLOR_BUFFER_BIT
3、GL_DEPTH_BUFFER_BIT);glLoadIdentity();glShadeModel(GL_SMOOTH);glTranslatef(-1.5f,1.0f,-7.0f);glColor3f(1.0f,0.0f,0.0f);glBegin(GL_TRIANGLES);glVertex3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);glVer
4、tex3f(1.0f,-1.0f,0.0f);glEnd();glTranslatef(3.0f,0.0f,0.0f);glColor3f(0.0f,0.0f,1.0f);glBegin(GL_QUADS);glVertex3f(-1.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f);glVertex3f(1.0f,1.0f,0.0f);glEnd();glTranslatef(-1.5f,-2.5f,0.0f);glColo
5、r3f(1.0f,1.0f,0.0f);glLineWidth(2.0f);glBegin(GL_LINE_LOOP);for(inti=0;i<200;i++)glVertex3f(1.0*float(sin(2*3.14*i/200)),1.0*float(cos(2*3.14*i/200)),0.0);glEnd();SwapBuffers(m_hDC);glFlush();//陰暗處理glClearColor(0,0,0,1);glClear(GL_COLOR_BUFFER_BIT
6、GL_DEPTH_BUFF
7、ER_BIT);glLoadIdentity();glShadeModel(GL_SMOOTH);//設(shè)置平滑插值glTranslatef(-1.5f,1.0f,-7.0f);glColor3f(1.0f,0.0f,0.0f);glBegin(GL_TRIANGLES);glColor3ub(255,0,0);glVertex3f(0.0f,1.0f,0.0f);glColor3ub(0,255,0);glVertex3f(-1.0f,-1.0f,0.0f);glColor3ub(255,255,0);glVerte
8、x3f(1.0f,-1.0f,0.0f);glEnd();glTranslatef(3.0f,0.0f,0.0f);glColor3ub(0,255,255);glBegin(GL_QUADS);glVertex3f(-1.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f);glVertex3f(1.0f,1.0f,0.0f);glEnd();glTranslatef(-1.5f,-2.5f,0.0f);glColor3f(1.
9、0f,1.0f,0.0f);glLineWidth(2.0f);glBegin(GL_LINE_LOOP);for(inti=0;i<200;i++)glVertex3f(1.0*float(sin(2*3.14*i/200)),1.0*float(cos(2*3.14*i/200)),0.0);glEnd();SwapBuffers(m_hDC);glFlush();//3D圖形glClearColor(0,0,0,1);glClear(GL_COLOR_BUFFER_BIT
10、GL_DEPTH_BUFFER_BIT
11、);glLoadIdentity();glTranslatef(-2.0f,0.0f,-8.0f);glBegin(GL_TRIANGLES);//正面glColor3ub(217,167,22);glVertex3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,1.0f);glVertex3f(1.0f,-1