]> git.localhorst.tv Git - tacos.git/blobdiff - src/graphics/window.cpp
basic floor idea
[tacos.git] / src / graphics / window.cpp
diff --git a/src/graphics/window.cpp b/src/graphics/window.cpp
new file mode 100644 (file)
index 0000000..99f0090
--- /dev/null
@@ -0,0 +1,48 @@
+#include "window.hpp"
+
+#include "../app/error.hpp"
+
+#include <stdexcept>
+#include <string>
+#include <GL/glew.h>
+
+
+namespace tacos {
+
+Window::Window(int width, int height) {
+       window = SDL_CreateWindow(
+               "tacos", // title
+               SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, // position
+               width, height, // size
+               SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE // flags
+       );
+       if (!window) {
+               throw SDLError("SDL_CreateWindow");
+       }
+       context = SDL_GL_CreateContext(window);
+       if (!context) {
+               SDL_DestroyWindow(window);
+               throw SDLError("SDL_GL_CreateContext");
+       }
+       glewExperimental = GL_TRUE;
+       GLenum err = glewInit();
+       if (err != GLEW_OK) {
+               SDL_GL_DeleteContext(context);
+               SDL_DestroyWindow(window);
+               std::string msg("glewInit: ");
+               msg += reinterpret_cast<const char *>(glewGetErrorString(err));
+               throw std::runtime_error(msg);
+       }
+}
+
+Window::~Window() noexcept {
+       SDL_GL_DeleteContext(context);
+       SDL_DestroyWindow(window);
+}
+
+void Window::Flip() noexcept {
+       SDL_GL_SwapWindow(window);
+}
+
+
+}