diff options
author | chai <chaifix@163.com> | 2019-01-12 19:04:27 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-01-12 19:04:27 +0800 |
commit | 3b4ee6f0d65b055c938679f5a95a5e7f116825bf (patch) | |
tree | 2f7dcddecacb98eb9755e1699526724e31905506 /src/libjin/graphics/je_gl.cpp | |
parent | e1e9a0d2262dd90507eae0dc3d779a1a6d5b78bd (diff) |
+glad
Diffstat (limited to 'src/libjin/graphics/je_gl.cpp')
-rw-r--r-- | src/libjin/graphics/je_gl.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp index 3ce869a..1783ef1 100644 --- a/src/libjin/graphics/je_gl.cpp +++ b/src/libjin/graphics/je_gl.cpp @@ -1,4 +1,6 @@ #define OGL2D_IMPLEMENT +#include "../utils/je_log.h" + #include "je_gl.h" #include "je_color.h" #include "je_canvas.h" @@ -18,7 +20,7 @@ namespace JinEngine OpenGL gl; - Canvas* const OpenGL::DEFAULT_CANVAS = new Canvas(0); + Canvas* const OpenGL::SCREEN = NULL; OpenGL::OpenGL() { @@ -35,10 +37,21 @@ namespace JinEngine { } + bool OpenGL::initContext() + { + // Init glad library. + if (!gladLoadGLLoader(SDL_GL_GetProcAddress)) + { + jin_log_error("init opengl context failed"); + return false; + } + + return true; + } + void OpenGL::init() { enable(GL_BLEND); - //enable(GL_TEXTURE_2D); setClearColor(0, 0, 0, 0xff); setColor(0xff, 0xff, 0xff, 0xff); setBlendMode(OpenGL::BlendMode::ALPHA); @@ -350,18 +363,17 @@ namespace JinEngine void OpenGL::unbindCanvas() { // Default bind to default canvas. - if (getCanvas() == DEFAULT_CANVAS) + if (getCanvas() == SCREEN) return; // Get window size as viewport. Window* wnd = Window::get(); int w = wnd->getW(); int h = wnd->getH(); - GLuint fbo = DEFAULT_CANVAS->getGLFrameBuffer(); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, w, h); gl.setProjectionMatrix(0, w, h, 0, -1, 1); - mCanvas = DEFAULT_CANVAS; + mCanvas = SCREEN; } Canvas* OpenGL::getCanvas() |