Why I cannot rotate my cube in PyOpenGL?

I am trying to rotate my cube when I pushed the key 'r' (keyevent), I am using Pyopengl, but I don't know why this doesn't it.

This is a part of my code.

def init(): 
   glMatrixMode (GL_PROJECTION)
   glClearColor(0.529, 0.529, 0.529, 0.0)#Definimos color de ventana
   glColor3f(0.0, 1.0, 1.0)#Definimos color inicial para el cubo

def dibujarCubo():
   glClear (GL_COLOR_BUFFER_BIT)
   glColor3f (1.0, 1.0, 1.0)
   glLoadIdentity ()
   gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   glutWireCube (1.0)
   glFlush ()

def reshape (w, h): #Esta funcion se escarga de reescalar la ventana
   glViewport (0, 0, w, h)
   glLoadIdentity ()
   glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
   glMatrixMode (GL_MODELVIEW)

def keyPressed(*args):
   key = args[0]
   if key == "r" or key =="R":
      glRotatef(30, 1, 0, 0)#Rotate in x

Generally you only want to call OpenGL functions from the display callback.

Modify keyPressed to increment a variable & call glutPostRedisplay() and dibujarCubo to use that variable as a glRotatef() parameter.


尝试在glRotatef()指令下面再次调用dibujarCubo()

链接地址: http://www.djcxy.com/p/81858.html

上一篇: glDrawElements在PyOpenGL中绘制一个立方体

下一篇: 为什么我不能在PyOpenGL中旋转我的多维数据集?