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();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
video_init();
|
Video video;
|
||||||
|
|
||||||
lua_State * L = lua_open();
|
lua_State * L = lua_open();
|
||||||
|
|
||||||
|
40
video.cc
40
video.cc
@ -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;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDefaultWidth()
|
m_surface = NULL;
|
||||||
{
|
|
||||||
return default_width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDefaultHeight()
|
void Video::start(int width, int height, bool fullscreen)
|
||||||
{
|
{
|
||||||
return default_height;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
25
video.h
25
video.h
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user