2014-12-20 01:46:31 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: Window.cpp
|
|
|
|
*
|
2018-06-05 01:24:54 +02:00
|
|
|
* Description:
|
2014-12-20 01:46:31 +01:00
|
|
|
*
|
|
|
|
* Created: 20/12/2014 00:17:10
|
|
|
|
*
|
2018-06-12 09:24:43 +02:00
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
2014-12-20 01:46:31 +01:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#include "OpenGL.hpp"
|
|
|
|
#include "Exception.hpp"
|
|
|
|
#include "Window.hpp"
|
|
|
|
|
2018-06-05 16:17:40 +02:00
|
|
|
void Window::open(const std::string &caption, u16 width, u16 height) {
|
2015-02-06 01:44:16 +01:00
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-06-05 16:17:40 +02:00
|
|
|
m_window.reset(SDL_CreateWindow(caption.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN));
|
2014-12-20 01:46:31 +01:00
|
|
|
if(!m_window) {
|
|
|
|
throw EXCEPTION("Window initialization failed:", SDL_GetError());
|
|
|
|
}
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-06-05 16:17:40 +02:00
|
|
|
m_context.reset(SDL_GL_CreateContext(m_window.get()));
|
|
|
|
if(!m_context) {
|
2014-12-20 01:46:31 +01:00
|
|
|
throw EXCEPTION("OpenGL context creation failed:", SDL_GetError());
|
|
|
|
}
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2014-12-20 01:46:31 +01:00
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2014-12-20 01:46:31 +01:00
|
|
|
m_isOpen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::clear() {
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::display() {
|
2018-06-05 16:17:40 +02:00
|
|
|
SDL_GL_SwapWindow(m_window.get());
|
2014-12-20 01:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setMouseCursorGrabbed(bool grabbed) {
|
|
|
|
SDL_SetRelativeMouseMode((SDL_bool)grabbed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setMouseCursorVisible(bool visible) {
|
|
|
|
SDL_ShowCursor(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setVerticalSyncEnabled(bool enabled) {
|
|
|
|
if(SDL_GL_SetSwapInterval(enabled) < 0) {
|
|
|
|
DEBUG("Warning: Can't enable VSync");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|