Hi, I'm zeet, I'm a long time lurker, but only recently joined this marvelous community.
Anyway, I'm kind of a novice graphics programmer, and want to learn more about graphics programming, the best way I felt I could do that was by creating my own little 3d engine, and since this is a creative project, I felt it would make a great thread.
Now, I am not trying to create some über optimized 3d engine capable of challenging Unity or UDK. But rather my own little thing so I can point at the screen and say: "I made this."
A little info about the project:- Written in c++.
- Using SDL for painless window creation/input events and threading.
- SDL_image for texture loading.
- OpenGL for graphics.
Now first step was to create a game entity/object class of some sort, to contain and execute game logic code. Some call this a scene graph, but considering I want them to exist in a scene without actually physically being anywhere I call them objects instead.
Anyway, the point of these objects is to execute game logic code, this way game logic will not bloat the rest of the engine.
So each game object has four redefinable functions, or so called virtual functions, called Initialize, Update, Draw, and DeInitialize where, for an example, Initialize is called upon adding a new object to the scene etc. basically, all you need to do to create a new object, is to make a new class and inherit the object class.
I realized quite fast that because c++ static language, and because I don’t like to have game logic variables in the basic game object, you would need to know exactly what class objects are to be able to access other objects’ game logic variables.
To solve this I designed a parameter class, which every object has. This way it is possible for an object to simply declare a few parameter on initialization, for an example:
class Example : object{
int MookHealth, MookDamage;
Public:
bool initialize(){
CreateParameter<int>("HP",&MookHealth);
CreateParameter<int>("Damage",&MookDamage);
return 1;
}
}
Other objects could then access them by calling a GetParameter function, in my opinion it is more elegant than having to
redefine_cast<Example>(objectPointer)->MookHealth
Even if my solution is slower.
I then created a window manager class, I won't be getting much into that since it's basically just a class that wraps around SDL's window functions. I also made a Game class which keeps track of FPS and updates all objects.
To tests out the object system I made a basic object that sets the window caption to current FPS.
class FPSTest : object{
string FPS; char _str[5];
public:
bool update(){
FPS = "Game engine. FPS: ";
sprintf(_str,"%d",Game.gameFPS);
FPS = _str;
return 1;
}
bool draw(){
Game.gameWindow.SetCaption(FPS);
return 1;
}
};
And voila, we now have a window:
(I know it's not much, but it's a start..)
If people are interested I will post my progress. I actually have A LOT more of the engine finished, as I started writing it quite a while ago. But I try to keep forum post chronological with the order in which I programmed the engine.
Next time, I will create a input manager class of some sort, we want to be able to INTERACT with our games.
Edited for clarity..