anaglym/Video.cc
Josh Holtrop 302764c865 grabbing input and hiding cursor by default
git-svn-id: svn://anubis/anaglym/trunk@28 99a6e188-d820-4881-8870-2d33a10e2619
2009-09-22 22:19:50 +00:00

61 lines
1.3 KiB
C++

#include "Video.h"
#include <SDL.h>
#include <iostream>
using namespace std;
Video::Video()
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
cerr << "SDL_Init() returned error!" << endl;
exit(3);
}
const SDL_VideoInfo * vidInfo = SDL_GetVideoInfo();
if (vidInfo != NULL)
{
m_defaultWidth = vidInfo->current_w;
m_defaultHeight = vidInfo->current_h;
}
else
{
cerr << "Warning: SDL_GetVideoInfo() returned NULL!" << endl;
m_defaultWidth = 1024;
m_defaultHeight = 768;
}
m_surface = NULL;
m_inputGrabbed = false;
}
void Video::start(int width, int height, bool fullscreen)
{
if (m_surface == NULL)
{
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);
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_GrabInput(SDL_GRAB_ON);
m_inputGrabbed = true;
m_fullscreen = fullscreen;
}
}
void Video::stop()
{
if (m_surface != NULL)
{
SDL_FreeSurface(m_surface);
m_surface = NULL;
}
}