为什么我不能在 PyOpenGL 中旋转我的立方体?
Why I cannot rotate my cube in PyOpenGL?
当我按下键 'r' (keyevent) 时,我正在尝试旋转我的立方体,我正在使用 Pyopengl,但我不知道为什么不能。
这是我的代码的一部分。
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
尝试在 glRotatef() 指令下再次调用 dibujarCubo()
通常您只想从显示回调中调用 OpenGL 函数。
修改 keyPressed
以增加变量并调用 glutPostRedisplay()
和 dibujarCubo
以将该变量用作 glRotatef()
参数。
当我按下键 'r' (keyevent) 时,我正在尝试旋转我的立方体,我正在使用 Pyopengl,但我不知道为什么不能。
这是我的代码的一部分。
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
尝试在 glRotatef() 指令下再次调用 dibujarCubo()
通常您只想从显示回调中调用 OpenGL 函数。
修改 keyPressed
以增加变量并调用 glutPostRedisplay()
和 dibujarCubo
以将该变量用作 glRotatef()
参数。