flipCode - Tech File - Jeroen Bouwens [an error occurred while processing this directive]
Jeroen Bouwens
Click the name for some bio info

E-Mail: flipcode@jeroen.ws

   06/04/1999, OpenGL Mania

Well, it's been a while since my last update, but I think now is a good moment. I've been busy the last couple of weeks learning OpenGL. Although at first I was a bit overwhelmed by the complexity of the API, I got used to it quite fast. A friend of mine also found a nice OpenGL wrapper component for C++Builder, and the result can be seen in the new test-app.

The changes are significant, but not very visible. The biggest change is of course the switch to GL, but also the addition of a (rudimentary) 3DS-file loader. I also added a checkbox to turn on/off the CPU-usage bars. These bars simply aren't made for high-speed animation, and switching them off makes quite a difference.

The other changes are all invisible. I've been playing around with my class-definitions again, and I think I have a nice structure now where most tasks/data are owned by the correct class. Good class design is very important in my view. If done well, it can make all the difference in having clean, easy-to-read-and-understand or complex, hard-to-follow-and-maintain code. In a one man project the size of a 3D engine this is a nice feature and not very essential. For anything larger, especially if a team is writing it, it can make the difference between success or failure.

The nice thing about OpenGL is that it is possible to replace the software renderer a piece at a time. At this point, I have simply replaced my own rasterizer with the GL one. This was very straightforward: At the very end of my rendering pipeline, there was a loop like this:

  for (i=0;i<Visible;i++) 
I moved this to a separate method called "Rasterize" because the GL-component I use somehow requires all OpenGL drawing to be done inside the "OnPaint" event-handler. The "draw"-method calls one of two polyfillers: OGLFlat or OGLGouraud. OGLFlat looks like this:

  //Retrieve vertex information
  x1 = SortList[FaceNum].Coords[0].X;
  y1 = SortList[FaceNum].Coords[0].Y;
  x2 = SortList[FaceNum].Coords[1].X;
  y2 = SortList[FaceNum].Coords[1].Y;
  x3 = SortList[FaceNum].Coords[2].X;
  y3 = SortList[FaceNum].Coords[2].Y;

  R = SortList[FaceNum].FaceColor.R;
  G = SortList[FaceNum].FaceColor.G;
  B = SortList[FaceNum].FaceColor.B;

  //Draw polygon



This is the complete polygon-filler! Couldn't be simpler in my view :).

Of course this is only the first step. Ultimately, the entire engine should be built around the GL structure, which means a lot more modifications. It's probably worthwhile to start from scratch. Until then, I think I now have the basic framework for further experimenting with visibility determination and more advanced rendering algorithms (raytracing and radiosity). More on these subjects later.

Happy coding,

  • 04/01/2002 - Thoughts On Software Development
  • 09/10/2000 - Observe Your Objects
  • 01/31/2000 - Factories
  • 09/14/1999 - Polymorphism and Inheritance
  • 08/14/1999 - Object Design
  • 06/04/1999 - OpenGL Mania
  • 05/04/1999 - 3D Clipping
  • 04/29/1999 - Introduction

  • This document may not be reproduced in any way without explicit permission from the author and flipCode. All Rights Reserved. Best viewed at a high resolution. The views expressed in this document are the views of the author and NOT neccesarily of anyone else associated with flipCode.

    Download The Sample Program: ManicMotion.exe

    [an error occurred while processing this directive]