Porting GLUT samples - 2

Let's look briefly at the ocx.

Events

Besides the 'Draw' event, the ocx fires Resize, Mouse, Pick and Key events and a few others which aren't of importance here.

1. Resize. The Resize event is used to set the viewport and make any needed adjustments the viewing frustrum. The ocx will handle the resize event by setting the viewport and adjusting the viewing parameters to maintain a correct aspect ratio. Quad returns true, indicating to the ocx that it should handle resizing. The ocx calls 'OnSize' in the glxCamera class and sets the viewport. If the client has returned true, it also sets the projection transform according to the camera properties. You can handle this in the app by not returning 'True' and instead calling glFrustrum, gluPerspective, or gluOrtho yourself.

2. Mouse and keyboard events are fired in response to user input. These events are typically used for navigation, menu selections, and picking. If you want to use the default ocx scene-rotation functions, set the 'MouseRotate' property to true. (You may also want to set the Trackball button and animate properties.) If you want to use the ocx for picking, set the 'Pick' property to true. You can use the key events to respond to the arrow and other keys.

Classes and Collections

The ocx contains several wrapper classes.
1. The glxLights collection. The glxLights collection doesn't do much except provide a wrapper for gl code. Its main utility is in allowing you to set the light parameters in about 4 lines instead of the 20 or more to fill several arrays and then pass them to GL. You do not need to create glxLight objects - to use a light, set its parameters and then set Enabled to true.

2. The glxMaterials collection. The glxMaterials collection predefines 28 materials which you use by creating a reference and then calling 'SetMaterial'. You can create other materials by calling:
    Set m_Mat = gCtl.NewMaterial
Like the glxLight class, the glxMaterial class allows you to set parameters in a few lines of code.

3. The glxImage and glxTexture classes are the most useful. At this time, they are capable of loading 24-bit 'bmp' files and the 'rgb' and 'bw' files used by many GLUT samples. Most of this code is from the SDK. A glxTexture object uses a glxImage to load and store bitmap data, but you can use glxImage objects directly. glxRGBImage is used privately by glxImage.

4. The glxShapes class is a port of the GLUT shape drawing functions. It simply draws geometric primitives.

5. The glxMesh and glxCurve classes are from the SDK samples. Future versions of the ocx will expose mesh functions, but at present, these are used only by the screen savers.

6. The glxFont class creates a 3d font.

7. All the 'gleXXX' classes are the Extrusion library classes, which are discussed elsewhere on this site.

That's a brief overview of the ocx. It's primary purpose is to handle some of the common GL tasks and some of the sticky issues which come up in porting C and GLUT samples.

<< Previous ........ Next >>




Please send suggestions, bug reports, and such to:



Home Page   |  Related Sites