Python OpenGL Can't Redraw Scene

Posted by RobbR on Stack Overflow See other posts from Stack Overflow or by RobbR
Published on 2012-10-18T22:59:06Z Indexed on 2012/10/18 23:00 UTC
Read the original article Hit count: 201

Filed under:
|
|

I'm getting started with OpenGL and shaders using GLUT and PyOpenGL. I can draw a basic scene but for some reason I can't get it to update. E.g. any changes I make during idle(), display(), or reshape() are not reflected.

Here are the methods:

def display(self):      
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glUseProgram(self.shader_program)

    self.m_vbo.bind()

    glEnableClientState( GL_VERTEX_ARRAY )
    glVertexPointerf(self.m_vbo)
    glDrawArrays(GL_TRIANGLES, 0, len(self.m_vbo))

    glutSwapBuffers()
    glutReportErrors()

def idle(self):
    test_change += .1
    self.m_vbo = vbo.VBO(
        array([
            [  test_change, 1, 0 ], # triangle
            [ -1,-1, 0 ],
            [  1,-1, 0 ],
            [  2,-1, 0 ], # square
            [  4,-1, 0 ],
            [  4, 1, 0 ],
            [  2,-1, 0 ],
            [  4, 1, 0 ],
            [  2, 1, 0 ],
        ],'f')
    )
    glutPostRedisplay()

def begin(self):
    glutInit()
    glutInitWindowSize(400, 400)
    glutCreateWindow("Simple OpenGL")
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutDisplayFunc(self.display)
    glutReshapeFunc(self.reshape)
    glutMouseFunc(self.mouse)
    glutMotionFunc(self.motion)
    glutIdleFunc(self.idle)

    self.define_shaders()

    glutMainLoop()

I'd like to implement a time step in idle() but even basic changes to the vertices or tranlastions and rotations on the MODELVIEW matrix don't display. It just puts up the initial state and does not update. Am I missing something?

© Stack Overflow or respective owner

Related posts about python

Related posts about opengl