converted video interface to a C++ class Video

git-svn-id: svn://anubis/anaglym/trunk@18 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-09-20 01:32:23 +00:00
parent ad3c1c6fde
commit a9ef42e77b
3 changed files with 51 additions and 24 deletions

View File

@ -39,7 +39,7 @@ int main(int argc, char * argv[])
usage(); usage();
} }
video_init(); Video video;
lua_State * L = lua_open(); lua_State * L = lua_open();

View File

@ -4,10 +4,7 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
static int default_width = 0; Video::Video()
static int default_height = 0;
void video_init()
{ {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) 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(); const SDL_VideoInfo * vidInfo = SDL_GetVideoInfo();
if (vidInfo != NULL) if (vidInfo != NULL)
{ {
default_width = vidInfo->current_w; m_defaultWidth = vidInfo->current_w;
default_height = vidInfo->current_h; m_defaultHeight = vidInfo->current_h;
} }
else else
{ {
cerr << "Warning: SDL_GetVideoInfo() returned NULL!" << endl; cerr << "Warning: SDL_GetVideoInfo() returned NULL!" << endl;
default_width = 1024; m_defaultWidth = 1024;
default_height = 768; 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;
}

25
video.h
View File

@ -1,9 +1,24 @@
#ifndef SDL_H #ifndef VIDEO_H
#define SDL_H #define VIDEO_H
void video_init(); #include <SDL/SDL.h>
int getDefaultWidth();
int getDefaultHeight(); 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 #endif