EDIT:: Basically the "Scene" is just for drawing to, as a sorta buffer region, which can then be passed to the renderer, and the renderer will draw whatever scene is passed to it, to the screen buffer.
SDLScene.h
Code: Select all
#ifndef SDLSCENE_H
#define SDLSCENE_H
#include <vector>
#include "SDL/SDL.h"
#include "SDLImage.h"
#include "SDLFont.h"
#include "Math2D.h"
class SDLScene
{
public:
SDLScene();
~SDLScene();
void drawSurface( SDL_Surface *surface, Vec2i point );
void drawSurface( SDLImage *image );
void drawSurface( SDLFont *font );
inline SDL_Surface* sceneSurface () { return sceneSurface_; }
inline void sceneSurface ( SDL_Surface* surface ) { sceneSurface_ = surface; }
private:
SDL_Surface* sceneSurface_;
};
#endif
Code: Select all
#include "SDLScene.h"
SDLScene::SDLScene ()
{
sceneSurface_ == NULL;
}
SDLScene::~SDLScene ()
{
}
void SDLScene::drawSurface( SDL_Surface *surface, Vec2i point )
{
SDL_Rect offset;
offset.x = point.x_;
offset.y = point.y_;
SDL_BlitSurface( surface, NULL, sceneSurface_, &offset );
}
void SDLScene::drawSurface( SDLImage *image )
{
drawSurface( image->surface(), image->point() );
}
void SDLScene::drawSurface( SDLFont *font )
{
drawSurface( font->surface(), font->point() );
}
Code: Select all
#ifndef SDLRENDERER_H
#define SDLRENDERER_H
#include <string>
#include "SDL/SDL.h"
#include "SDLScene.h"
#include "Math2D.h"
class SDLRenderer
{
public:
SDLRenderer ();
~SDLRenderer ();
virtual bool init ( int width, int height, int bpp, int flags);
virtual void cleanUp ();
virtual void tick ();
void drawScene( SDLScene *scene );
inline Vec2i point( Vec2i p ) { return point_; }
inline void point( int x, int y ) { point_.x_ = x; point_.y_ = y; }
private:
SDL_Surface *screenSurface_; // SDL < 2.0
Vec2i point_;
};
#endif
Code: Select all
#include <iostream>
#include "SDL/SDL.h"
#include "SDLImage.h"
#include "SDLFont.h"
#include "SDLRenderer.h"
#include "Math2D.h"
SDLRenderer::SDLRenderer ()
{
screenSurface_ = NULL;
point( 0, 0 );
}
SDLRenderer::~SDLRenderer ()
{
}
bool SDLRenderer::init ( int width, int height, int bpp, int flags)
{
screenSurface_ = SDL_SetVideoMode( width, height, bpp, flags );
if(screenSurface_ == NULL)
return false;
return true;
}
void SDLRenderer::cleanUp ()
{
}
void SDLRenderer::tick ()
{
SDL_Flip( screenSurface_ );
}
void SDLRenderer::drawScene( SDLScene *scene )
{
SDL_Rect offset;
offset.x = point_.x_;
offset.y = point_.y_;
SDL_BlitSurface( scene->sceneSurface(), NULL, screenSurface_, &offset );
}