6/05/2006

Debug Drawing



Today I continued working on the CollisionTree, and I *think* I should have the basics working by now, but I don't really know it for sure;). The thing is, that I didn't really have a convenient way to test it yet. In my experience, the best way to test something like this, is to make everything, from triangles, to node boundingbox, to whatever, visible in 3D. Up until now, I simply did these kind of things by directly calling the opengl drawing functions from the main graphics loop. But the CollisionTree is pretty complex, and so to do this well, I would have to actually put OPenGL code inside the CollisionTree class (which is in a module which I try to keep clean of any graphics related api related stuff).

Because I'm certainly going to need this kind of debug drawing more often, and since it would be nice to be able to keep this visualization code in my engine, I decided to make a library with some debug drawing functions. It contains a static class, containing functions like DrawLine, DrawBox, which let you draw stuff to the screen, It also contains a DebugMesh, which can be used for static meshes, like a collision world.

But the real cool things are DebugDrawContexts. These contexts allow you to render debug information totally independent of the graphics thread and framerate. You can request such a context from any thread, at any time, draw your stuff to the context, and forget about it. The context will then automatically be visible, in the next graphics frame, and won't disappear until you explicitely remove it from the scene. If you request the same context again, you can redraw it (and while you're drawing, you will still see the old context), and after you call the EndDrawing function, this new "drawing" will be visible. This allows you to easily do debug drawing of gameplay stuff that's running in a different thread, and probably at a different framerate.

There are also timed contexts, which will disappear after a given time. These contexts are very handy for showing things like text balloons, which give information
about a certain event in your scene.

posted by Lieven 01:11


Other Bloggers
  • nervedemosystem
  • Boson
  • Walter Tamboer
  • Eternal lands development
  • walter still rules
    Cool Projects
  • Mono, .NET for linux n co
  • OGRE
  • walter still rules