I'm trying to play around with OpenGl and python on macos. And when I run the code from tutorial I get errors:
GLUT Warning: The following is a new check for GLUT 3.0; update your code.
GLUT Fatal Error: redisplay needed for window 1, but no display callback.
The code I try to run:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(300, 300)
glutInitWindowPosition(50, 50)
glutInit(sys.argv)
glutCreateWindow(b"Happy New Year!")
glutMainLoop()
There's already a question about this problem on Stack Overflow , but a clear answer wasn't given to this question. As far as I understand, I should add
glutDisplayFunc(glutCreateWindow)
right before
glutMainLoop()
But if I do so, I get another error:
TypeError: this function takes at least 1 argument (0 given)
What's wrong?
glutMainLoop
runns the event processing loop. When doing this, the callback function which is set by glutDisplayFunc
is called. You have to implement and set this function:
eg
def display:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
# do the drawing
# .....
glutSwapBuffers()
glutPostRedisplay()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(300, 300)
glutInitWindowPosition(50, 50)
glutInit(sys.argv)
glutCreateWindow(b"Happy New Year!")
glutDisplayFunc(display)
glutMainLoop()
Note, glutPostRedisplay
marks the current window as needing to be redisplayed, this causes the window to be redisplayed continuously. glutSwapBuffers
swaps the buffers of the current window, this means it makes the drawing "visible" on the viewport.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.