Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
103 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 The Problem
 The Solution
 Using the
 OpenGL Module


 Printable version

 


Using the OpenGL module

Using the module is really simple, just stick to the following steps:

  1. Do not include gl.h, include OpenGL.h instead
  2. Do not link to OpenGL32.lib
  3. Do not call wgl functions, call the exact same function with a prefix of OpenGL
  4. Do not call OpenGL related functions like SwapBuffers, call the same function with a prefix of OpenGL instead
  5. At run-time identify the OpenGL driver to use by using OpenGLFindDriver(), Init it using OpenGLInit()
  6. At exit, call OpenGLUnInit() to unload the opengl driver.
  7. Whatever you do, dont use glu*() routines.

You're probably thinking that this doesn't sound all the simple, but really it is. As an example I've also included a quick spinning cube OpenGL program to give you a working example.

Sample code that uses the other sample code: gldemo2.c

Comments on the sample code

GLDemo2.c actually demonstrates quite a few different things in addition to dynamic-loading of the opengl driver, starting with full-screen mode (which judging by how often this question is asked in the opengl newsgroup, oughtta make it worth a look-see for most people right there). Hopefully the code itself is fairly self-explanatory, I've tried to comment it fairly well.

What it doesnt demonstrate well however, is how to setup a proper camera. Those of you more familiar with OpenGL are doubtless gasping in horror at the fact that I put the camera transform in the projection matrix. And yes I know that this is technically a no-no, as it invalidates OpenGL's fogging and lighting operations. However, in self-defense I'll just point out that this code was originally written a long time ago to run on a MiniDriver which has neither fogging nor lighting (so there). Still readers should beware that this is wrong, evil and just plain bad. Do not imitate my laziness, put the camera in the modelview matrix where it belongs - something I will leave to a future article.

Is all this renaming stuff really necessary

Actually you could probably get by without it by compiling the opengl.c module with a few changes as a lib file. However, because you would be dealing with GDI functions etc, link order would become important, complexity would begin spiraling upward, life as we know it would end, and I decided it wasn't worth the bother.

I'd like to give a special thanks to Dan Mintz for his help in adding support for the full list of OpenGL functions to the module, as well as help with testing on various card/driver combinations.

by Ryan Haksi
http://members.home.com/borealis/ryan.html