From bf4827f46f22b4df0fa2ddd6716fd59247f9e1bb Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 2 Oct 2010 01:52:19 +0200 Subject: Ported from SDL to SFML. --- application.cpp | 61 ++++++++++++--------------------------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) (limited to 'application.cpp') diff --git a/application.cpp b/application.cpp index 07f4411..cafaeab 100644 --- a/application.cpp +++ b/application.cpp @@ -3,11 +3,6 @@ #include Application::Application() { - // Initialize SDL - if(SDL_Init(SDL_INIT_VIDEO)) { - throw(std::runtime_error("SDL initialization failed")); - } - please_quit = false; } @@ -16,47 +11,15 @@ Application::~Application() { } void Application::init_window(unsigned int w, unsigned int h, bool fs) { - // Fetch the video info - const SDL_VideoInfo *info = SDL_GetVideoInfo(); - if(!info) { - throw(std::runtime_error("SDL info query failed")); - } - // The SDL mode-flags - int flags = SDL_OPENGL; // OpenGL in SDL - flags |= SDL_GL_DOUBLEBUFFER; // Double buffering - flags |= SDL_HWPALETTE; // Hardware palette - // Check for hardware surface aviability - if(info->hw_available) { - flags |= SDL_HWSURFACE; - } else { - flags |= SDL_SWSURFACE; - } - // Check for hardware blit ability - if(info->blit_hw) { - flags |= SDL_HWACCEL; - } - // Setup double buffering - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + window = new sf::Window(sf::VideoMode(w, h, 32), "Foo"); - SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); - - if(fs) { - flags |= SDL_FULLSCREEN; - } - - // Get our surface - surface = SDL_SetVideoMode(w, h, 32, flags); - if(!surface) { - throw(std::runtime_error("Video mode set failed")); - } + window->UseVerticalSync(true); } void Application::run() { while(1) { - SDL_Event e; - while(SDL_PollEvent(&e)) { + sf::Event e; + while(window->GetEvent(e)) { event(e); } @@ -65,6 +28,8 @@ void Application::run() { } update(); + + window->Display(); } } @@ -72,22 +37,22 @@ void Application::quit() { please_quit = true; } -void Application::event(const SDL_Event& e) { - switch(e.type) { - case SDL_QUIT: +void Application::event(const sf::Event& e) { + switch(e.Type) { + case sf::Event::Closed: quit(); break; - case SDL_KEYDOWN: - event_keypress(e.key.keysym.sym); + case sf::Event::KeyPressed: + event_keypress(e.Key.Code); break; default: break; } } -void Application::event_keypress(SDLKey key) { +void Application::event_keypress(sf::Key::Code key) { switch(key) { - case SDLK_ESCAPE: + case sf::Key::Escape: quit(); break; default: -- cgit v1.2.3