Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

pge::SDLApplication Class Reference

#include <SDLApplication.h>

Inheritance diagram for pge::SDLApplication:

Inheritance graph
[legend]

Public Types

typedef pge::SDLApplication::MouseCoordinate MouseCoordinate

Public Member Functions

virtual ~SDLApplication (void)
 Destructor.

virtual void initCall (void)=0
virtual void reshapeCall (GLsizei width, GLsizei height)=0
virtual void keyDownCall (int key)=0
virtual void keyUpCall (int key)=0
virtual void mousePressCall (int button, int x, int y)=0
virtual void mouseReleaseCall (int button, int x, int y)=0
virtual void mainLoopCall (void)=0
void execute (void)
void shutdown (void)
void sleep (unsigned int delay)
void swapBuffer (void)
unsigned int getTicks (void)
void setMousePointer (int x, int y)
void setMousePointer (const MouseCoordinate &coord)
MouseCoordinate getMousePointer (void)
int getResolutionWidth (void)
int getResolutionHeight (void)
int getDisplayDepth (void)
bool isFullscreen (void)
std::string getTitle (void)

Protected Member Functions

bool openWindow (int resX, int resY, int bits, bool fullScreen, const std::string &title)

Private Attributes

int m_resX
int m_resY
int m_bits
bool m_fullscreen
std::string m_title
SDL_Surface * m_surface
int m_videoFlags
bool m_running

Member Typedef Documentation

typedef struct pge::SDLApplication::MouseCoordinate pge::SDLApplication::MouseCoordinate
 

Referenced by pge::GLApplication::mainLoopCall().


Constructor & Destructor Documentation

pge::SDLApplication::~SDLApplication void   )  [virtual]
 

Destructor.

Definition at line 46 of file SDLApplication.cpp.

References m_bits, m_fullscreen, m_resX, m_resY, m_running, m_surface, m_title, and m_videoFlags.

00046                                             {
00047                 m_surface = NULL;
00048                 m_resX = 0;
00049                 m_resY = 0;
00050                 m_bits = 0;
00051                 m_fullscreen = false;
00052                 m_title = "";
00053                 m_videoFlags = 0;
00054                 m_running = false;
00055         }


Member Function Documentation

void pge::SDLApplication::execute void   ) 
 

Definition at line 170 of file SDLApplication.cpp.

References initCall(), keyDownCall(), keyUpCall(), m_bits, m_running, m_surface, m_videoFlags, mainLoopCall(), mousePressCall(), mouseReleaseCall(), and reshapeCall().

00170                                          {
00171                 //
00172                 // Variables
00173                 //
00174                 SDL_Event event;
00175 
00176 
00177                 //pLogger::getInstance()->printLog("pSDLApplication: Trying to execute application ...");
00178 
00179                 // check for initialization
00180                 if(m_surface == NULL) {
00181                         //pLogger::getInstance()->printError("pSDLApplication: Initialization error. Be sure to run openWindow(...) before executing!");
00182                         return;
00183                 } else {
00184                         //pLogger::getInstance()->printLog("pSDLApplication: Init done. Entering main loop!");
00185                 }
00186 
00187                 // Do the only global init just before entering the mainloop.
00188                 initCall();
00189 
00190                 m_running = true;
00191 
00192                 // SDL main loop.
00193                 // Continue main loop until running is false.
00194                 while(m_running) {
00195 
00196                         // get the SDL events
00197                         while(SDL_PollEvent(&event)) {
00198 
00199                                 // handle event
00200                                 switch (event.type) {
00201 
00202                                         // if the program received the SDL_QUIT event, then quit
00203                                 case SDL_QUIT:
00204                                         m_running = false;
00205                                         break;
00206 
00207                                         // if the program received a keystroke event
00208                                 case SDL_KEYDOWN:
00209                                         keyDownCall(event.key.keysym.sym);
00210                                         break;
00211 
00212                                 case SDL_KEYUP:
00213                                         keyUpCall(event.key.keysym.sym);
00214                                         break;
00215 
00216                                 case SDL_MOUSEMOTION:
00217                                         // Do not call mouseMotion(x, y); here because warping the pointer creates
00218                                         // a new mousemotion event -> the system gets caught in an endless loop
00219                                         break;
00220 
00221                                 case SDL_MOUSEBUTTONDOWN:
00222                                         mousePressCall(event.button.button, event.button.x, event.button.y);
00223                                         break;
00224 
00225                                 case SDL_MOUSEBUTTONUP:
00226                                         mouseReleaseCall(event.button.button, event.button.x, event.button.y);
00227                                         break;
00228 
00229                                         // if the program received a resize event
00230                                 case SDL_VIDEORESIZE:
00231                                         // request SDL to resize the window to the size and
00232                                         // depth etc. that we specify
00233                                         m_surface = SDL_SetVideoMode(event.resize.w, event.resize.h, m_bits, m_videoFlags);
00234                                         // reshape the OpenGL window
00235                                         reshapeCall(event.resize.w, event.resize.h);
00236                                         if(m_surface == NULL) {
00237                                                 //pLogger::getInstance()->printError("pSDLApplication: Could not reshape OpenGL window.");
00238                                                 return;
00239                                         }
00240                                         break;
00241                                 // The default action
00242                                 default:
00243                                         break;
00244                                 }
00245                         }
00246                         mainLoopCall();
00247                 }
00248 
00249                 // program has run, shutdown now
00250                 //pLogger::getInstance()->printLog("pSDLApplication: Shutting down window.");
00251                 //pLogger::getInstance()->printLog("pSDLApplication: Bye Bye!");
00252 
00253                 SDL_FreeSurface(m_surface);
00254                 SDL_ShowCursor(SDL_ENABLE);
00255                 SDL_Quit();
00256         }

Here is the call graph for this function:

int pge::SDLApplication::getDisplayDepth void   ) 
 

Definition at line 358 of file SDLApplication.cpp.

References m_bits.

00358                                                 {
00359                 return m_bits;
00360         }

SDLApplication::MouseCoordinate pge::SDLApplication::getMousePointer void   ) 
 

Definition at line 324 of file SDLApplication.cpp.

References pge::SDLApplication::MouseCoordinate::x, and pge::SDLApplication::MouseCoordinate::y.

Referenced by pge::CoreEngine::mainLoop(), and pge::GLApplication::mainLoopCall().

00324                                                                           {
00325                 MouseCoordinate c;
00326 
00327 
00328                 SDL_GetMouseState(&c.x, &c.y);
00329                 return c;
00330         }

int pge::SDLApplication::getResolutionHeight void   ) 
 

Definition at line 348 of file SDLApplication.cpp.

References m_resY.

Referenced by pge::GLApplication::mainLoopCall().

00348                                                     {
00349                 return m_resY;
00350         }

int pge::SDLApplication::getResolutionWidth void   ) 
 

Definition at line 338 of file SDLApplication.cpp.

References m_resX.

Referenced by pge::GLApplication::mainLoopCall().

00338                                                    {
00339                 return m_resX;
00340         }

unsigned int pge::SDLApplication::getTicks void   ) 
 

Definition at line 294 of file SDLApplication.cpp.

Referenced by pge::CoreEngine::CoreEngine(), pge::GLApplication::GLApplication(), pge::CoreEngine::mainLoop(), and pge::GLApplication::mainLoopCall().

00294                                               {
00295                 return SDL_GetTicks();
00296         }

std::string pge::SDLApplication::getTitle void   ) 
 

Definition at line 378 of file SDLApplication.cpp.

References m_title.

00378                                                {
00379                 return m_title;
00380         }

virtual void pge::SDLApplication::initCall void   )  [pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

bool pge::SDLApplication::isFullscreen void   ) 
 

Definition at line 368 of file SDLApplication.cpp.

References m_fullscreen.

00368                                               {
00369                 return m_fullscreen;
00370         }

virtual void pge::SDLApplication::keyDownCall int  key  )  [pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

virtual void pge::SDLApplication::keyUpCall int  key  )  [pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

virtual void pge::SDLApplication::mainLoopCall void   )  [pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

virtual void pge::SDLApplication::mousePressCall int  button,
int  x,
int  y
[pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

virtual void pge::SDLApplication::mouseReleaseCall int  button,
int  x,
int  y
[pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

bool pge::SDLApplication::openWindow int  resX,
int  resY,
int  bits,
bool  fullScreen,
const std::string &  title
[protected]
 

Definition at line 63 of file SDLApplication.cpp.

References initVSync(), m_bits, m_fullscreen, m_resX, m_resY, m_running, m_surface, m_title, m_videoFlags, and setVSyncEnabled().

Referenced by pge::GLApplication::GLApplication().

00063                                                                                                              {
00064                 //
00065                 // Variables
00066                 //
00067                 const SDL_VideoInfo *videoInfo;
00068                 std::string logMessage;
00069 
00070 
00071                 m_resX = resX;
00072                 m_resY = resY;
00073                 m_bits = bits;
00074                 m_fullscreen = fullscreen;
00075                 m_title = title;
00076                 m_videoFlags = 0;
00077                 m_surface = NULL;
00078                 m_running = false;
00079 
00080                 /*pLogger::getInstance()->printLog("pSDLApplication: Trying to open window:");
00081                 if(m_fullscreen) {
00082                 pLogger::getInstance()->printLog("fullscreen.");
00083                 } else {
00084                 pLogger::getInstance()->printLog("window mode.");
00085                 }*/
00086 
00087                 // initialize SDL video mode and timer settings
00088                 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
00089                         //pLogger::getInstance()->printError("pSDLApplication: Could not initialize SDL.");
00090                         return false;
00091                 }
00092 
00093                 // set the video flags needed by SDL
00094                 m_videoFlags  = SDL_OPENGL;     // flag for opengl
00095                 m_videoFlags |= SDL_HWPALETTE;  // flag for access to hardware palette
00096                 m_videoFlags |= SDL_DOUBLEBUF;
00097                 m_videoFlags |= SDL_ANYFORMAT;
00098                 m_videoFlags |= SDL_OPENGLBLIT;
00099                 m_videoFlags |= SDL_RESIZABLE;  // enable the window to be resize-able;
00100                 if(m_fullscreen) {
00101                         m_videoFlags |= SDL_FULLSCREEN; // fullscreen
00102                 }
00103 
00104                 // get some hardware information
00105                 videoInfo = SDL_GetVideoInfo();
00106 
00107                 if(videoInfo == NULL) {
00108                         // receiving the info failed
00109                         //pLogger::getInstance()->printError("pSDLApplication: Could not get video info.");
00110                         return false;
00111                 }
00112 
00113                 // now set the available flags just tested
00114                 if(videoInfo->hw_available) {
00115                         m_videoFlags |= SDL_HWSURFACE;
00116                 } else {
00117                         m_videoFlags |= SDL_SWSURFACE;
00118                 }
00119                 // see if blitting is available
00120                 if(videoInfo->blit_hw) {
00121                         m_videoFlags |= SDL_HWACCEL;
00122                 }
00123 
00124                 // create an OpenGL double buffered rendering context
00125                 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
00126 
00127                 // the size of the OpenGL depth buffer
00128                 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_bits);
00129 
00130                 // size of the OpenGL stencil buffer
00131                 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
00132 
00133                 // size of the OpenGL accumulation buffer
00134                 SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);
00135                 SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);
00136                 SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0);
00137                 SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);
00138 
00139                 m_surface = SDL_SetVideoMode(m_resX, m_resY, m_bits, m_videoFlags);
00140 
00141                 if(m_surface == NULL) {
00142                         //pLogger::getInstance()->printError("pSDLApplication: Could not set SDL video mode.");
00143                         return false;
00144                 }
00145 
00146                 // Hide the mouse pointer
00147                 SDL_ShowCursor(SDL_DISABLE);
00148 
00149                 // This is very important for smooth mouse moving.
00150                 SDL_WM_GrabInput(SDL_GRAB_ON);
00151 
00152                 // Set the window caption ( first arg for window, second one for the iconified mode)
00153                 SDL_WM_SetCaption(m_title.c_str(), m_title.c_str());
00154 
00155                 //pLogger::getInstance()->printLog("pSDLApplication: SDL ok.");
00156 
00157                 if(initVSync()) {
00158                         setVSyncEnabled(false);
00159                 }
00160 
00161                 return true;
00162         }

Here is the call graph for this function:

virtual void pge::SDLApplication::reshapeCall GLsizei  width,
GLsizei  height
[pure virtual]
 

Implemented in pge::GLApplication.

Referenced by execute().

void pge::SDLApplication::setMousePointer const MouseCoordinate coord  ) 
 

Definition at line 314 of file SDLApplication.cpp.

References pge::SDLApplication::MouseCoordinate::x, and pge::SDLApplication::MouseCoordinate::y.

00314                                                                          {
00315                 SDL_WarpMouse(coord.x, coord.y);
00316         }

void pge::SDLApplication::setMousePointer int  x,
int  y
 

Definition at line 304 of file SDLApplication.cpp.

Referenced by pge::CoreEngine::mainLoop(), and pge::GLApplication::mainLoopCall().

00304                                                          {
00305                 SDL_WarpMouse(x, y);
00306         }

void pge::SDLApplication::shutdown void   ) 
 

Definition at line 264 of file SDLApplication.cpp.

References m_running.

Referenced by pge::CoreEngine::shutdown().

00264                                           {
00265                 m_running = false;
00266         }

void pge::SDLApplication::sleep unsigned int  delay  ) 
 

Definition at line 274 of file SDLApplication.cpp.

Referenced by pge::GLApplication::mainLoopCall().

00274                                                      {
00275                 SDL_Delay(delay);
00276         }

void pge::SDLApplication::swapBuffer void   ) 
 

Definition at line 284 of file SDLApplication.cpp.

Referenced by pge::CoreEngine::mainLoop(), and pge::GLApplication::mainLoopCall().

00284                                         {
00285                 SDL_GL_SwapBuffers();
00286         }


Field Documentation

int pge::SDLApplication::m_bits [private]
 

Definition at line 84 of file SDLApplication.h.

Referenced by execute(), getDisplayDepth(), openWindow(), and ~SDLApplication().

bool pge::SDLApplication::m_fullscreen [private]
 

Definition at line 85 of file SDLApplication.h.

Referenced by isFullscreen(), openWindow(), and ~SDLApplication().

int pge::SDLApplication::m_resX [private]
 

Definition at line 82 of file SDLApplication.h.

Referenced by getResolutionWidth(), openWindow(), and ~SDLApplication().

int pge::SDLApplication::m_resY [private]
 

Definition at line 83 of file SDLApplication.h.

Referenced by getResolutionHeight(), openWindow(), and ~SDLApplication().

bool pge::SDLApplication::m_running [private]
 

Definition at line 89 of file SDLApplication.h.

Referenced by execute(), openWindow(), shutdown(), and ~SDLApplication().

SDL_Surface* pge::SDLApplication::m_surface [private]
 

Definition at line 87 of file SDLApplication.h.

Referenced by execute(), openWindow(), and ~SDLApplication().

std::string pge::SDLApplication::m_title [private]
 

Definition at line 86 of file SDLApplication.h.

Referenced by getTitle(), openWindow(), and ~SDLApplication().

int pge::SDLApplication::m_videoFlags [private]
 

Definition at line 88 of file SDLApplication.h.

Referenced by execute(), openWindow(), and ~SDLApplication().


The documentation for this class was generated from the following files:
Generated on Mon Oct 16 12:09:30 2006 for Phobosengine by doxygen 1.3.4