Your new problem is in events.h
Look carefully at this code:
bool events::closeRequest(){ bool closeRequest = false; while(closeRequest == false) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { closeRequest = true; } } } return closeRequest; }
Be cause we have an outer while loop that says 'while( closeRequest == false )', the entire function
cannot return until this condition is met. Obviously the only way for this condition to be true is if we receive the SDL_QUIT event. A better name for this function might be loopForeverUntilWindowIsClosed [smile].
We can re-write simply:
bool events::closeRequest(){ while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { return true; } } return false; }
Here is how I would re-write your code (bear in mind I threw it all into a single file, you will have to separate it again):
#include <iostream>#include <stdexcept>#include "SDL.h"#include "SDL_opengl.h"class SGE{public: // Don't write empty constructors // Especially when there is a sane task we can give the constructor SGE(int screenWidth, int screenHeight, int bitsPerPixel); ~SGE(); // removed in favour of the constructor // void startWindow(); // avoid functions returning a boolean or integer // that always return the same value. use 'void' // bool stopWindow(); void draw();private: // we can be a little more descriptive with our variable names ;) int screenWidth; int screenHeight; int bitsPerPixel;};// In C++, we initialise variables in the constructors 'intialiser list'// You start with a colon following the end of the argument list// then you place each member variable you want to initialise// with parentheses around what you wish to initialise it with.// also note I used the same name for the parameters as the members// this is ok, C++ knows that in an initialiser list the only thing that// can be initialised are membersSGE::SGE(int screenWidth, int screenHeight, int bitsPerPixel): screenWidth(screenWidth), screenHeight(screenHeight), bitsPerPixel(bitsPerPixel){ // logging removed because you didn't include it in zip // log logIns; // prefer to declare variables at point of use // SDL_Surface *screen; if(SDL_Init(SDL_INIT_VIDEO) != 0) { // as a fatal error, throwing an exception is a reasonable thing to do throw std::runtime_error(SDL_GetError()); } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_Surface * screen = SDL_SetVideoMode(screenWidth, screenHeight, bitsPerPixel, SDL_OPENGL /*| SDL_FULLSCREEN*/); if(!screen) { // same as above regarding fatal error // also note we need to call SDL_Quit() here // destructors do not get called when an object throws an // exception in its constructor SDL_Quit(); throw std::runtime_error(SDL_GetError()); }}SGE::~SGE(){ SDL_Quit();}void SGE::draw(){ glClearColor(0.0, 0.0, 0.0, 0.0); glBegin(GL_LINES); glVertex3f(6.0, 4.0, 2.0); glVertex3f(2.0, -4.0, 3.3); glVertex3f(5.0, 8.0, 8.0); glVertex3f(-4.7, 5.0, -3.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(6.0, -1.0, -7.0); glEnd(); SDL_GL_SwapBuffers();}class events{public: // Don't write empty constructors and destructors // C++ will generate these for you if you don't provide them // C++ will also generate copy constructors and operator=() // which are not always desired // events(); // ~events(); bool closeRequest();private: SDL_Event event;};bool events::closeRequest(){ while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { return true; } } // if we reach here, then we must not have received the SDL_QUIT event return false;}int main(int argc, char *argv[]){ SGE engineInstance(300,300,32); // logging removed because you didn't include it in zip //log logInstance; events eventInstance; while(eventInstance.closeRequest() == false) { engineInstance.draw(); } return 0; // engineInstance destructor cleans up SDL for us}