OpenGL

Contained here are some of the wierdest bits of example code you are ever likely to find. These aim to cover random aspects of programming not often covered by many textbooks and other tutorials.

 

Simple Glut Example

Possibly the simplest openGL code known to mankind. This just creates a window and displays the standard teapot....

117Kb

Simple Triangle Example

This just extends the simple glut example by drawing a basic openGL triangle.

117Kb

Gen Triangles Example

Well, when you know how to draw a polygon, there are only really two things you can do to draw objects. Either a) mathmatically generate some primitive shapes, or b) load up a set of triangles and render them. This example deals with the first approach.

120Kb

 

Raster Font example

This example demostrates how to use raster fonts in OpenGL. An enumeration is used to allow us to specify numbers in binary.

126kb

 

Glut Raster Font example

This is a little example of how to create a fullscreen glut application. This is a handy starting point for a game.

119kb

Glut Game Mode Example

This is a little example of how to create a fullscreen glut application. This is a handy starting point for a game.

117kb

 

Glut Game Keyboard Example

glut has a fairly bad way of handling keyboard input from the point of view of a game programmer. It splits the keys into two sets, normal and special keys. This example wraps both sets in a way that is far more useful for a game engine.

119kb

Glut Window Config File

This example reads and writes a simple config file to the hard disk. Within the config file are all of the window settings which are used to initialise the window.

150kb

DirectX Keyboard input with glut

It is entirely possible under Win32 to make use of Direct Input to handle the keyboard input for your glut programs. This is a fairly sensible idea for a game since DirectX will also allow you to access the modifier keys alt,ctrl, shift etc.

139kb

 

Adding Joypad Support

This example uses DirectX under Windows, and the joystick lib under linux to get access to Joypads within your applications.

147kb

Frame Rate Independance

At different screen resolutions the frame rate of your application will change. Ideally your program should maintain the same speed no matter what the frame rate is.

119kb

Bezier Curve Example

This is a wee simple sample of how to render a bezier curve. It doesn't use the most optimised of techniques to render it, but rather the most obvious.

118kb

 

Hermite Curve Example

This is a wee simple sample of how to render a hermite curve. It uses the simplest possible method for rendering the curve.

118kb

 

Chaikin Curve Example

This little obscure curve type is a simple subdivision curve. The calculation method is very simple and it can be shown that the curve generated is a quadratic b-spline.

124kb

 

Cubic B-Spline Curve Example

This is a wee simple sample of how to render a cubic B-Spline. This curve is very similar to a cubic bezier curve in how we calculate it, however the curve has much better properties for maintaining curve continuity, as demonstrated in the next example.

118kb

Clamped Cubic B-Spline Curve Example

This is a wee simple sample of how to render a number of cubic b-spline segments to create a clamped curve. This greatly helps the understanding of NURBS curves and the Cox-De-Boor algorithm.

119kb

Nurbs Curve Example

This example uses the Cox-De-Boor algorithm to calculate the points on a single Nurbs Curve.

119kb

Simple Bezier Patch Example

Using 16 Points we can create a simple bezier patch. This example simply evaluates the points using one of the least optimal methods known to mankind. The Optimised Nurbs sample below also includes a more efficient way of rendering bezier patches.

119kb

 

Simple Nurbs Surface Example

This example uses the Cox-De-Boor algorithm to evaluate points on a Nurbs Surface.

119kb

Optimised Bezier Example

Moving on from the previous bezier patch example, we now need to start worrying about rendering the surface as triangle strips, handling the texture co-ords, and calculating the surface normals.

125kb

Maya 3D Camera Example

This very basic tutorial shows you how to create a Maya-like camera movement using mouse input in glut.

118kb

Floaty Camera Example

This example shows you how to create a camera that slightly lags behind where it should be. This is done with a simple spring to pull the camera to where it should be. This gives a really nice feel to the camera within a computer game. A big thank you to Chris Armsden for the original floaty camera code. I've basically nicked it off him and stripped it down a touch.

123kb

Quake 2 MD2 Loaders and Maya Exporter (+ source)

A selection of MD2 (Quake2) Model loaders and exporter for Maya. The loaders range in complexity from the very simplest upto a version that supports instances, vertex buffer objects, staggered updates etc. The result is lots and lots of models with frame-rate to spare....

1.2Mb

Dot3 Bump Mapped Blend shapes (+ source)

A highly optimised blend shape example. The normals and tangents are dynamically calculated and Dot3 bump mapping is applied. Funny things are done with pointers to try to keep things fairly fast. (Model by Dave Hunt)

507Kb

 

Dot 3 Bump mapped OBJ loader (+ source)

A series of 10 step by step tutorials on how to load an obj file. vertex arrays, tangent space and Dot3 bump mapping is also used. (obj file format here)

1.38Mb

 

Creating Simple Buttons using function pointers (+ source)

This is a step by step tutorial showing how to create basic buttons in openGL and C using linked lists and function pointers.

52Kb

A simple glut based editor framework (+ source)

This is a really simple scriptable GUI and a really simple scene graph. SetAttr and GetAttr functions allow you to set individual attributes on each object (limited to numbers only). The program also features selection using the back buffer, multiple viewports, a command line, start menu bar, menus etc. It's not exactly the greatest code ever written, however it is designed to be very simple to use and understand how it works. Source code included.

PUI User Interface Examples

Pui is a cross platform user interface library for use with openGL and glut. It's not the greatest library ever written, but may be useful for some things. This zip contains 11 examples of different user interface controls.

872Kb

DXT Texture Compression Source

This is a simple code listing for a function to create a DXT compressed texture in OpenGL. A more complete example can be found below in the texture manager example.

ScreenShot example

This example uses glReadPixels to read the frame buffer and save it as a tga image file.

140Kb

OpenGL Texture Manager Example

An example of a texture manager for openGL that supports tga, pcx and bmp images. DXT compression is also supported.

174kb

 

Texture Transparency using OpenGL Blending

Blending in OpenGL can be used to create alpha map based transparencies. This can simply be achieved by making use of GL_SRC_ALPHA & GL_ONE_MINUS_SRC_ALPHA as the parameters of glBlendFunc.

186kb

Sphere Mapping Example

This simply extends the previous tutorial to include sphere mapping. OpenGL can optionally generate texture co-ordinates for us, in this case it is generating texture coordinates for sphere mapped objects. The result is a fairly simple way of obtaining

249kb

Projected Texture Coords Example

This example uses OpenGL to project a texture onto an object. This can be very handy for things like lights etc.

347kb

Texture Matrix Example

This example fiddles about with openGL's texture matrix stack. This allows us to do silly things like scrolling and rotating textures.

347kb

fmod Mp3 Playback Example

This example uses fmod to play an mp3 sound file.

1.63Mb

fmod sound Example

This example uses fmod to playback a number of sound effects

528kb

 

fmod Frequencies Example

This example uses fmod to perform a fast fourier transform (FFT) on the sounds waveform data to produce the frequencies in the sound. Fmod's FFT unit can then provide you with an array of 512 floats representing the frequency data. This is then rendered to an openGL window.

1.77Mb

 

Direct Sound - Mp3 Playback Example

This example uses fmod to play an mp3 sound file.

6kb

 

Direct Sound - sound Example

This example uses fmod to playback a number of sound effects

15kb

 

Direct Sound - 3D sound Example

This example uses fmod library to playback 3D sound. I've not found this to work too well under linux due to certain driver issues.

6.6Mb

 

OpenGL Fog Example

This is just a simple example of how to control basic openGL fog.

118kb

 

OpenGL Fog Coord Example

Fog coordinates allow us to add a finer grain of control over fog within a scene. They can be used to essentially 'paint' the placement of fog around a scene. One of the problematic things about fog coordinates is the need to compute distances to the camera per vertex. This is often a costly process and as such should be considered for inclusion within a vertex program.

120kb

 

OpenGL Materials Example

Open GL materials can be used to add various material properties to a surface. These properties are used in conjuction with OpenGL's lighting model to control the ambient, diffuse and specular colours of a material.

124kb

 

OpenGL Lighting Example

This example demonstrates the various ways within OpenGL that you can control lights.

124kb

 

C-Style Stack Example

This example is a fairly lame example of how a stack works. As the user clicks the mouse, the points are added and removed from the stack.

117kb

 

C-Style Queue Example

This example is a fairly lame example of how a queue works. As the user clicks the mouse, the points are added and removed from the queue.

117kb

 

Lame Particle System

This is a very bad example (using a C-style linked list) of how to create a particle system. This just illustrates some of the key concepts of linked lists....

120kb

 

Slightly Better Particle System

This particle system uses vertex arrays to draw the particle system. The stride parameter is used to step over the particles in situe, we can also manage our particles

148kb