这时就调用glPopMatrix从栈里取出一个“状态”了,这个状态就是你调用glPushMatrix之前的那个状态。...然后你再随便做第二次移动或旋转变换,再用glPopMatrix(); OpenGL 就把刚刚保存的那个位置和角度恢复。...将本次需要执行的缩放、平移等操作放在glPushMatrix和glPopMatrix之间。glPushMatrix()和glPopMatrix()的配对使用可以消除上一次的变换对本次变换的影响。...3)将modelview变换放在glPushMatrix和glPopMatrix之间可以使本次变换和上次变换独立。...(); // 可以看出glPushMatrix和glPopMatrix之间的变换效果被消除。
本篇先谈一下glpushmatrix和glpopmatrix这两个函数吧。 opengl中的坐标变换,总是针对当前矩阵,如果当前矩阵为M,紧跟的变换矩阵为I,则执行完I后,当前矩阵变为M*I。...一个方法是把当前矩阵M*I/I,但这样做不仅麻烦,而且还会遇到其它问题;另一种方法就是我们把状态M保存下来,但需要的时候再调出来,这时就该glpushmatrix与glpopmatrix上场了。...M,使用glpushmatrix将当前矩阵M的副本M1压入栈顶,当前矩阵变为M1=M,当执行下一步的矩阵变换I后,当前矩阵变为M1*I,执行完相应的绘画功能后,我们希望下一步的操作的当前矩阵为M,使用glpopmatrix
强大的opengl就帮我们提供了两个函数:giPushMatrix()和glPopMatrix(); 首先我们要知道,对于矩阵的操作都是对于矩阵栈的栈顶来操作的。...当经过一系列的变换后,栈顶矩阵被修改,此时调用glPopMatrix()时,栈顶矩阵被弹出,且又会恢复为原来的状态。 函数的作用过程可以用下图描述,更为直观。...所以在场景中存在多种矩阵变换时,glPushMatrix()和glPopMatrix()一般情况下也要结合glMatrixMode(GLenum mode)运用,系统才知道具体操作的是哪个矩阵栈。...day, 0.0, 1.0, 0.0); 25 glutWireSphere(0.2, 10, 8); /* draw smaller planet */ 26 } 27 glPopMatrix
写入代码; glPushMatrix(); glColor3f(1,0,0); //写入代码; glutSolidCube(1); //绘制立方体身 glPopMatrix...glPushMatrix(); glColor3f(1,1,0); //写入代码; glutSolidCube(1); //绘制立方体头 glPopMatrix...glPushMatrix(); glColor3f(1,0.5,0.2); //写入代码; glutSolidCube(1); //绘制立方体手 glPopMatrix...glPushMatrix(); glColor3f(1,0.5,0.2); //写入代码; glutSolidCube(1); //绘制立方体手 glPopMatrix...glPushMatrix(); glColor3f(0.5,0.5,1); //写入代码; glutSolidCube(1); //绘制立方体腿 glPopMatrix
用缩放矩阵乘以当前矩阵,格式为glScalef(x缩放比例,y缩放比例,z缩放比例) glutWireCube(1.0f);//glut库函数,画一个三维的Cube,参数为边长 glPopMatrix...0.0f); glPushMatrix(); glScalef(2.0f, 0.4f, 1.0f); glutWireCube(1.0f); glPopMatrix...(); glPopMatrix(); glFlush(); } void reshape (int width, int height) { glViewport...display()中用到了glPushMatrix()和glPopMatrix(),事实上glPushMatrix()可以理解为建立一个局部坐标系,glPopMatrix()恢复全局坐标系,它们可以嵌套使用
当需要恢复最近一次的保存时,调用glPopMatrix()函数,它相当于从堆栈栈顶弹出一个矩阵为当前矩阵。...glRotatef(45.0,0.0,0.0,1.0); glColor3f (0.0, 1.0, 0.0); drawSquare(); //中间左菱形 glPopMatrix...glRotatef(45.0,0.0,0.0,1.0); glColor3f (0.0, 0.7, 0.0); drawSquare(); //中间中菱形 glPopMatrix...glRotatef(45.0,0.0,0.0,1.0); glColor3f (0.0, 0.4, 0.0); drawSquare(); //中间右菱形 glPopMatrix...(); glPopMatrix(); glTranslatef(0.0,-3.0,0.0); glScalef(4.0,1.5,1.0); glColor3f (0.0, 0.0
gl.glPushMatrix(); gl.glTranslatef(0, 2, 0); gl.glColor3f(0.8f, 0.8f, 0.8f); gl.glPopMatrix(...glu.gluOrtho2D(0, windowWidth, 0, windowHeight); gl.glRasterPos2f(windowWidth / 2, windowHeight / 2); gl.glPopMatrix...(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); } ...}
glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glutSolidTorus(1.0f, 2.0f, 30.0f, 30.0f);//绘制圆环 } glPopMatrix...glColor4f(0.0f, 1.0f, 0.0f, 0.5); glutSolidSphere(2.0f, 30.0f, 30.0f);//绘制球体 } glPopMatrix...0, 0); glVertex3f(5, 0, 0); glVertex3f(5, 5, 0); glVertex3f(0, 5, 0); glEnd(); glPopMatrix...0, 0); glVertex3f(5, 0, 0); glVertex3f(5, 5, 0); glVertex3f(0, 5, 0); glEnd(); glPopMatrix
当需要恢复最近一次的保存时,调用glPopMatrix()函数,它相当于从堆栈栈顶弹出一个矩阵为当前矩阵。...glTranslatef(2.0,3.0,0.0); //向右移动2单位,向上移动3单位 glColor3f (0.0, 1.0, 0.0); drawSquare(); //绘制边长为2绿色正方形 glPopMatrix...向上移动3单位 glRotatef(30,0.0,0.0,1.0); //顺时针旋转30角度 glColor3f (0.0, 1.0, 0.0); drawSquare(); //绘制边长为2绿色正方形 glPopMatrix...glTranslatef(0.0f,2.0f,0.0f); glScalef(3.0,0.5,1.0); glColor3f (1.0, 0.0, 0.0); drawSquare(); //上面红色矩形 glPopMatrix...(); glPopMatrix(); glTranslatef(0.0,-3.0,0.0); glScalef(4.0,1.5,1.0); glColor3f (0.0, 0.0, 1.0); drawSquare
fEarth, 0.0f, 1.0f, 0.0f); glTranslatef(200.0f, 0.0f, 0.0f); glutSolidSphere(20.0f, 20, 20); //画地球 glPopMatrix...(); glPopMatrix(); glRotatef(6.0f, 1.0f, 1.0f, 1.0f); glRotatef(fMoon, 0.0f, 1.0f, 0.0f); glColor3f
当需要恢复最近一次的保存时,调用glPopMatrix()函数,它相当于从堆栈栈顶弹出一个矩阵为当前矩阵。...0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glutWireSphere(0.2, 10, 8); /* draw smaller planet */ glPopMatrix...提示:使用glPushMatrix()和glPopMatrix()在适当的时候保存和恢复坐标系统的位置。
*sin(2*PI/n*i)); //发出结束绘图命令 glEnd(); //绘图后,恢复绘图前的模型变换矩阵 //这样,对当前图形的变换对后面图形绘制不影响 glPopMatrix...glColor4f(1.0f, 0.0f, 0.0f, 0.5); glutSolidTorus(0.3, 0.7, 30.0f, 30.0f);//绘制实心圆环 } glPopMatrix.../绘制球体 glTranslatef(0, 0, -50); glutSolidSphere(0.4f, 30.0f, 30.0f);//绘制球体 } glPopMatrix
= vertices.end(); iter++ ) glVertex2i( iter->hx(), iter->hy() ); glEnd(); glPopMatrix...glEnd(); } } glDisable( GL_LINE_STIPPLE );//关闭点画模式 glPopMatrix
2, 0, 0); // 平移 glRotatef(rotate, 0, 1, 0); glRotatef(rotate, 1, 0, 0); DrawCube(); glPopMatrix...); glRotatef(rotate, 1, 0, 0); //glScalef(0.5, 0.5, 0.5); // 缩放 DrawCube(); glPopMatrix...glPushMatrix(); glColor3f(0, 0, 1); glTranslatef(movX1, movY1, 0); DrawCube(); glPopMatrix...glPushMatrix(); glColor3f(0, 1, 0); glTranslatef(movX2, movY2, 0); DrawCube(); glPopMatrix
glFlush, glGetFloatv, glLightfv, glLoadIdentity, glMatrixMode, glMultMatrixf, glPopMatrix...node.py文件,导入需要的库: import random from OpenGL.GL import glCallList, glColor3f, glMaterialfv, glMultMatrixf, glPopMatrix...glColor3f(cur_color[0], cur_color[1], cur_color[2]) #渲染对象模型 self.render_self() glPopMatrix...glFlush, glGetFloatv, glLightfv, glLoadIdentity, glMatrixMode, glMultMatrixf, glPopMatrix...glColor3f(cur_color[0], cur_color[1], cur_color[2]) #渲染对象模型 self.render_self() glPopMatrix
glPushMatrix(); glTranslatef(0.0f, 0.0f, -5.0f); glRotated(angle, 1, 1, 0); DrawBox(); glPopMatrix...no_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidSphere(1.0, 20, 20); glPopMatrix...no_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidSphere(1.0, 20, 20); glPopMatrix...low_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidSphere(1.0, 20, 20); glPopMatrix...no_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidSphere(1.0, 20, 20); glPopMatrix
GL_DEPTH_BUFFER_BIT); glPushMatrix (); glRotatef(roangles,0.0,0.0,1.0); glutSolidSphere(2.0,32,32 ); glPopMatrix
领取专属 10元无门槛券
手把手带您无忧上云