Removed all code that uses OpenGL from Image.
[io/quag.git] / addons / OpenGL / samples / cylinder.io
blob7e55550532947171ef86197ce342c54f6e78ead1
1 #!/usr/bin/env io
3 GLCylinderApp := 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, -5)
24 glRotated(angleX, 1, 0, 0)
25 glRotated(angleY, 0, 1, 0)
27 glTranslated(0, 0, -1.5)
29 cylinder useFillStyle
30 cylinder draw
32 glDisable(GL_LIGHTING)
33 glColor4d(.4,.4,.4, 1)
34 cylinder useLineStyle
35 cylinder draw
36 glEnable(GL_LIGHTING)
38 glFlush
39 glutSwapBuffers
42 mouse := method(button, state, x, y,
43 lastX = x
44 lastY = y
47 motion := method(x, y,
48 angleX = angleX + (y - lastY)
49 angleY = angleY + (x - lastX)
50 lastX = x
51 lastY = y
52 glutPostRedisplay
55 run := method(
56 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
57 glutInitWindowSize(512, 512)
58 glutInit; glutCreateWindow("Io Cylinder")
59 glutEventTarget(self)
60 glutReshapeFunc
61 glutDisplayFunc
62 glutMouseFunc
63 glutMotionFunc
65 glClearColor(1, 1, 1, 1)
66 glEnable(GL_DEPTH_TEST)
67 glEnable(GL_LIGHTING)
68 glEnable(GL_LIGHT0)
69 glDisable(GL_CULL_FACE)
71 glEnable(GL_BLEND)
72 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
73 glEnable(GL_LINE_SMOOTH)
74 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
75 glLineWidth(2)
77 self cylinder := GLUCylinder clone do(
78 setBaseRadius(1.0)
79 setTopRadius(1.0)
80 setHeight(3.0)
81 setSlices(16)
82 setStacks(8)
85 glutMainLoop
89 GLCylinderApp clone run