Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / OpenGL / samples / sphere.io
blobc8669aed3da18abe3aae964e22d0dcd9e7814431
1 #!/usr/bin/env io
3 GLSphereApp := Object clone do(
4 appendProto(OpenGL)
6 angleX := -45
7 angleY := 0
8 lastX := 0
9 lastY := 0
11 reshape := method(w, h,
12 glMatrixMode(GL_PROJECTION)
13 glLoadIdentity
14 gluPerspective(45, w / h, 1.0, 10.0)
15 glMatrixMode(GL_MODELVIEW)
16 glViewport(0, 0, w, h)
19 display := method(
20 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
22 glLoadIdentity
23 glTranslated(0, 0, -3)
24 glRotated(angleX, 1, 0, 0)
25 glRotated(angleY, 0, 1, 0)
26 sphere useFillStyle
27 sphere draw
29 glDisable(GL_LIGHTING)
30 glColor4d(.4,.4,.4, 1)
31 sphere useLineStyle
32 sphere draw
33 glEnable(GL_LIGHTING)
35 glFlush
36 glutSwapBuffers
39 mouse := method(button, state, x, y,
40 lastX = x
41 lastY = y
44 motion := method(x, y,
45 angleX = angleX + (y - lastY)
46 angleY = angleY + (x - lastX)
47 lastX = x
48 lastY = y
49 glutPostRedisplay
52 run := method(
53 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
54 glutInitWindowSize(512, 512)
55 glutInit; glutCreateWindow("Io Sphere")
56 glutEventTarget(self)
57 glutReshapeFunc
58 glutDisplayFunc
59 glutMouseFunc
60 glutMotionFunc
62 glClearColor(1, 1, 1, 1)
63 glEnable(GL_DEPTH_TEST)
64 glEnable(GL_LIGHTING)
65 glEnable(GL_LIGHT0)
66 glDisable(GL_CULL_FACE)
68 glEnable(GL_BLEND)
69 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
70 glEnable(GL_LINE_SMOOTH)
71 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
72 glLineWidth(2)
74 self sphere := GLUSphere clone do(
75 setRadius(0.8)
76 setSlices(12)
77 setStacks(12)
80 glutMainLoop
84 GLSphereApp clone run