http://sdickinson.com/wordpress/wp-content/themes/HashOne
http://sdickinson.com/wordpress
Obox Signature Series Subscribe to my RSS feed

0 Comments Another OpenGL update

Article written by the brilliant Sam on the 02 Jul 2009 , in the C++ category

I’ve been working on a new OpenGL program. Didn’t finish the last one as I decided I wanted to make a portable application (ie, so I can port it to Windows, and possibly even DirectX one day). Only a touch of Objective-C/Cocoa to set up the windowing and use some nice OS specific functions (such as Cocoa automatically being able to decode PNG files), most of it is written in C++

So I’ve been playing around with VBO’s (Vertex Buffer Objects) and FBO’s (Frame Buffer Objects) which I had been doing in the previous program, but it turns out I was doing it slightly wrong. So now that it’s all working correctly I have a bit of an app going.

Currently it pretty much only loads Obj models (a simple ASCII based format), but most 3D applications will export this.

Underneath there is a lot going on. It has:-

  • Obj Model loading/rendering code
    • Works in both VBO mode and Immediate mode for debugging purposes
  • Quake style console (not shown)
    • Press ~ to bring it down, and you can type commands, register/change variables (currently moving the camera around is done like this, as is model loading)
  • Texture manager
    • I can keep track and list all the used textures
  • Shader manager
    • Like the texture manager, to keep track of it all
  • Font manager
    • Rendering fonts/strings to the screen
    • Using a single font texture “atlas” for all the characters, basically one big texture that slides its position around on a triangle fan (or quad if you prefer to think of it that way) to only show the correct character entirely done in GLSL (GL Shader Language – basically programming directly on the graphics card)
  • Particle renderer (not shown)

Next things I’d like to do are is have a model manager to allocate one (or more) large VBO on the card to hold lots of smaller models and index them within the VBO, more shaders – I’d really love to try some SSAO (Screen Space Ambient Occlusion – basically simulating the way that indirect light will still light and shadow things) and deferred lighting/shadowing and write a full GUI for it for things like menus, combo boxes, buttons, etc.

I’m sure I’ll come up with a lot more, possibly turning it into some type of game engine one day.

Here’s a screenshot of what I have so far.

OpenGL Renderer

It doesn’t look like much, but there’s a lot of work going on there.

The colours you can see on the model (which I actually made myself) are what’s known as a normal map. It’s the way lighting is calculated on 3D models.

Unfortunately there’s a couple of problems with this model.

  1. The first one that stands out is that it’s missing parts. When I exported the model, I accidentally left some of the parts as Sub-D and NURBS surfaces, which can’t be directly rendered by my renderer (or even represented in the Obj file). I’ve actually exported what I think is a proper model, just haven’t copied the file onto my laptop yet.
  2. The other one that isn’t so obvious unless you know what you’re looking at. With normal maps, we represent the normal as a colour. Basically Red = X, Green = Y and Blue = Z. Now a triangle (which is what the model is made up of) that is facing the camera should typically have a blueish tinge (like the bottom of the car does), but as you can see, the door is a green/orange colour. What is happening is that many of the triangle are actually facing the wrong way. Oops. Will have to fix that up :-)

One thing that may stick out in that screenshot too (at least if you click it and view it in full size) is that the frame rate is only 20FPS. Basically there are three reasons for this:-

  1. The first one is that I’m only rendering a frame once a millisecond (which works out to be around 40FPS) rather than maxing it out at the fastest possible rate
  2. Next it’s only a debug build, so the compiler hasn’t optimised the code
  3. Finally the model is 300,000 triangles, so in that alone, we’re doing around about 6,000,000 triangles per second (triangles * fps) , which that said isn’t fantastic (I am on a laptop graphics card though), but due to the way I’m calling the code, it will be a direct division of 40… ie, 40, 20, 10, etc.

So next post, I’ll hopefully show a proper render of the model. Maybe even throw in a quick tutorial on VBO’s (which are really quite easy when you get your head around them).

Read More Add a Comment