summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2003-09-15 13:36:06 +0000
committerJames Henstridge <jamesh@src.gnome.org>2003-09-15 13:36:06 +0000
commitea7f1197088dbed5f5301b0137a47ec299da4efb (patch)
tree10e50f6b46e8c4fd621367b7af1bdfb251657de6 /examples
parentc51e388d2a8168881e6dbc5ed7dc6aa2e121ca1f (diff)
downloadpygtk-ea7f1197088dbed5f5301b0137a47ec299da4efb.tar.gz
remove files.
2003-09-15 James Henstridge <james@daa.com.au> * gtk/gtkgl*: remove files. * gtk/Makefile.am: remove gtkgl binding. * configure.in (build_gtkgl): remove gtkgl bindings.
Diffstat (limited to 'examples')
-rw-r--r--examples/gl/README3
-rw-r--r--examples/gl/cone.py97
-rw-r--r--examples/gl/dots.py129
-rw-r--r--examples/gl/gears.py290
4 files changed, 0 insertions, 519 deletions
diff --git a/examples/gl/README b/examples/gl/README
deleted file mode 100644
index 673e5d82..00000000
--- a/examples/gl/README
+++ /dev/null
@@ -1,3 +0,0 @@
-These examples demonstrate using OpenGL with pygtk. They require that the
-gtkglarea package be installed before building pygtk, and you must install
-PyOpenGL for the actual OpenGL bindings.
diff --git a/examples/gl/cone.py b/examples/gl/cone.py
deleted file mode 100644
index 66117e05..00000000
--- a/examples/gl/cone.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env python
-
-import gtk
-import gtk.gl
-
-from OpenGL.GL import *
-from OpenGL.GLU import *
-
-rotx = 250
-roty = 0
-
-def hchanged(hadj):
- global roty
- roty = hadj.value
- redraw(glarea)
-
-def vchanged(vadj):
- global rotx
- rotx = vadj.value
- redraw(glarea)
-
-quadObj = gluNewQuadric()
-
-def glutSolidCone(base, height, slices, stacks):
- gluQuadricDrawStyle(quadObj, GLU_FILL)
- gluQuadricNormals(quadObj, GLU_SMOOTH)
- gluCylinder(quadObj, base, 0.0, height, slices, stacks)
-
-def redraw(glarea, event=None):
- if not glarea.make_current(): return
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- glPushMatrix()
- glScale(0.5, 0.5, 0.5)
- #glTranslate(0, -1, 0)
- glRotatef(rotx, 1, 0, 0)
- glRotatef(roty, 0, 1, 0)
- glutSolidCone(1, 2, 50, 10)
- glPopMatrix()
- glarea.swap_buffers()
-
-def realise(glarea):
- if glarea.make_current():
- glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
- glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
- glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
- glMaterial(GL_FRONT, GL_SHININESS, 50.0)
- glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
- glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
- glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
- glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
- glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
- glEnable(GL_LIGHTING)
- glEnable(GL_LIGHT0)
- glDepthFunc(GL_LESS)
- glEnable(GL_DEPTH_TEST)
-
-#if not gtkgl.query():
-# print "OpenGL not supported. Bye."
-# raise SystemExit
-
-win = gtk.Window()
-win.connect("destroy", gtk.mainquit)
-win.set_title("Cone")
-
-table = gtk.Table(2, 3)
-table.set_border_width(5)
-table.set_col_spacings(5)
-table.set_row_spacings(5)
-win.add(table)
-table.show()
-
-vadj = gtk.Adjustment(250, 0, 360, 5, 5, 0)
-vscale = gtk.VScale(vadj)
-table.attach(vscale, 1,2, 0,1, xoptions=gtk.FILL)
-vscale.show()
-
-hadj = gtk.Adjustment(0, 0, 360, 5, 5, 0)
-hscale = gtk.HScale(hadj)
-table.attach(hscale, 0,1, 1,2, yoptions=gtk.FILL)
-hscale.show()
-
-vadj.connect("value_changed", vchanged)
-hadj.connect("value_changed", hchanged)
-
-glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1))
-glarea.set_size_request(300, 300)
-
-glarea.connect("realize", realise)
-glarea.connect("expose_event", redraw)
-
-table.attach(glarea, 0,1, 0,1)
-glarea.show()
-
-win.show()
-
-gtk.mainloop()
-#glarea.destroy()
diff --git a/examples/gl/dots.py b/examples/gl/dots.py
deleted file mode 100644
index 668e7de9..00000000
--- a/examples/gl/dots.py
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/env python
-try:
- from Numeric import *
-except:
- print "This demo requires the Numeric extension, sorry"
- import sys
- sys.exit()
-from RandomArray import *
-import string, sys
-from OpenGL.GL import *
-
-import gtk
-import gtk.gl
-
-MY_LIST=1
-NUMDOTS = 500
-NUMDOTS2 = 600
-x = random(NUMDOTS)*2-1
-y = random(NUMDOTS)*2-1
-MAX_AGE = 13
-age = randint(0,MAX_AGE,(NUMDOTS,))
-move_length = .005 # 1.0 = screen width
-angle = 0 # in radians
-delta_angle = .2 # in radians
-move_x = move_length*cos(angle)
-move_y = move_length*sin(angle)
-
-glarea = None
-timer_id = 0
-
-def display(area=None, event=None):
- global x, y, move_x, move_y, NUMDOTS, NUMDOTS2, MAX_AGE, age
-
- # do not draw unless we can make the area the current drawable
- if not glarea.make_current(): return
-
- glClearColor(0.0, 0.0, 0.0, 0.0)
- glClear(GL_COLOR_BUFFER_BIT)
- glColor3f(1.0,1.0,0.0)
- glBegin(GL_POINTS)
- x = x + move_x
- y = y + move_y
- age = age + 1
- which = greater(age, MAX_AGE)
- x = choose(which, (x, random(NUMDOTS)))
- y = choose(which, (y, random(NUMDOTS)))
- age = choose(which, (age, 0))
- x = choose(greater(x,1.0),(x,x-1.0)) # very cool - wraparound
- y = choose(greater(y,1.0),(y,y-1.0))
- glVertex(transpose(array([x,y])))
- glVertex(transpose(array([x-.005,y+.005])))
- glVertex(transpose(array([x+.005,y-.005])))
- x2 = random(NUMDOTS2)
- y2 = random(NUMDOTS2)
- glVertex(transpose(array([x2,y2])))
- glEnd()
- glFlush()
-
- glarea.swap_buffers()
-
- return gtk.TRUE
-
-def mouse(glarea, event):
- global angle, delta_angle, move_x, move_y, move_length, timer_id
-
- if event.button == 1:
- angle = angle + delta_angle
- elif event.button == 3:
- angle = angle - delta_angle
- elif event.button == 2:
- if timer_id:
- gtk.timeout_remove(timer_id)
- timer_id = 0
- else:
- timer_id = gtk.idle_add(display)
- move_x = move_length * cos(angle)
- move_y = move_length * sin(angle)
-
-def setup_viewport():
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0)
-
-def reshape_callback():
- x, y, w, h = glarea.get_allocation()
-
- glViewport(0, 0, w, h)
- setup_viewport()
- return gtk.FALSE
-
-def reshape(glarea, allocation):
- # the allocation parameter here is of type GTK_TYPE_POINTER, so we
- # can't get to it directly -- so we set an idle callback and use
- # the get_allocation method
- gtk.idle_add(reshape_callback)
-
-def main():
- global glarea, timer_id
- win = gtk.Window()
- win.set_title("GL Dots")
- win.connect("destroy", gtk.mainquit)
-
- glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER))
- glarea.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- glarea.set_size_request(300, 300)
-
- setup_viewport()
- glarea.connect_after("size_allocate", reshape)
- glarea.connect("expose_event", display)
- glarea.connect("button_press_event", mouse)
-
- timer_id = gtk.idle_add(display)
-
- win.add(glarea)
- glarea.show()
- win.show()
-
- gtk.mainloop()
- #glarea.destroy()
-
-#if gtkgl.query():
-# print "Use the mouse buttons to control some of the dots."
-
-main()
-#else:
-# print "Your X server does not support GLX"
-
-
-
diff --git a/examples/gl/gears.py b/examples/gl/gears.py
deleted file mode 100644
index 43ddcef2..00000000
--- a/examples/gl/gears.py
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/usr/bin/env python
-
-# A translation of the gears demo that comes with mesa, modified to use
-# a few GtkHScale widgets for the rotation, rather than the keyboard.
-
-from OpenGL.GL import *
-import gobject
-import gtk
-import gtk.gl
-
-import math
-
-# Draw a gear wheel. You'll probably want to call this function when
-# building a display list since we do a lot of trig here.
-#
-# Input: inner_radius - radius of hole at center
-# outer_radius - radius at center of teeth
-# width - width of gear
-# teeth - number of teeth
-# tooth_depth - depth of tooth
-def gear(inner_radius, outer_radius, width, teeth, tooth_depth):
- cos = math.cos
- sin = math.sin
-
- r0 = inner_radius
- r1 = outer_radius - tooth_depth/2.0
- r2 = outer_radius + tooth_depth/2.0
-
- da = 2.0*math.pi / teeth / 4.0
-
- glShadeModel( GL_FLAT )
-
- glNormal3f( 0.0, 0.0, 1.0 )
-
- # draw front face
- glBegin( GL_QUAD_STRIP )
- for i in range(teeth + 1):
- angle = i * 2.0*math.pi / teeth
- glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 )
- glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 )
- glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 )
- glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 )
- glEnd();
-
- # draw front sides of teeth
- glBegin( GL_QUADS )
- da = 2.0*math.pi / teeth / 4.0
- for i in range(teeth):
- angle = i * 2.0*math.pi / teeth
- glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 )
- glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 )
- glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 )
- glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 )
- glEnd()
-
-
- glNormal3f( 0.0, 0.0, -1.0 )
-
- # draw back face
- glBegin( GL_QUAD_STRIP )
- for i in range(teeth + 1):
- angle = i * 2.0*math.pi / teeth
- glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 )
- glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 )
- glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da),-width*0.5 )
- glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 )
- glEnd()
-
- # draw back sides of teeth
- glBegin( GL_QUADS )
- da = 2.0*math.pi / teeth / 4.0
- for i in range(teeth):
- angle = i * 2.0*math.pi / teeth
-
- glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da),-width*0.5 )
- glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da),-width*0.5 )
- glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 )
- glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 )
- glEnd()
-
-
- # draw outward faces of teeth
- glBegin( GL_QUAD_STRIP );
- for i in range(teeth):
- angle = i * 2.0*math.pi / teeth
-
- glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 )
- glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 )
- u = r2*cos(angle+da) - r1*cos(angle)
- v = r2*sin(angle+da) - r1*sin(angle)
- len = math.sqrt( u*u + v*v )
- u = u / len
- v = v / len
- glNormal3f( v, -u, 0.0 )
- glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 )
- glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 )
- glNormal3f( cos(angle), sin(angle), 0.0 )
- glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 )
- glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da),-width*0.5 )
- u = r1*cos(angle+3*da) - r2*cos(angle+2*da)
- v = r1*sin(angle+3*da) - r2*sin(angle+2*da)
- glNormal3f( v, -u, 0.0 )
- glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 )
- glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da),-width*0.5 )
- glNormal3f( cos(angle), sin(angle), 0.0 )
-
- glVertex3f( r1*cos(0), r1*sin(0), width*0.5 )
- glVertex3f( r1*cos(0), r1*sin(0), -width*0.5 )
-
- glEnd()
-
-
- glShadeModel( GL_SMOOTH )
-
- # draw inside radius cylinder
- glBegin( GL_QUAD_STRIP )
- for i in range(teeth + 1):
- angle = i * 2.0*math.pi / teeth;
- glNormal3f( -cos(angle), -sin(angle), 0.0 )
- glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 )
- glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 )
- glEnd()
-
-view_rotx=20.0
-view_roty=30.0
-view_rotz=0.0
-
-gear1 = 0
-gear2 = 0
-gear3 = 0
-
-angle = 0.0
-
-def xchange(adj):
- global view_rotx
- view_rotx = adj.value
- draw(glarea)
-def ychange(adj):
- global view_roty
- view_roty = adj.value
- draw(glarea)
-def zchange(adj):
- global view_rotz
- view_rotz = adj.value
- draw(glarea)
-
-def draw(glarea, event=None):
- if not glarea.make_current(): return
-
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
-
- glPushMatrix()
- glRotatef( view_rotx, 1.0, 0.0, 0.0 )
- glRotatef( view_roty, 0.0, 1.0, 0.0 )
- glRotatef( view_rotz, 0.0, 0.0, 1.0 )
-
- glPushMatrix()
- glTranslatef( -3.0, -2.0, 0.0 )
- glRotatef( angle, 0.0, 0.0, 1.0 )
- glCallList(gear1)
- glPopMatrix()
-
- glPushMatrix()
- glTranslatef( 3.1, -2.0, 0.0 )
- glRotatef( -2.0*angle-9.0, 0.0, 0.0, 1.0 )
- glCallList(gear2)
- glPopMatrix()
-
- glPushMatrix()
- glTranslatef( -3.1, 4.2, 0.0 )
- glRotatef( -2.0*angle-25.0, 0.0, 0.0, 1.0 )
- glCallList(gear3)
- glPopMatrix()
-
- glPopMatrix()
-
- glarea.swap_buffers()
-
-def idle():
- global angle
- angle = angle + 2.0
-
- draw(glarea)
-
- return gtk.TRUE
-
-def reshape_idle():
- if not glarea.make_current(): return
- x, y, width, height = glarea.get_allocation()
-
- glViewport(0, 0, width, height)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- if width > height:
- w = width / height
- glFrustum( -w, w, -1.0, 1.0, 5.0, 60.0 )
- else:
- h = height / width
- glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 )
-
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- glTranslatef( 0.0, 0.0, -40.0 )
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
-
- return gtk.FALSE
-
-def reshape(glarea, allocation):
- gtk.idle_add(reshape_idle)
-
-def init(glarea):
- if not glarea.make_current(): return
-
- global gear1, gear2, gear3
-
- pos = (5.0, 5.0, 10.0, 0.0 )
- red = (0.8, 0.1, 0.0, 1.0 )
- green = (0.0, 0.8, 0.2, 1.0 )
- blue = (0.2, 0.2, 1.0, 1.0 )
-
- glLightfv( GL_LIGHT0, GL_POSITION, pos )
- glEnable( GL_CULL_FACE )
- glEnable( GL_LIGHTING )
- glEnable( GL_LIGHT0 )
- glEnable( GL_DEPTH_TEST )
-
- # make the gears
- gear1 = glGenLists(1)
- glNewList(gear1, GL_COMPILE)
- glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red )
- gear( 1.0, 4.0, 1.0, 20, 0.7 )
- glEndList()
-
- gear2 = glGenLists(1)
- glNewList(gear2, GL_COMPILE)
- glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green )
- gear( 0.5, 2.0, 2.0, 10, 0.7 )
- glEndList()
-
- gear3 = glGenLists(1)
- glNewList(gear3, GL_COMPILE)
- glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue )
- gear( 1.3, 2.0, 0.5, 10, 0.7 )
- glEndList()
-
- glEnable( GL_NORMALIZE )
-
-#if not gtkgl.query():
-# print "OpenGL not supported. Bye."
-# raise SystemExit
-
-win = gobject.new(gtk.Window,
- title='Gears')
-win.connect("destroy", gtk.mainquit)
-
-table = gtk.Table(4, 2)
-win.add(table)
-table.show()
-
-glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DEPTH_SIZE, 1, gtk.gl.DOUBLEBUFFER))
-glarea.set_size_request(300, 300)
-
-glarea.connect("realize", init)
-glarea.connect("size_allocate", reshape)
-glarea.connect("expose_event", draw)
-
-gtk.idle_add(idle)
-
-table.attach(glarea, 0,2, 0,1)
-glarea.show()
-
-for row, label, start, cb in ((1,'X Rotation', view_rotx, xchange),
- (2,'Y Rotation', view_roty, ychange),
- (3,'Z Rotation', view_rotz, zchange)):
- l = gtk.Label(label)
- table.attach(l, 0,1, row,row+1, xoptions=0, yoptions=gtk.FILL)
- l.show()
-
- adj = gtk.Adjustment(start, 0, 360, 5, 5, 0)
- adj.connect("value_changed", cb)
-
- scale = gtk.HScale(adj)
- table.attach(scale, 1,2, row,row+1, yoptions=gtk.FILL)
- scale.show()
-
-win.show()
-
-gtk.mainloop()
-
-#glarea.destroy()