0

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?

0

1 Answer 1

1

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:

e.g.

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.