File: GLE.py

package info (click to toggle)
pyopengl 2.0.1.08-5.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,484 kB
  • ctags: 9,036
  • sloc: pascal: 64,950; xml: 28,088; ansic: 20,696; python: 19,761; tcl: 668; makefile: 240; sh: 25
file content (98 lines) | stat: -rwxr-xr-x 2,537 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!

# This is statement is required by the build system to query build info
if __name__ == '__build__':
	raise Exception

import sys
from OpenGL.GL import *
from OpenGL.GLE import *
from OpenGL.GLUT import *


class GLE_demo:

	def __init__(self):
		# initial mouse position
		self.lastx = 121
		self.lasty = 121

		# set the display mode and create the window
		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
		glutCreateWindow("GLE demo")
		
		# setup the callbacks
		glutDisplayFunc(self.on_display)
		glutMotionFunc(self.on_motion)
		glutReshapeFunc(self.on_reshape)

		# 
		glClearDepth(1.0)
		glEnable(GL_DEPTH_TEST)
		glClearColor(0.0, 0.0, 0.0, 0.0)
		glShadeModel(GL_SMOOTH)

		glMatrixMode(GL_MODELVIEW)
		# initialize lighting */
		glLightfv(GL_LIGHT0, GL_POSITION,  (40.0, 40, 100.0, 0.0))
		glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.99, 0.99, 0.99, 1.0))
		glEnable(GL_LIGHT0)
		glLightfv(GL_LIGHT1, GL_POSITION, (-40.0, 40, 100.0, 0.0))
		glLightfv(GL_LIGHT1, GL_DIFFUSE, (0.99, 0.99, 0.99, 1.0))
		glEnable(GL_LIGHT1)
		glEnable(GL_LIGHTING)
		glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE)
		glEnable(GL_COLOR_MATERIAL)


	def on_motion(self, x, y):
		# store the mouse coordinate
		self.lastx = x
		self.lasty = y
		# redisplay
		glutPostRedisplay()


	def on_reshape(self, width, height):
		# setup the viewport
		glViewport(0, 0, width, height)
		# setup the projection matrix
		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		# calculate left/right and top/bottom clipping planes based the smallest square viewport
		a = 9.0/min(width, height)
		clipping_planes = (a*width, a*height)
		# setup the projection
		glFrustum(-clipping_planes[0], clipping_planes[0], -clipping_planes[1], clipping_planes[1], 50.0, 150.0)


	def on_display(self):
		# clear the buffer
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

		# Set up the model view matrix
		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()
		glTranslatef(0.0, 0.0, -80.0)
		glRotatef(self.lastx, 0.0, 1.0, 0.0)
		glRotatef(self.lasty, 1.0, 0.0, 0.0)

		# a nice pale lime green
		glColor3f(0.6, 0.8, 0.3)

		# set the join styles for GLE
		gleSetJoinStyle(TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP)
		gleHelicoid(1.0, 6.0, 2.0, -3.0, 4.0, None, None, 0.0, 1080.0)

		# swap the buffer
		glutSwapBuffers()



if __name__ == '__main__':
	# initialize GLUT 
	glutInit(sys.argv)
	# create the demo window
	GLE_demo()
	# enter the event loop
	glutMainLoop ()