00001
#include "window_sdl.h"
00002
00003
CWindowSDL* CWindowSDL::m_pInstance = 0;
00004
00005 CWindowSDL::CWindowSDL ()
00006 {
00007 m_pSurface = 0;
00008 }
00009
00010 CWindowSDL::~CWindowSDL ()
00011 {
00012
if (m_pSurface)
00013 SDL_FreeSurface (m_pSurface);
00014 }
00015
00016 CWindowSDL*
CWindowSDL::Instance ()
00017 {
00018
if (m_pInstance == 0)
00019 m_pInstance =
new CWindowSDL;
00020
return m_pInstance;
00021 }
00022
00023 void CWindowSDL::Kill ()
00024 {
00025
if (m_pInstance != 0)
00026 {
00027
delete m_pInstance;
00028 m_pInstance = 0;
00029 }
00030 }
00031
00032 bool CWindowSDL::IsCreate ()
00033 {
00034
return m_pInstance != 0;
00035 }
00036
00037 void CWindowSDL::Swap ()
00038 {
00039 SDL_GL_SwapBuffers ();
00040 }
00041
00042 bool CWindowSDL::Create (
const char* szName,
unsigned short unWidth,
unsigned short unHeight,
unsigned char ucColor,
bool bFullscreen)
00043 {
00044
if (SDL_Init (SDL_INIT_VIDEO) < 0)
00045 {
00046 printf (
"Impossible d'initializing SDL Video : %s", SDL_GetError ());
00047
return false;
00048 }
00049
00050
00051
00052
00053
00054
00055
unsigned int uiVideoFlags = SDL_OPENGL | SDL_DOUBLEBUF | SDL_HWPALETTE | SDL_RESIZABLE;
00056
00057
if (bFullscreen)
00058 uiVideoFlags |= SDL_FULLSCREEN;
00059
00060
const SDL_VideoInfo *pVideoInfo = SDL_GetVideoInfo ();
00061
00062
00063
if (pVideoInfo->hw_available)
00064 uiVideoFlags |= SDL_HWSURFACE;
00065
else
00066 uiVideoFlags |= SDL_SWSURFACE;
00067
00068
if (pVideoInfo->blit_hw)
00069 uiVideoFlags |= SDL_HWACCEL;
00070
00071
00072 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
00073 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
00074 SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 0);
00075 SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0);
00076 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
00077 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
00078 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
00079
00080
if ((m_pSurface = SDL_SetVideoMode (unWidth, unHeight, ucColor, uiVideoFlags)) == 0)
00081 {
00082
return false;
00083
00084 }
00085
00086 SDL_WM_SetCaption (szName, szName);
00087 _Resize (unWidth, unHeight);
00088
00089
00090
unsigned char pucData[4] = {0, 0, 0, 0};
00091 SDL_Cursor* pCursor = SDL_CreateCursor (pucData, pucData, 4, 4, 0, 0);
00092 SDL_SetCursor (pCursor);
00093
00094
return true;
00095 }
00096
00097
void CWindowSDL::_Resize (
unsigned short unWidth,
unsigned short unHeight)
00098 {
00099
if (unHeight == 0)
00100 unHeight = 1;
00101
00102 glViewport (0, 0, unWidth, unHeight);
00103
00104 glMatrixMode (GL_PROJECTION);
00105 glLoadIdentity ();
00106
00107 gluPerspective (45.f, (
float)unWidth / (
float)unHeight, 0.1f, 512);
00108
00109 glMatrixMode (GL_MODELVIEW);
00110 glLoadIdentity ();
00111 }
00112