aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/render/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/render/window.cpp')
-rw-r--r--src/libjin/render/window.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/libjin/render/window.cpp b/src/libjin/render/window.cpp
new file mode 100644
index 0000000..20a6adc
--- /dev/null
+++ b/src/libjin/render/window.cpp
@@ -0,0 +1,83 @@
+#include "window.h"
+#include "3rdparty/GLee/GLee.h"
+#include "canvas.h"
+#include "utils/macros.h"
+namespace jin
+{
+namespace render
+{
+
+ shared Window* Window::g_wnd = 0;
+
+ Window::Window(): wnd(0), ctx(0)
+ {
+ }
+
+ Window::~Window()
+ {
+ }
+
+ void Window::init(int pw, int ph, const char* t)
+ {
+ w = pw;
+ h = ph;
+
+ if (wnd)
+ {
+ SDL_DestroyWindow(wnd);
+ SDL_FlushEvent(SDL_WINDOWEVENT);
+ }
+
+ if (ctx)
+ {
+ SDL_GL_DeleteContext(ctx);
+ }
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+
+ Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL ;
+
+ int wx = SDL_WINDOWPOS_UNDEFINED,
+ wy = SDL_WINDOWPOS_UNDEFINED;
+
+ /* Create window */
+ wnd = SDL_CreateWindow(t, wx, wy, w, h, flags);
+
+ // Create an opengl context
+ ctx = SDL_GL_CreateContext(wnd);
+ SDL_GL_MakeCurrent(wnd, ctx);
+
+ // Default clear color
+ glClearColor(0.f, 0.f, 0.f, 1.f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ // Default render color
+ glColor4f(1, 1, 1, 1);
+
+ /**
+ * Set the viewport to top-left corner.
+ * Bind to the default render buffer.
+ */
+ Canvas::unbind();
+
+ // Swap window buffer
+ swapBuffers();
+ }
+
+ SDL_Window* Window::getWnd()
+ {
+ return wnd;
+ }
+
+ SDL_GLContext Window::getCtx()
+ {
+ return ctx;
+ }
+
+}
+} \ No newline at end of file