Posts Tagged ‘3d game engine’

OpenGL in VisualStudio.Net with the TAO Framework

March 4th, 2009

Some who read me on a regular basis might be wondering what ever happened to the RPG I was writing in VisualStudio using Microsoft’s XNA technology. Truth is, it never went anywhere. Like a lot of past projects, I got very psyched about it, wrote a bunch of code, and then school started and I got way too busy to finish it. I haven’t touched the code since I wrote that post, but now I’ve got some new ideas.

Last term in school, I took an excellent course on OpenGL programming with C++. The course covered how to create and render 3D graphics, with study lent to topics such as window management, points, vertices, and polygons, lighting and shading, hidden surface removal, and texturing. My earlier post about the MAX 3D Engine was a byproduct of that course.

Since then, I’ve discovered a managed .NET wrapper around the OpenGL libraries called the Tao Framework that allows you to (in theory) code any graphics application in Visual Basic or C# that you could in C++, with the added bonus of the pretty IDE, code completion, top of the line window handling procedures, and the .NET libraries. Now at this point, if you’re a graphics programmer, you’re laughing aloud at my outrageous claim – managed, run-time interpreted code could never be fast enough to run a video game! You may be correct. Frankly, I have no idea, as I haven’t yet had the time to write a full video game.

What I have come up with however, are two starter projects for anybody wishing to try their hand at OpenGL programming using Tao and Visual Basic.NET. The code in both is well documented, easy to follow (especially if you are familiar with standard OpenGL routines), and seems to run at a reasonable 60fps. Now, I can’t tell until I add a few more polygons to the scene whether this framerate is an artificial limit applied by the environment, or if interpreted code actually has no hope of ever running a game at a reasonable speed. That is an experiment for a later day. For now, I will simply share these starter projects for all to use. If you do something with them, please leave a comment and let me know how it went.

Tao2D Test Harness:

A simple application that spins a tri-coloured, smooth-shaded triangle around the y-axis.

Source Code: Tao2D Source VB.Net.zip

MD5 Hash: 4DA0FC584B1EF8738B3B9CA4C1F55388

Binaries: Tao2D Binary.zip

MD5 Hash: 611382CB00CADD860A81A85573CBA763

Tao3D Test Harness:

A simple application that spins a really crappy looking cone around the x-axis

Source Code: Tao3D Source VB.NET.zip

MD5 Hash: 8D54DB42109F12C745AD14922FF8850E

Binaries: Tao3D Binaries.zip

MD5 Hash: 5D4CD4D02B3EE1194758A543DF36C034

As always, I recommend using Tyler Burton’s Hash Verifier program to verify the integrity of these downloads.

MAX: A Half-Baked 3D Engine

January 5th, 2009

Last term, I took the CP411 Computer Graphics course at Wilfrid Laurier from Professor Hongbing Fan. It was an introductory course to creating computer graphics systems using standard C++ and OpenGL technologies. All in all, it was probably the best course I’ve taken yet at WLU, and I learned an awful lot. As a final project, we were asked to create some 3D application, and I chose (without really considering the ramifications of such a commitment) to attempt a 3D graphics engine.

The result was MAX; a highly extensible, working 3D graphics engine that I would say is about par with an N64 in terms of graphics capabilities, and leaves enough room for improvement that I could probably spend another full year working solely on it. However, for 2 weeks development time, I think that what I came up with represents an excellent baseline for what is necessary of a 3D engine, and that it was a worthwhile project and a great learning experience.

Following are a number of screen shots from the project:

The engine itself, while simplistic, is robust. It relies on OpenGL for its lighting and backface removal functions, supports mouse and keyboard input, texturing, models (although I haven’t written any adapters for importing complex model formats yet – all of the models are hard-coded for now), collision detection, and basic physics such as gravity.

By and large, I had problems with the amount of work. When I decided to create a 3D engine, I made the mistake of not setting out some boundaries for what I wanted to get out of it. I had 2 weeks to work on the project, and just started throwing whatever I had at the project. This of course led to feature creep, poor organization, and a continuous reduction in expectations for the final product. That said, I really am proud of the result of the experiment, although I would definetly change my work habits next time around.

Finally, here is a quick list of improvements that I feel need to be made to the engine before it is ready to host any kind of game:

  • Improved Collision Detection: Current algorithms utilize a simplified object-aligned bounding box algorithm that simply checks whether any two bounding boxes intersect with each other. Pros of the method are that multiple bounding boxes are supported for any model, and that moving model collisions (colliders) are abstracted from non-moving model collisions (colidees), meaning that no two inanimate objects will ever be checked for a collision with each other. A better method is to project the model onto each of the axes, and check for collisions between the resulting 2D shapes. If the 2D shapes collide on every axis, then the two objects are colliding. For an awesome tutorial (albeit in flash script and for a 2D engine, but easily extensible, check out N Tutorials)
  • Object Collision Events: Currently, when any two objects in the game collide, they both stop in their tracks. This works, but it would be better to assign some scriptable action to this event, and to implement semi-complex interactions like friction and force and the ability for one object to push another. The engine already supports gravity on all moveable objects, as well as collision detection with the outer walls of the world area, so a little bit more physics would be nice.
  • Complex Model Support: This is a seriously trying thing to do. Models of more than about 50 polygons quickly become unwieldy to handle quickly in memory and require some fast code to display at a decent frame rate. At least that’s what I’ve read. Since I needed an engine fast, and didn’t want to waste my time modeling (heck, I can’t draw anyway), I created my models as hard-coded in-engine entities comprised of simplistic geometry and this did not become a concern. However, I would like to improve my model class to support a greater number of polygons and textures, and enable reading in from common model formats.
  • Texture and Lighting Class Wrappers: Currently these items are exposed right in the main class of the application. It would be nice to have some sort of abstraction around them that allows for simple palette and lighting switches, as well as for improved resource management. Also, dynamic shadows are cool, and require only one additional rendering pass that should be easy enough to implement.
  • Particle Engine and Visual Effects: An easy way to do really cool visual effects is with a simple, sturdy particle engine that supports textures, anti-aliasing, and swarm-like movement of the particles. This can be used for bugs, birds, magic spells, weather effects, leaves in the wind, tornadoes, or really most any other simple effect you can think of. NeHe has an interesting tutorial on the matter here.

Overall, I’m proud of what I accomplished in such a short period of time. As always, the code is available for download for those who wish to play with it or just check it out.

Enjoy,

Jon

Edit: Resized the images so that they aren’t all gross and stretched out. Also, my apologies to any non-programmers attempting to download the engine – all you’ll get is Dev C++ source code. I’ll compile it and up an *.exe file tonight for those who aren’t interested in the pain and anguish involved in attempting to use Dev.