-
Notifications
You must be signed in to change notification settings - Fork 1
/
glut_example2d.py
49 lines (38 loc) · 1.01 KB
/
glut_example2d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import common2d, sys
import OpenGL.GLUT as glut
import OpenGL.GL as gl
_myProg = None
def displayFunc():
global _myProg
common2d.display(_myProg)
glut.glutSwapBuffers()
def set_global_program(program):
global _myProg
_myProg = program
def reshape(width,height):
gl.glViewport(0, 0, width, height)
def keyboard( key, x, y ):
if key == '\033':
sys.exit( )
if __name__=="__main__":
# GLUT init
# --------------------------------------
glut.glutInit()
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Hello world!')
glut.glutReshapeWindow(640,480)
glut.glutReshapeFunc(reshape)
glut.glutDisplayFunc(displayFunc)
glut.glutKeyboardFunc(keyboard)
program = common2d.init_shader_program()
set_global_program(program)
# Make program the default program
gl.glUseProgram(program)
# Enter mainloop
# --------------------------------------
glut.glutMainLoop()
if __name__ == '__main__':
main()