summaryrefslogtreecommitdiffstats
path: root/video.cpp
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-21 04:48:02 +0100
committerNao Pross <naopross@thearcway.org>2019-01-21 04:48:02 +0100
commitca091e358a8b02423ba304bfca055712b3a70881 (patch)
tree71252ee4f0316387fd2c335fe299313b5b313167 /video.cpp
parentInitial commit, add makefile, .gitignore and debug header (diff)
downloadlibwsdl2-ca091e358a8b02423ba304bfca055712b3a70881.tar.gz
libwsdl2-ca091e358a8b02423ba304bfca055712b3a70881.zip
Add basic window wrapper
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/video.cpp b/video.cpp
new file mode 100644
index 0000000..8413cb4
--- /dev/null
+++ b/video.cpp
@@ -0,0 +1,44 @@
+#include "video.hpp"
+#include "debug.hpp"
+
+extern "C" {
+#include <SDL2/SDL.h>
+}
+
+#include <exception>
+
+
+using namespace wrapsdl2;
+
+window::window(const std::string& title, std::size_t width, std::size_t height) {
+ // create (hidden) window
+ m_window = SDL_CreateWindow(
+ title.c_str(),
+ SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED,
+ static_cast<int>(width),
+ static_cast<int>(height),
+ SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN
+ );
+
+ if (m_window == NULL) {
+ throw std::runtime_error("failed to create SDL window");
+ }
+
+ // create surface
+ m_surface = SDL_GetWindowSurface(m_window);
+}
+
+window::~window() {
+ SDL_FreeSurface(m_surface);
+ SDL_DestroyWindow(m_window);
+}
+
+
+void window::show() { SDL_ShowWindow(m_window); }
+void window::hide() { SDL_HideWindow(m_window); }
+void window::raise() { SDL_RaiseWindow(m_window); }
+
+void window::update() {
+ SDL_UpdateWindowSurface(m_window);
+} \ No newline at end of file