Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / OpenGL / docs / tutorial / lesson1 / main.io
blob9cab9e0725b53d1be51c6672016345d719330e4f
1 // NeHe Tutorial #1
2 // See original source and C based tutorial at:
3 // http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
4 //
5 // Ported to Io by Steve Dekorte 2003
6 // 2004-08-01 Updated by Doc O'Leary
8 /*
9 This code shows how to get OpenGL going with Io. Support is provided by
10 the OpenGL object, which is in the ioDesktop binary. Simply run it with
11 this file as the argument, and you should get a boring and
12 empty-yet-stylishly-black GLUT window.
14 For the most part, the lessons translate fairly directly from the given
15 C code over to Io. For the purposes of clarity, only changed code will
16 be documented, and then only extensively if there is a significant
17 difference between the site's code and the code ported to Io.
20 // While we could technically clone OpenGL itself, it is really a singleton.
21 // To avoid adding all these methods to it, we'll simply make it our parent.
22 Demo := Object clone
23 Demo appendProto(OpenGL)
25 // This method handles what ReSizeGLScene does in the original tutorial.
26 Demo reshape := method(w, h,
27 glViewport(0, 0, w, h)
28 glMatrixMode(GL_PROJECTION)
29 glLoadIdentity
30 gluPerspective(45.0, w / h, 0.1, 100.0)
31 glMatrixMode(GL_MODELVIEW)
32 glLoadIdentity
35 // Same as the InitGL of the original.
36 Demo InitGL := method(
37 glShadeModel(GL_SMOOTH) // Enables Smooth Shading
38 glClearColor(0, 0, 0, 0) // Black Background
39 glClearDepth(1) // Enables Clearing Of The Depth Buffer
40 glEnable(GL_DEPTH_TEST) // Enables Depth Testing
41 glDepthFunc(GL_LEQUAL) // The Type Of Depth Test To Do
43 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) // Really Nice Perspective Calculations
46 // This method handles what DrawGLScene does in the original tutorial.
47 Demo display := method(
48 // Clear The Screen And The Depth Buffer
49 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
50 glLoadIdentity
52 glutSwapBuffers // Because GLUT double buffers.
55 // To avoid all the window consruction steps, we just use GLUT.
56 // This is same as is done in the main() for Mac OS X:
57 // http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Mac_OS_X
58 Demo main := method(
59 glutInit
60 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
61 glutInitWindowSize(640, 480)
62 glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99")
63 glutEventTarget(self)
65 self InitGL
67 // Call our display and reshape methods by default.
68 glutDisplayFunc
69 glutReshapeFunc
71 glutMainLoop // Start Event Processing Engine
74 // And, of course, we have to call main to get everything going.
75 Demo main