Sign in to follow this  
Jace-

Creating a basic graphics engine

Recommended Posts

Hello all, A couple of friends and I are required to make a non-trivial 3D game for a college course. Each member of the group is required to write some modual for the game. I have been assigned the task of creating the graphics engine. I've done a bit of work with DirectX but this will still basically be my first graphics engine. Obviously I have no plans to create something like the unreal engine, but I do want to make a solid engine with good educational merits. My intended goal for this post is to get feedback or ideas on ways to properly structure a gfx engine specifically for a game. Or perhaps warnings on common mistakes made by novice DirectX/Gfx engine writers. Obvoiusly this is an extremely broad topic and I dont expect anyone to tell me how to write an entire gfx engine or even half of that in a single post, though that would be amazingly helpful, i'm just hoping to get some good feedback; a spring board if you will. Primarily though, I don't want to be regretting not having implemented something important months in to the project; or doing something "wrong" for that matter. Thanks for any and all responses. Of course graphics is always game specific, The following is a bit of info on the game related to graphics: -Language used is C++ -3rd person camera -World the player moves on is a (big) sphere -No height maps will be used -Vertex and Pixel shaders intended to be used -I can't think of much else... if anyone needs more info. Please dont hesitate to ask.

Share this post


Link to post
Share on other sites
That sounds a little more complicated than anything I've done, but basically I start from the ground up. I started by making different modules for my engine.

1. Window Creation
2. DirectX Device Creation
3. Resource Manager
4. Sound
5. Input
6. Collision Detection
7. State Machine (used to add states to the engine that can be processed and changed)

I've used my engine for basic 3D, but mostly just 2D games because everything is there for me ID3DXSprite handler. I'd look into making the engine very easy to use, but also only have one entry point. I use a variable that can access all of the parts of my engine (global_engine). I build my engine as a lib file and then just include the necessary headers and I'm ready to go. I've spent countless hours on building my engine, mainly for the experience, but if your strapped for time I'd use an already developed engine like Irrlicht, Ogre, or even better Torque.

Share this post


Link to post
Share on other sites
What's your time-frame?

Most important advice, IMO - keep it simple - you don't want to drown in a swamp of to-be-implemented features. Especially that you have little experience in the field.
Also, I imagine that you'll need the graphics engine ready for debugging stage (read: very soon). So first make it work, then make it look good.

Share this post


Link to post
Share on other sites
Time frame is a two semester course. Thats about 8 months total. In theory there is plenty of time to make it really good, but I'm also taking 6 classes per semester. So it's probably more like a 4 month period of time stretched over the 2 semester year. I'm not crazy, i'm just taking the recommended courses...

Currently for graphics, I plan on having a singleton GfxManager class with a std::map of all the list of 3D objects. When it comes time to render i call the render function on every object in the map...

Edit: Also i'm not sure what sort of member data the 3D object will need, any tips? My current list is:
-World Xform
-color
-mesh
-object id (for indexing into my map)
-pointer to parent object (pointer to the game entity that contains the gfx object ie: dude, tree, enemy, etc..)
-Vertex Shader
-Pixel Shader

[Edited by - Jace- on October 4, 2006 4:32:57 PM]

Share this post


Link to post
Share on other sites
If you want decent performance, you will have to do some frustum culling (only render the objects in the field of view of the player). The use of a space subdivision algorithm (bsp, quadtrees ..) is a must here.

Share this post


Link to post
Share on other sites
Simple engine you say?

1. Window and device creation
2. Scene graph (bsp, quad/oct-trees, any tree... and some way to organize objects in theworld) + Frustum, but thats basic!
3. Math library. Lot's of fun writing that :|
4. Collision detection
5. Resource managers
6. Lot's of utility classes. Timers, animation, noise generators etc.

This would work as a simple framework, but it's a lot of work to make it good even if it seems simple.

Share this post


Link to post
Share on other sites
Just some inspirational words, "Ask and Learn". The awesome people on this forum have a wealth of information. Just make sure that you have done some research as most of us have fulltime jobs or are extremely busy.

If you are looking for some advice, go look at other opensource graphics engine and take a look at the structure, if you like some parts, make a note and make notes on the parts that you dislike.

Other than that, it seems like most of the guys here have given you quite a good list of things that need to be included in your graphics engine.

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
I'd say start simple:

1.
Get yourself a bit acquainted with the math (Vector2, Vector3, Matrix3 and Matrix4) and implement classes for these (do it by example, because if you make an error, you'll end up with crap :) ).
2.
Figure out how to draw triangles with directx (DrawPrimitiveUp is your friend).
3.
Figure out how to load a popular 3d-format, so you're able to load a model (MD2 is my current choice: http://tfc.duke.free.fr/coding/md2-specs-en.html). Don't use directx file formats as X, because they're horrible.
4.
And as a last point figure out how to move the camera so you're looking at your model (directx has a lookat-function, look for that one).

Do all this with the culling and z-buffer of directx turned on, so don't look at BSP-trees (you'll waste all your time!). You'll get a reasonable performance for the time being, but at least you've got your basic capabilities. Try to get that in an abstraction-layer ... at least that's what I did, because I can't stand all the directx-code throughout my project.

At this point you can start thinking about more advanced math-topics (quaternion for nice camera-movements), nice messaging-structure (so your objects know when to draw, get user-input, etc.), tools (eg timers, etc.), etc, etc. Anyway there are plenty of tutorials out there.


Ta,
Richard


PS:
Don't forget to turn on the lights :)

Share this post


Link to post
Share on other sites
Thanks guys,
Thanks to your input I've already begun work on a math library. So far I got some good functionality including collision detection for lines, planes, triangles, spheres, and axis aligned bouding boxes. I'm starting to be skeptic on whether or not I will be needing BSP or quad trees. Though I'm a bit worried that the game will have too many objects and it will be to difficult to add BSP trees late in the project.

Anyone just happen to know of any good open source gfx engines done in DirectX, perfect for learning from. Ogre seems nice but doesnt let me see the nitygrity stuff that deals with D3D?
Thanks again for all your feedback, it's been invaluable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this