diff options
author | chai <chaifix@163.com> | 2018-05-17 19:12:18 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-05-17 19:12:18 +0800 |
commit | 9edf2ba9fe8524976d2f298767fff0149e8c0d41 (patch) | |
tree | 38d74676a57de508a40ac581286255c2a18dce12 /src/libjin/render/window.cpp | |
parent | 70cdd89e887641b7423e5d4d05928d14ee014aba (diff) |
change file tree
Diffstat (limited to 'src/libjin/render/window.cpp')
-rw-r--r-- | src/libjin/render/window.cpp | 83 |
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 |