PDA

View Full Version : 3D Engine Structure?



McZ
02-06-2003, 12:43 AM
I want to create my own 3D Engine using OpenGL.. but I can't find any good information on how to setup everything... I want the engine to use classes and stuff.. so far I have a class that creates a rendering contex in a window.

but then... how do I manage the rendering in a good way?

is it a good idea to create a Scene class that contains all objects, lights and a camera, that has a render function to render the whole scene at once after the collition detection, depth sorting, transparent Object sorting and so on..

DJSnow
02-06-2003, 02:10 AM
there is a printed book available, called "OpenGL game programming": this book is very useable.
If you don't want to buy it (what i recommend to you) surf around the indernet and search after ebooks or other online articles, which describes the technology you need.
I'm sure, that there is a book outside in .PDF format, called "designing a 3D multiplayer game engine"; but i'm not sure, what the URL exactly was. use google....

V-man
02-06-2003, 06:19 AM
The rendering is managed by your renderer class.
The physics is done by your ....
Objects are in there ....

and so on.

and eventually, you will have to break some OO concepts for reasons of efficiency and the people who advocate OO methodology so strongly will hunt you down and hang you.

saian
02-06-2003, 09:08 AM
DJSnow: do you mean the american book OpenGL programming that explain nothing but you already know ?? I don't think this is a good book for making a 3D engine. The engine described is very poor, and all the things written are fairly available on the net...

don't see an attack to you, that's not my way of life.


Now, if you want to make your own engine, just start from the scrach: the less things you will discover, the best understood you'll get later...

you could look at some 3D engines available (as little3D or nebula and so forth...).

see you on the road !

saian

MickeyMouse
02-06-2003, 09:09 AM
Whether it's good to have Scene class depends on what you want.
Best you can do to learn about how to write good engine is to look into some free engines somewhere in the net. However I must say it's difficult to find more or less good and free OO 3d engine (have to look at Crystal Space), but I believe that making your app _really_ OO actually saves you a lot of time you would otherwise loose tracking some nasty bugs..

zed
02-06-2003, 09:29 AM
at the bottem of page here http://uk.geocities.com/sloppyturds/kea/kea.html
ive written a simplified version of how the actual mesh rendering part of my engine is structured

JustHanging
02-06-2003, 10:43 AM
Just a quick note, zed, your page has became totally unreadable on 800*600 thanks to those long comments in the code.

Anyway, there's some interesting stuff there. Wonder where the mythical gotterdammerung page is.

-Ilkka

jwatte
02-06-2003, 02:29 PM
Are you interested only in the rendering part, or do you also want to simulate a world, camrea, actors, export data from modeling packages, script interactions, ... ?

I'd recommend googling for "scene graph" for the former to give you some idea of ways to go.

McZ
02-06-2003, 11:25 PM
Originally posted by jwatte:
[B]Are you interested only in the rendering part, or do you also want to simulate a world, camrea, actors, export data from modeling packages, script interactions, ... ?
[B]

I'm intrested in all the parts.. I want classes for world, camera, object and so on and then a render class that renders everything

I want to know how to manage textures, objects and lights.

JustHanging
02-06-2003, 11:35 PM
I haven't advertised delphi3d for several hours now, it's getting about time. In the articles section there's a whole series of articles concerning 3d engine developement. The quality varies a bit, but you'll learn a lot from there.

The address is www.delphi3d.net (http://www.delphi3d.net)

-Ilkka

Tom Nuydens
02-07-2003, 12:05 AM
Originally posted by JustHanging:
I haven't advertised delphi3d for several hours now, it's getting about time. In the articles section there's a whole series of articles concerning 3d engine developement. The quality varies a bit, but you'll learn a lot from there.

Thanks for pimping my site. http://www.opengl.org/discussion_boards/ubb/smile.gif

I'm not particularly proud of anything I did before the year 2001, though, so proceed at your own risk http://www.opengl.org/discussion_boards/ubb/wink.gif

-- Tom

DJSnow
02-07-2003, 12:45 AM
@saian:

mmh, no i mean the book (and _this_ is the title) "OpenGL game programming", written by AndreLaMothe, Dave Astle and other guys from gamedev.net (i think), i think it's is published by a publishing house called "prima tech", the URL of the book is http://glbook.gamedev.net/ - do you mean this book, saian ?

But, apart from which book you mean, you are right with your oppinion regarding this book (~the prima tech's one):
This is book is really no "hardcore advanced prof." book (as you might expect it from titles such as "realtime rendering"), but it describes the basics of OpenGL rendering and utilizing of 3D features in an easy-to-understand way - and the "owner" of this thread told us, that he want to start - so i thought this book could help him. And yes, you are again right: the engine is not the one which could Doom8 or Quake12 - but it is a base from which you can expand, learn and grow up.

>>american book OpenGL programming
mmh, i have never heard of a book called like this; please tell me, what is the exact title ?? (or is it this book what i mean??)

>>don't see an attack to you, that's not my
>>way of life.
no problem at all - the world is free.... (oh yes, not all parts; i forgot http://www.opengl.org/discussion_boards/ubb/wink.gif )

>>"designing a 3D multiplayer game engine"
and this book, recommended by me, is available at the web as a series of .PDF files (each chapter) - but, as already said, i don't know the URL - or do you mean this book, saian ??

>>explain nothing but you already know ??
if you are meaning the "OpenGL game programming" book, you are right, again: this book hasn't taught me very much - because i was already at the "advanced level" when i bought it - but, all of us here can't know at which level the author of this thread "McZ" is, so i though aiming at a beginner-level would be not wrong.


@ALL:
BTW: does anyone of you owns the book called "realtime shading" ?? (this one with the red "spinning top" on its title - it is sometimes shown here on GL.org on the mainpage)
If yes: is it good ? what is the content about ? (yes, realtime shading, i know for myself, but i mean more details on this book if anyone has it)



[This message has been edited by DJSnow (edited 02-07-2003).]

Jan
02-07-2003, 01:06 AM
Originally posted by JustHanging:
Wonder where the mythical gotterdammerung page is.

-Ilkka
http://uk.geocities.com/sloppyturds/gotterdammerung.html

pkaler
02-07-2003, 10:32 AM
Nice to see that you are keeping it professional! http://www.opengl.org/discussion_boards/ubb/smile.gif
http://uk.geocities.com/sloppyturds/cv.html

zed
02-07-2003, 04:15 PM
Originally posted by PK:
Nice to see that you are keeping it professional! http://www.opengl.org/discussion_boards/ubb/smile.gif
http://uk.geocities.com/sloppyturds/cv.html

good enuf to join bodie + doyle u think?, naw mate theyll cramp my style.
note that site is old (im 32 now http://www.opengl.org/discussion_boards/ubb/smile.gif), though still havent washed my hair since oktoberfest 1999 when i got piss all over it (not my own) sticky for a few days, oh funtimes

anyways for an engine i believe u must keep everything as seperate as possible

heres what i do

rendermanager // models textures glstates etc
scene // camera actors particlesystems etc
os // window input sound timer
game // hud menu options etc

personally i like to have each area knowing very little about other areas, ie everything is greatly independant

pkaler
02-08-2003, 06:27 PM
Originally posted by zed:
good enuf to join bodie + doyle u think?, naw mate theyll cramp my style.


Who?

Back to the original question. I think you need to get yourself some more general coding knowledge. Also, take a look at a bunch of engines already available out there. Random links: http://neoengine.sourceforge.net/ http://xengine.sourceforge.net/ http://nebuladevice.sourceforge.net/ http://crystal.sourceforge.net/drupal/ http://ogre.sourceforge.net/ http://www.addall.com/New/compare.cgi?isbn=0201633620 http://www.addall.com/New/compare.cgi?isbn=1558605932

PixelDuck
02-09-2003, 06:53 AM
I would recommend 3D Game Engine Design by David Eberly. Although it is crammed with math, so if you don't like that, it might not be the best choise. And I'd suggest downloading the Quake II engine, if you already haven't. It's old, but it has the basic structure and since the basis of ogl doesn't really change (hasn't changed) it's still a good reference. And I do think mister Carmack knows what he's doing.

zed
02-09-2003, 09:14 AM
>>who?<<

>OK OK So I succumbed. I watched these two back when I was in college. Raymond Doyle is a nice tarty, curly headed cutie and William Andrew Philip Bodie is ... well, you only need one of those to pull the plow. They have a very, very interesting relationship. Back in the day, it took me a couple of shows to catch on, but they spent more time with each other after their dates, than with the dates... If someone happens to look at Doyle the wrong way, Bodie grows fangs. And Doyle is none too tolerant of anyone messing with Bodie either. Its a bit more subtle thing than say ... Starsky & Hutch... but there is definitely something there.

There is a lot of fun by play here as well as some really interesting plots. The boys have a good time with each other and even though our Raymond is a queen diva on occasion, Bodie still worships him. The bad part is that Doyle knows it. I also find it entertaining that they hate each other's "girlfriends" and even their boss doesn't find it odd that they live in each other's pockets. There's some very cute subtext dialog between them and there's enough physical horsing around to make a slasher's heart go all atwitter.

The best part of the show is the lovely lads in their tight pants (sorry, trousers). I would like to personally induct Bodie into the Black Tab Front Club. Oi, but he packs them tight. Then our Raymond in his spray painted jeans. A fine plush ass he displays too. Oddly enough Bodie seems to like it too. More than once you can see eyes straying towards it. And sometimes there's goosing. I almost hurt myself when I caught the first occurrence of it. Entirely too funny! <
http://www.blacktauna.com/slash/pros.html

i havent seen it for 15years but it all starts to make sense

PixelDuck
02-09-2003, 09:36 AM
What!? =)
I think this is a bit OT http://www.opengl.org/discussion_boards/ubb/wink.gif

ioquan
02-10-2003, 11:40 AM
Use typical object oriented design approaches. Look for the nouns, like scene, object, terrain, model, camera, etc. and make classes out of them. Look for opportunites to use inheritance as well. Personally, I have all of my objects derived directly or indirectly from an Entity class, and all moving entities derived from a DynamicEntity class. This allows me to share positioning and physics code between all of my different types of objects. Hope this gives you some ideas.

And PixelDuck, the guy said he wants OO, so the LAST THING ON EARTH you should recommend is the q2 engine.

[This message has been edited by ioquan (edited 02-10-2003).]

zed
02-10-2003, 07:25 PM
>>Use typical object oriented design approaches. Look for the nouns, like scene, object, terrain, model, camera, etc. and make classes out of them. Look for opportunites to use inheritance as well. Personally, I have all of my objects derived directly or indirectly from an Entity class, and all moving entities derived from a DynamicEntity class. This allows me to share positioning and physics code between all of my different types of objects. Hope this gives you some ideas.<<

i dont like inheritence from what ive seen in textbooks.
eg
struct Object{}

struct SpaceShip : public Object{}

struct Alien : public SpaceShip{}

struct Player : public SpaceShip{}

etc personally i find this bollux.

the only inheritence i use is the following this is the single structure that gets inherited in the whole engine

struct Object
{
Object() { set_ID(); }
int ID;
int object_type;
};

struct Alien : public Object
{};

struct Xtree : public Object
{};

thus any object can comunicate with any other object in the scene.

ioquan
02-13-2003, 03:58 PM
You wouldnt make alien derived from space ship. I use something like this:

class Entity

class DynamicEntity : public Entity

class ParticleCluster : public DynamicEntity

class Camera : public DynamicEntity

class Light : public DynamicEntity

class ModelEntity : public DynamicEntity

class Character : public ModelEntity

...

dorbie
02-13-2003, 04:18 PM
Sigh it's a shame that Martin Shaw mistook himself for a serious actor, didn't want to be typecast and put the kybosh on repeats (at least that's what I heard). Best series ever.

Do do do, doobie doobie do do, do do do do do.

McZ
02-14-2003, 12:33 AM
I got an idea how to create my engine.

is this a good way ?

first I have created a main class called C_ICE3D. in that class I have a virtual Render function and a pointer to my renderer (only OpenGL at the moment). and a World class that contains a CameraManger, LightManager and an ObjectManager.

ex:
class C_ICE3D {
C_IceRenderer *Renderer;
C_IceWorld *World;

virtual void Render(void);
StartEngine(HWND hwnd);
StopEngine();
};

then my world class looks like this

class C_IceWorld {
C_CameraManager *Cameras;
C_LightManager *Lights;
C_ObjectManager *Objects;
C_TextureManager *Textures;
C_TextManager *Text;

void Render();
...
};

and my render class has a C_Camera class pointer to the active camera from the camera manager, and then it has a pointer to all the other managers (Light, Objects, Font, Texture) the Render class calls the LightManager class to get the lights currently active (class can contain more then 8 lights but only 8 lights active at once) then it sets all light propertis and positions, after that it calls the ObjectManager to get a RenderObjectList that list points to the objects in the ObjectManager in the order to render them (Z-Sort, texture-sort and so on). when the objects renders the texturemanager is called to get the texture(s) for the object(s).
when all objects is done the TextManager is called to get the text-strings and position, colors/texture and then it prints out all text.

to use the C_ICE3D class you have to create your own class that inherits from C_ICE3D

ex:
class C_MyEngine : public C_ICE3D {
void Render(void); // This is the render loop
};

then create your render window and in WM_CREATE: call MyEngine->StartEngine(hwnd);

you have to call World->Render(); in your render loop to render all objects.. I made it that way so you can disable the use of the buildt in World Class.

is this a good solution?

knackered
02-14-2003, 01:58 AM
Did any of you see The Bullsh*tters? It was a parody of The Professionals done by the "Comic Strip Presents..." people?
The homo-erotic undertones of the series were explored quite extensively...it was hilarious. Keith Alan and Peter Richardson got it bang on.

V-man
02-14-2003, 08:21 AM
>>>then create your render window and in WM_CREATE: call MyEngine->StartEngine(hwnd);

you have to call World->Render(); in your render loop to render all objects.. I made it that way so you can disable the use of the buildt in World Class.

is this a good solution?<<<

The least I can say is

MyEngine->StartEngine(hwnd);

I don't know what the above does, but personally, I wouldn't.

as for
World->Render();

that's more inline.

zed
02-14-2003, 11:01 AM
>>C_CameraManager *Cameras;
C_LightManager *Lights;
C_ObjectManager *Objects;
C_TextureManager *Textures;
C_TextManager *Text;<<

textures dont belong in the same structure with the rest (not sure what text is doing there also?)

also try to minimize use of pointers, eg what happens if an object has a pointer to a texture + then later the texture doesnt exist?
bummer, use IDs instead

jwatte
02-14-2003, 05:02 PM
I would use interface pointers rather than concrete pointers, with contracts between the interfaces and the users.

Then I'd build the system in layers, where there's generic allocators, containers, and strategies at the bottom; specific implementations and adaptors in the middle; application code that instantiates and uses all this stuff at the top. And I'd be really strict about layering.

McZ
02-15-2003, 12:14 PM
Originally posted by V-man:
MyEngine->StartEngine(hwnd);
World->Render();


well the MyEngine->StartEngine(hwnd); starts the renderloop in a new thread that's why I have it that way.

The World->Render(); is a function to render all objects in my world class.



Originally posted by zed:
textures dont belong in the same structure with the rest (not sure what text is doing there also?)


how should I control the texture and text then?

I will use ID's and then when I render the stuff the renderfunction will call the TextureManager for the texture with the specefic ID.


Originally posted by jwatte:

I would use interface pointers rather than concrete pointers, with contracts between the interfaces and the users.


what do you mean with that?

pkaler
02-15-2003, 12:48 PM
Originally posted by McZ:
what do you mean with that?

He most likely means that you should define abstract base classes. Then derive concrete classes from your abstract classes. Your client code would have a pointer to the abstract class that points to some concrete class. For example, some pseudocode:




class IModelLoader
{
virtual Load() = 0;
};

class C3DSLoader : public IModelLoader
{
Load();
};

class CMD3Loader : public IModelLoader
{
Load();
};

class CEngine
{
public:

private:
IModelLoader *mLoader;
// or even better
std::vector<IModelLoader*> mLoaders;
};


What I do is store my loaders in a std::map. They are mapped with the file extensions that they handle. So given a filename, I lookup the appropriate loader by parsing the file extension and then I load away.

So what are the advantages? I don't have to keep adding Load3DS(), LoadFoo(), LoadBar() member functions to some low-level which would require a recompile throughout the whole codebase.

Since I use pointers in my interfaces rather than objects, I can forward declare classes rather than #include the file.




// engine.h

// Forward declaration
// #include "modelloader.h" not required
class IModelLoader;

class CEngine
{
public:

private:

IModelLoader *mLoader;
};

pkaler
02-15-2003, 12:55 PM
Btw, I recommend reading
Design Patterns. Gamma et all.
http://www3.addall.com/New/compare.cgi?isbn=0201633612

Warning: Design patterns are not a silver bullet though. After reading the book, everything will look like a pattern. But experience will help you figure out when to apply a pattern.

I also recommend Large Scale C++ Software Design. http://www3.addall.com/New/compare.cgi?isbn=0201633620

McZ
02-16-2003, 11:30 PM
Thanks for the answer PK.

now I understand. and I already use that type of pointers. my FileManager is buildt that way. and my render class

ex.

class C_Renderer {
// some private stuff
public:
virtual void CreateRenderer();
virtual void Render();
...
};

then when I init the engine I choose wich renderer to use.

class C_RendererGL : public C_Renderer {
...
};

or

clas C_RendererD3D : public C_Renderer {
...
};

the Direct3D version isn't functional yet though.

my FileManager works the same way.. with only one Load(...); function and then it checks the filetype and choose the correct class for it.. ex. C_AseFile for ase files...

[This message has been edited by McZ (edited 02-17-2003).]

Robert Osfield
02-20-2003, 12:55 AM
Above are links to other game engine projects. Often game engines are built ontop of scene graphs, reusing whats out there might save you alot of time, or might help in guiding the developing on your own rendering code.

The three main open source scene graphs are:
http://www.openscenegraph.org http://www.plib.org http://www.opensg.org

Robert.