Change parser to do C style () for operators: 1+2*3 == 1+(2)*3
[io/quag.git] / addons / OpenGL / docs / tutorial / lesson3 / main.io
blobc606850dd85df5c6aa8a8029bd032be8f4cfb665
1 // NeHe Tutorial #3
2 // See original source and C based tutorial at:
3 // http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=03
4 //
5 // Ported to Io by Steve Dekorte 2003
6 // 2004-08-01 Updated by Doc O'Leary
8 Demo := Object clone
9 Demo appendProto(OpenGL)
11 Demo reshape := method(w, h,
12 glViewport(0, 0, w, h)
13 glMatrixMode(GL_PROJECTION)
14 glLoadIdentity
15 gluPerspective(45.0, w / h, 0.1, 100.0)
16 glMatrixMode(GL_MODELVIEW)
17 glLoadIdentity
20 Demo InitGL := method(
21 glShadeModel(GL_SMOOTH)
22 glClearColor(0, 0, 0, 0)
23 glClearDepth(1)
24 glEnable(GL_DEPTH_TEST)
25 glDepthFunc(GL_LEQUAL)
27 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
30 // Ooooo, pretty colors!
31 Demo display := method(
32 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
33 glLoadIdentity
35 // Move Left 1.5 units and into the screen 6.0 units.
36 glTranslated(-1.5, 0.0, -6.0)
38 // Draw a triangle
39 glBegin(GL_TRIANGLES) // Start drawing a triangle
40 glColor3d(1, 0, 0) // Set the color to red
41 glVertex3d(0, 1, 0) // Top
42 glColor3d(0, 1, 0) // Set the color to green
43 glVertex3d(1, -1, 0) // Bottom Right
44 glColor3d(0, 0, 1) // Set the color to blue
45 glVertex3d(-1, -1, 0) // Bottom Left
46 glEnd // We are done with the triangle
48 glTranslated(3.0, 0.0, 0.0)
50 // Draw a square (quadrilateral)
51 glColor3d(0.5, 0.5, 1) // Set The Color To Blue One Time Only
52 glBegin(GL_QUADS) // Start drawing a 4 sided polygon
53 glVertex3d(-1.0, 1.0, 0.0) // Top Left
54 glVertex3d(1.0, 1.0, 0.0) // Top Right
55 glVertex3d(1.0, -1.0, 0.0) // Bottom Right
56 glVertex3d(-1.0, -1.0, 0.0) // Bottom Left
57 glEnd
59 glutSwapBuffers
62 Demo main := method(
63 glutInit
64 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
65 glutInitWindowSize(640, 480)
66 glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99")
67 glutEventTarget(self)
69 self InitGL
71 glutDisplayFunc
72 glutReshapeFunc
74 glutMainLoop
77 Demo main