Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Event loop integration example

  • Loading branch information...
commit 0afe6a7faa0dc03aed644f3903752bf299239c7e 1 parent f4b8b67
Nicolas P. Rougier authored fperez committed

Showing 1 changed file with 46 additions and 0 deletions. Show diff stats Hide diff stats

  1. +46 0 docs/examples/lib/gui-glut.py
46 docs/examples/lib/gui-glut.py
... ... @@ -0,0 +1,46 @@
  1 +#!/usr/bin/env python
  2 +"""Simple GLUT example to manually test event loop integration.
  3 +
  4 +This is meant to run tests manually in ipython as:
  5 +
  6 +In [5]: %gui glut
  7 +
  8 +In [6]: %run gui-glut.py
  9 +
  10 +In [7]: gl.glClearColor(1,1,1,1)
  11 +"""
  12 +
  13 +#!/usr/bin/env python
  14 +import sys
  15 +import OpenGL.GL as gl
  16 +import OpenGL.GLUT as glut
  17 +
  18 +def display():
  19 + gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
  20 + glut.glutSwapBuffers()
  21 +
  22 +def resize(width,height):
  23 + gl.glViewport(0, 0, width, height+4)
  24 + gl.glMatrixMode(gl.GL_PROJECTION)
  25 + gl.glLoadIdentity()
  26 + gl.glOrtho(0, width, 0, height+4, -1, 1)
  27 + gl.glMatrixMode(gl.GL_MODELVIEW)
  28 +
  29 +
  30 +if glut.glutGetWindow() > 0:
  31 + interactive = True
  32 + glut.glutInit(sys.argv)
  33 + glut.glutInitDisplayMode(glut.GLUT_DOUBLE |
  34 + glut.GLUT_RGBA |
  35 + glut.GLUT_DEPTH)
  36 + glut.glutShowWindow()
  37 +else:
  38 + glut.glutCreateWindow('gui-glut')
  39 + interactive = False
  40 +
  41 +glut.glutDisplayFunc(display)
  42 +glut.glutReshapeFunc(resize)
  43 +gl.glClearColor(0,0,0,1)
  44 +
  45 +if not interactive:
  46 + glut.glutMainLoop()

0 comments on commit 0afe6a7

Please sign in to comment.
Something went wrong with that request. Please try again.