diff --git a/anaglym.cc b/anaglym.cc index 46ae847..03b7870 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -39,7 +39,7 @@ int main(int argc, char * argv[]) usage(); } - video_init(); + Video video; lua_State * L = lua_open(); diff --git a/video.cc b/video.cc index 0534b56..80afb95 100644 --- a/video.cc +++ b/video.cc @@ -4,10 +4,7 @@ #include using namespace std; -static int default_width = 0; -static int default_height = 0; - -void video_init() +Video::Video() { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { @@ -18,23 +15,38 @@ void video_init() const SDL_VideoInfo * vidInfo = SDL_GetVideoInfo(); if (vidInfo != NULL) { - default_width = vidInfo->current_w; - default_height = vidInfo->current_h; + m_defaultWidth = vidInfo->current_w; + m_defaultHeight = vidInfo->current_h; } else { cerr << "Warning: SDL_GetVideoInfo() returned NULL!" << endl; - default_width = 1024; - default_height = 768; + m_defaultWidth = 1024; + m_defaultHeight = 768; + } + + m_surface = NULL; +} + +void Video::start(int width, int height, bool fullscreen) +{ + if (width == 0) + width = m_defaultWidth; + if (height == 0) + height = m_defaultHeight; + int flags = SDL_HWSURFACE | SDL_OPENGL; + if (fullscreen) + flags |= SDL_FULLSCREEN; + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + m_surface = SDL_SetVideoMode(width, height, 32, flags); +} + +void Video::stop() +{ + if (m_surface != NULL) + { + SDL_FreeSurface(m_surface); + m_surface = NULL; } } - -int getDefaultWidth() -{ - return default_width; -} - -int getDefaultHeight() -{ - return default_height; -} diff --git a/video.h b/video.h index 336621b..c24da14 100644 --- a/video.h +++ b/video.h @@ -1,9 +1,24 @@ -#ifndef SDL_H -#define SDL_H +#ifndef VIDEO_H +#define VIDEO_H -void video_init(); -int getDefaultWidth(); -int getDefaultHeight(); +#include + +class Video +{ + public: + Video(); + void start(int width = 0, + int height = 0, + bool fullscreen = true); + void stop(); + int getDefaultWidth() { return m_defaultWidth; } + int getDefaultHeight() { return m_defaultHeight; } + + protected: + int m_defaultWidth; + int m_defaultHeight; + SDL_Surface * m_surface; +}; #endif