Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / OpenGL / samples / cube.io
blob2929af3a1fc9aeb53de02a32b9b459881a97984c
1 #!/usr/bin/env io
4 // glcube.io - A simple Openprogram
5 // (C) 2002 Mike Austin
7 // Set a simple namespace
9 GLCubeApp := Object clone do(
10 appendProto(OpenGL)
12 angleX := -26
13 angleY := 74
14 lastX := 0
15 lastY := 0
17 reshape := method(w, h,
18 glMatrixMode(GL_PROJECTION)
19 glLoadIdentity
20 gluPerspective(45, w / h, 1.0, 10.0)
21 glMatrixMode(GL_MODELVIEW)
22 glViewport(0, 0, w, h)
25 display := method(
26 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
28 glLoadIdentity
29 glTranslated(0, 0, -3);
30 glRotated(angleX, 1, 0, 0)
31 glRotated(angleY, 0, 1, 0)
32 glutSolidCube(1)
34 glDisable(GL_LIGHTING)
35 glColor4d(.4,.4,.4, 1)
36 glutWireCube(1.002)
37 glEnable(GL_LIGHTING)
39 glFlush
40 glutSwapBuffers
43 mouse := method(button, state, x, y,
44 lastX = x
45 lastY = y
48 motion := method(x, y,
49 angleX = angleX + (y - lastY)
50 angleY = angleY + (x - lastX)
51 lastX = x
52 lastY = y
53 glutPostRedisplay
56 run := method(
57 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
58 glutInitWindowSize(512, 512)
59 glutInit; glutCreateWindow("Io Cube")
60 glutEventTarget(self)
61 glutReshapeFunc
62 glutDisplayFunc
63 glutMouseFunc
64 glutMotionFunc
66 glClearColor(1, 1, 1, 1)
67 glEnable(GL_DEPTH_TEST)
68 glEnable(GL_LIGHTING)
69 glEnable(GL_LIGHT0)
70 glDisable(GL_CULL_FACE)
72 glEnable(GL_BLEND)
73 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
74 glEnable(GL_LINE_SMOOTH)
75 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
76 glLineWidth(2)
78 glutMainLoop
82 GLCubeApp clone run