• 13
• 15
• 27
• 9
• 9

# Video engine design

This topic is 3960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm creating a game engine in C#, and I'm currently in the design process. The engine itself will be limited to 2D graphics. For the video bit, I'm considering two rendering approaches. The first one is the regular approach; where you draw each frame manually. There is not much to say about this one, you just draw images onto the screen every frame, clear the screen then draw them again. Settings such as alpha value, tinting colors, rotation etc. could be implemented like they are implemented in OpenGL - through various function calls before drawing. Pseudo code example:
while( gameIsRunning )
{
// This is of course not placed directly in the main loop
// It's just there to illustrate the diffrence
Alpha( 0.5 );
Rotation( 180 );
DrawSpaceShip();

Swap buffers and clear the screen
}


The second way to do it is to make everything rendered on screen object based, and to change a spaceship's rotation you would just modify the object's members. Then all the rendering is handled inside the engine automatically. I've seen this approach a few times and it is superior to the other one in some aspects. Pseudo code example:
Object spaceShip = new SpaceShip();
spaceShip.Alpha = 0.5;
spaceShip.Rotation = 180;
while( gameIsRunning )
{
RenderScene();
}


Advantages of method 1: * The user is given more control, at a pixel level. Making every pixel an object in for example a retro plasma effect isn't very efficient. * Probably easier to create tilemaps this way, but I'm not 100% sure about this. Advantages of method 2: * Requires less code from the programmer, since all the drawing is handled automatically. * Easier to add special effects to objects, such as waving back and forth and fading to different colors etc. There are of course many more pros/cons, but I'm confused, how should I do it? Martin

##### Share on other sites
Personally, I'd lean towards method 2. Basically, your render loop is very simple: you build a list of objects, sort it into the correct order (usually Z order), and then tell each object/effect to draw itself.

This allows you to use things like inheritance, virtual dispatch, and so on to arrive at a cleaner and more powerful design. C# is, really, a fairly OO-centric language, so (in my experience at least) you'll tend to get the cleanest results by working with the language rather than against it. That is, exploit the OO capabilities of C#, rather than using a procedural/OpenGL style which isn't particularly well-suited to C#'s strengths.