I've been doing a SDL openGL tutorial to show a simple triangle in fullscreen mode. The problem is, while the game is fullscreen and the background is black and all, when I try to draw triangles they 'clip' if they go otuside the 800*600 viewport I have defined (I have 1280*800 on my laptop). So the game should change the reoslution while playing to 800*600.
Here's what I've done - I know its alot
#include "cApp.h"
//
// constructor
//
cApp::cApp() {
running = true;
mainSurface = NULL;
}
//
// destructor
//
cApp::~cApp() {
}
//
// toggls fullscreen
//
void cApp::toggleFullscreen() {
if(!SDL_WM_ToggleFullScreen(mainSurface))
onExit();
}
//
// creates the main window
//
void cApp::createWindow(int height, int width, int flags) {
mainSurface = SDL_SetVideoMode(width,height,SCREEN_DEPTH,flags);
if (!mainSurface)
onExit();
}
//
// initialises opengl
//
void cApp::initOpenGL() {
glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity();
// FOV // Ratio
gluPerspective(45.0f,(GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT, 1 ,150.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity();
}
//
// renders a scene
//
void cApp::renderScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
// Position View Up Vector
gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0);
glBegin (GL_TRIANGLES); // This is our BEGIN to draw
glVertex3f(0, 1, 0); // Here is the top point of the triangle
glVertex3f(-1, 0, 0); glVertex3f(1, 0, 0); // Here are the left and right points of the triangle
glEnd();
SDL_GL_SwapBuffers();
}
//
// handles key-down event
//
void cApp::onKeyDown(SDL_keysym* keysym) {
switch (keysym->sym) {
case SDLK_ESCAPE:
onExit();
default:
break;
}
}
//
// Cleans up resources
//
void cApp::onCleanup() {
SDL_Quit();
}
//
// Starts terminating game
//
void cApp::onExit() {
running = false;
}
//
// render graphics
//
void cApp::onRender() {
renderScene();
}
//
// game logics
//
void cApp::onLoop() {
}
//
// event handling
//
void cApp::onEvent(SDL_Event* Event) {
switch (Event->type) {
case SDL_KEYDOWN:
onKeyDown(&Event->key.keysym);
break;
default:
break;
}
}
//
// init
//
bool cApp::onInit() {
if(SDL_Init( SDL_INIT_VIDEO ) < 0)
return false;
// create main window
createWindow(SCREEN_HEIGHT,SCREEN_WIDTH,SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_FULLSCREEN);
// init opengl
initOpenGL();
return true;
}
//
// Entry point & main loop
//
int cApp::onExecute() {
bool res;
if (!( res = onInit())) {
onCleanup();
return -1;
}
SDL_Event m_event;
while (running) {
while(SDL_PollEvent(&m_event)) {
onEvent(&m_event);
}
onLoop();
onRender();
}
onCleanup();
return 0;
}