#include "fns.h"
#include <string>
#include <iostream>
-#include <GL/gl.h>
+#include <SDL/SDL_opengl.h>
#include "SDL_ttf.h"
const Uint32 Game::waitTime = 1000/60; /* ms */
glLoadIdentity();
}
+void Reshape( int w, int h )
+{
+ if( h <= 0 ) h = 1 ;
+
+ glViewport( 0, 0, w, h ) ;
+
+ glMatrixMode( GL_PROJECTION ) ;
+ glLoadIdentity() ;
+ gluPerspective( 45.0, (GLfloat)w / (GLfloat)h, 0.1, 1000.0 ) ;
+
+ glMatrixMode( GL_MODELVIEW ) ;
+ glLoadIdentity() ;
+}
/** Global static pointer used to ensure a single instance of the class. */
Game* Game::m_instance = NULL;
/** This function is called to create an instance of the class.
- Calling the constructor publicly is not allowed.
- The constructor is private and is only called by this Instance function.
+Calling the constructor publicly is not allowed.
+The constructor is private and is only called by this Instance function.
*/
Game* Game::game(){
if(!m_instance)
}
atexit (SDL_Quit);
// Initialize SDL_ttf library
- if (TTF_Init() != 0)
- {
- cerr << "TTF_Init() Failed: " << TTF_GetError() << endl;
- SDL_Quit();
- exit(1);
- }
+ if (TTF_Init() != 0)
+ {
+ cerr << "TTF_Init() Failed: " << TTF_GetError() << endl;
+ SDL_Quit();
+ exit(1);
+ }
atexit (TTF_Quit);
+
+ /* Turn on double buffering with a 24bit Z buffer.
+ * You may need to change this to 16 or 32 for your system */
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+
/** Set 800x600 video mode */
- mScreen = SDL_SetVideoMode(screenwidth, screenheight, 32, SDL_OPENGL);
+ mScreen = SDL_SetVideoMode(screenwidth, screenheight, 32, SDL_OPENGL | SDL_RESIZABLE);
if (!mScreen) {
printf ("Couldn't set video mode: %s\n", SDL_GetError ());
exit (2);
SDL_WM_SetCaption("Ivan's Game", NULL);
SDL_ShowCursor(0);
-
+
init_GL(screenwidth, screenheight);
/** Load Resources */
LoadResources();
-
+
// set start time for fps calc
startclock = SDL_GetTicks();
}
done = 1;
break;
+ case SDL_VIDEORESIZE :
+ Reshape( event.resize.w, event.resize.h ) ;
+ break ;
+
case SDL_USEREVENT:
getCurrentLevel()->drawScene();
break;