I created the new branch that will use PyOSG.
[krufty_fps.git] / L04_lam_pgu.py
blob1dfddfd452d65a458ddb6b57a355da087bb0ca0e
1 #!/usr/bin/env python
2 # demo of laminar.PanelOverlaySurface, by
3 # David Keeney 2006
4 # based on version of Nehe's OpenGL lesson04
5 # by Paul Furber 2001 - m@verick.co.za
7 # you need pgu to be installed, and you need a copy of the default theme directory
8 # as 'test_theme', and you need the accompanying config.txt in that test_theme dir.
10 import sys
11 sys.path.insert( 0, '..' )
13 from OpenGL.GL import *
14 from OpenGL.GLU import *
15 import pygame
16 from pygame.locals import *
18 # import gui stuff
19 from pgu import gui as pgui
20 import lamina
22 rtri = rquad = 0.0
24 triOn = quadOn = True
26 def resize((width, height)):
27 if height==0:
28 height=1
29 glViewport(0, 0, width, height)
30 glMatrixMode(GL_PROJECTION)
31 glLoadIdentity()
32 gluPerspective(45, 1.0*width/height, 0.1, 100.0)
33 glMatrixMode(GL_MODELVIEW)
34 glLoadIdentity()
36 def init():
37 glShadeModel(GL_SMOOTH)
38 glClearColor(0.0, 0.5, 0.0, 0.0)
39 glClearDepth(1.0)
40 glEnable(GL_DEPTH_TEST)
41 glDepthFunc(GL_LEQUAL)
42 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
44 def draw():
46 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
47 glLoadIdentity()
48 glTranslatef(-1.5, 0.0, -6.0)
50 # draw triangle
51 global rtri
52 glRotatef(rtri, 0.0, 1.0, 0.0)
54 glBegin(GL_TRIANGLES)
55 glColor3f(1.0, 0.0, 0.0)
56 glVertex3f(0.0, 1.0, 0.0)
57 glColor3f(0.0, 1.0, 0.0)
58 glVertex3f(-1.0, -1.0, 0)
59 glColor3f(0.0, 0.0, 1.0)
60 glVertex3f(1.0, -1.0, 0)
61 glEnd()
63 # draw quad
64 glLoadIdentity()
65 glTranslatef(1.5, 0.0, -6.0)
66 global rquad
67 glRotatef(rquad, 1.0, 0.0, 0.0)
69 glColor3f(0.5, 0.5, 1.0)
70 glBegin(GL_QUADS)
71 glVertex3f(-1.0, 1.0, 0)
72 glVertex3f(1.0, 1.0, 0)
73 glVertex3f(1.0, -1.0, 0)
74 glVertex3f(-1.0, -1.0, 0)
75 glEnd()
77 # draw gui
78 glLoadIdentity()
79 global gui_screen
80 gui_screen.display()
83 def main():
85 global rtri, rquad, gui_screen
86 video_flags = OPENGL|DOUBLEBUF
88 pygame.init()
89 pygame.display.set_mode((640,480), video_flags)
90 font = pygame.font.SysFont("default", 18)
91 fontBig = pygame.font.SysFont("default", 24)
92 fontSub = pygame.font.SysFont("default", 20)
93 theme = pgui.Theme('test_theme');
95 resize((640,480))
96 init()
99 # create PanelOverlaySurface
100 # gui_screen = lamina.LaminaPanelSurface((640,480), (-3.3, 2.5, 6.6, 5))
101 gui_screen = lamina.LaminaScreenSurface()
103 gui = pgui.App(theme=theme)
104 gui._screen = gui_screen.surf
106 # func to toggle triangle spin
107 def triTog():
108 global triOn
109 triOn = not triOn
110 # func to toggle quad spin
111 def quadTog():
112 global quadOn
113 quadOn = not quadOn
115 # create page # layout using document
116 lo = pgui.Container(width=640)
118 # create page label
119 title = pgui.Label("Lamina Demo : PGU", font=fontBig)
120 lo.add(title,29,13)
122 # create triangle button, connect to triTog handler function,
123 # and install in gui
124 btn1 = pgui.Button("Stop/Start Triangle")
125 btn1.connect(pgui.CLICK, triTog)
126 lo.add(btn1,120,440)
127 btn2 = pgui.Button("Stop/Start Quad")
128 btn2.connect(pgui.CLICK, quadTog)
129 lo.add(btn2,420,440)
130 gui.init(lo)
132 frames = 0
133 ticks = pygame.time.get_ticks()
134 while 1:
135 event = pygame.event.poll()
136 if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
137 break
139 # handle gui events and raster updating
140 gui.event((event))
141 chg = gui.update(gui_screen.surf)
142 if chg:
143 gui_screen.refresh(chg)
145 # draw all objects
146 draw()
148 # update rotation counters
149 if triOn:
150 rtri += 0.2
151 if quadOn:
152 rquad+= 0.2
154 # make changes visible
155 pygame.display.flip()
156 frames = frames+1
158 print "fps: %d" % ((frames*1000)/(pygame.time.get_ticks()-ticks))
161 if __name__ == '__main__': main()