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:
parent
ad3c1c6fde
commit
a9ef42e77b
@ -39,7 +39,7 @@ int main(int argc, char * argv[])
|
||||
usage();
|
||||
}
|
||||
|
||||
video_init();
|
||||
Video video;
|
||||
|
||||
lua_State * L = lua_open();
|
||||
|
||||
|
48
video.cc
48
video.cc
@ -4,10 +4,7 @@
|
||||
#include <iostream>
|
||||
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;
|
||||
}
|
||||
|
25
video.h
25
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 <SDL/SDL.h>
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user