Crash-Override.net

Benjamin 'blindcoder' Schieder - Code Collection

Home | Who am I?

libGLI - New Object HowTo

by Benjamin Schieder

v0.1, 03. Jan 2003


This HowTo mainly shows how to create a new 3D-Object using and for use with libGLI
Copyright (c) 2003 Benjamin Schieder

1. Introduction

2. Problem

3. Solution


1. Introduction

1.1 Author

The Author of this document is also the current Maintainer of libGLI which, at the time of writing, can be found at http://www.crash-override.net.
You contact him via E-Mail via 'libgli at scavenger dot homeip dot net'

1.2 Getting

This document is maintained together with the libGLI library at its website http://www.crash-override.net.

1.3 License

Copyright (c) 2003 Benjamin Schieder

2. Problem

2.1 Requirements

To create a new object to use it with libGLI you need the following:
  1. libGLI - http://www.crash-override.net./libgli/main.php
  2. An implementation of OpenGL - Mesalib, NVidia's GLX driver or whatever suits your needs (ask your distributor)
  3. A C++-Compiler and standard header files (*.h)
  4. Knowledge about OpenGL-Programming
  5. The will to do it

2.2 Problem-Description

So, now you've successfully downloaded, compiled and installed libGLI, you understand how the demo-programs work and adapted them a little so that you now have a basic understanding of how libGLI works. Now you want to create your own object for your own program, say, a game.
This HowTo will tell you how to create a simple 3D-Object with libGLI.

3. Solution

3.1 Start

We start out with a simple program opening our OpenGL-Window with a width of 800600 using the GLUT library.


3.2 Adding the class

For the sake of simplicuty we just add the new class to the existing code instead of a separate file.
DO NOT DO THAT IN PRODUCTION CODE!!!
Here we inserted a class CGLI_Pyramid and created the instance "pyramid". Note that all methods from CGLI_Object are inherited which include, but are not limited to, Show, Hide, SetRotation, SetPosition and others.

3.3 Adding the Draw() code

Now, what good does this do when the object does not draw anything to the screen? Here we add the Draw() code:
Also note the 3 new lines in the main() part. This adds the Object to the screen using the CGLI_Interface 'iface'.

3.4 Effects

Now, an object that just sits there is pretty boring. Now we let the pyramid do something when clicked on with the mouse. To achive this, we insert two new variables and some code into the constructor, the Draw(), and the ProcessInternalCallBack():
Note that there are no changes in the main() part.

3.5 Multiple Objects

As a last thing we add a second pyramid just for fun :)