2 Replies - 2327 Views - Last Post: 24 February 2011 - 12:05 PM Rate Topic: -----

#1 diego_pmc  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 565
  • Joined: 13-May 09

2D Graphics Engine Design

Posted 24 February 2011 - 11:37 AM

I'm trying to figure out a good design for a 2D graphics engine. The language I'm using is C++ and the library is SDL. However, the library should be of little importance since I'd like to make the engine portable (I doubt I'll need it, but I want to do it for exercise).

I've only written a bare bones engine: all you can do is draw an image from a file (you cannot even specify the coordinates). Here are the interfaces of my classes up until now:

Spoiler


Here are my questions/worries:

• How should I store graphical settings such as resolution, bits-per-pixel, whether or not the window is full-screen, etc? Ideally both Image and GraphicsRenderer should be able to read them. The Renderer for obvious reasons, and Image so it could convert the data to the right bits-per-pixel format.

• I'm not sure whether I should have more than one screen surface in my engine. Currently the only one is the private member in GraphicsRenderer. Should I instead have more screens, so I could more easily (re)draw the screens when I switch game states? Or should I just wait to see if this optimization is in fact necessary and only then modify the engine as appropriate?

• This is more of a request. Could someone describe to me all the base components of a simple 2D graphics engine? I don't need code, only a basic sketch that shows the purpose of each class and interaction with other classes.

This post has been edited by diego_pmc: 24 February 2011 - 11:57 AM


Is This A Good Question/Topic? 1
  • +

Replies To: 2D Graphics Engine Design

#2 stayscrisp  Icon User is online

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: 2D Graphics Engine Design

Posted 24 February 2011 - 12:03 PM

As an aside you might want to make GraphicsRenderer an interface base class so that you can derive specific renderers from it, a step towards your engines portability :)

class IGraphicsRenderer
{
   public:

      bool LoadImage(std::string file) = 0;
      void Draw() = 0;

      // lots more

   private:

      // some more stuff :)/>
};



#include "GraphicsRenderer.h"

class SDLRenderer : public IGraphicsRenderer
{
   public:

      bool LoadImage(std::string filename);
      void Draw();

   private:

      // more stuff
};



In your code you can access the renderer through a pointer to the base class

IGraphicsRenderer* theGraphicsRenderer = new SDLGraphicsRenderer(); // or another derived renderer



The rest of your code doesn't need to know about which type of renderer it is. You could even change the type of renderer at runtime rather than compile time.

This post has been edited by stayscrisp: 24 February 2011 - 12:07 PM

Was This Post Helpful? 2
  • +
  • -

#3 Fib  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 161
  • View blog
  • Posts: 554
  • Joined: 12-March 09

Re: 2D Graphics Engine Design

Posted 24 February 2011 - 12:05 PM

Some components of a 2D graphics engine:

  • Camera (To handle map scrolling, and drawing objects that are only within the camera)
  • Drawing a tile map
  • Drawing and animating sprites
  • Rotating and scaling sprites (Should use OpenGL for this)
  • Handling transparency of sprites and backgrounds
  • Drawing particles
  • Drawing text and handling fonts
  • Drawing GUI
  • Lighting


Those are just some that I can think of off the top of my head. There's a lot more stuff that you can put into it.

This post has been edited by Fib: 24 February 2011 - 12:10 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1