diff options
Diffstat (limited to 'src/libjin/graphics')
-rw-r--r-- | src/libjin/graphics/je_bitmap.h | 2 | ||||
-rw-r--r-- | src/libjin/graphics/je_gl.cpp | 24 | ||||
-rw-r--r-- | src/libjin/graphics/je_gl.h | 7 | ||||
-rw-r--r-- | src/libjin/graphics/je_graphic.cpp | 2 | ||||
-rw-r--r-- | src/libjin/graphics/je_texture.h | 2 | ||||
-rw-r--r-- | src/libjin/graphics/je_window.cpp | 4 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_shader.cpp | 2 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_shader.h | 2 |
8 files changed, 28 insertions, 17 deletions
diff --git a/src/libjin/graphics/je_bitmap.h b/src/libjin/graphics/je_bitmap.h index 644e56e..ad4ab05 100644 --- a/src/libjin/graphics/je_bitmap.h +++ b/src/libjin/graphics/je_bitmap.h @@ -5,8 +5,6 @@ #include <functional> -#include "GLee/GLee.h" - #include "../common/je_types.h" #include "../math/je_vector2.hpp" 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() diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h index 090003c..6f88ba1 100644 --- a/src/libjin/graphics/je_gl.h +++ b/src/libjin/graphics/je_gl.h @@ -6,7 +6,8 @@ #include "../math/je_matrix.h" #include "../math/je_transform.h" -#include "GLee/GLee.h" +//#include "GLee/GLee.h" +#include "glad/glad.h" #include "je_color.h" @@ -50,11 +51,13 @@ namespace JinEngine //int64 textureMemory; }; - static Canvas* const DEFAULT_CANVAS; + static Canvas* const SCREEN; OpenGL(); ~OpenGL(); + bool initContext(); + void init(); void enable(GLenum cap); diff --git a/src/libjin/graphics/je_graphic.cpp b/src/libjin/graphics/je_graphic.cpp index d4a706a..e097230 100644 --- a/src/libjin/graphics/je_graphic.cpp +++ b/src/libjin/graphics/je_graphic.cpp @@ -37,7 +37,6 @@ namespace JinEngine glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl.texImage(GL_RGBA8, mSize.w(), mSize.h(), GL_RGBA, GL_UNSIGNED_BYTE, pixels); - } Graphic::~Graphic() @@ -50,7 +49,6 @@ namespace JinEngine gl.bindTexture2D(mTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, max_filter); - } void Graphic::render(float x, float y, float sx, float sy, float r, float ox, float oy) const diff --git a/src/libjin/graphics/je_texture.h b/src/libjin/graphics/je_texture.h index a99033f..6b8fa54 100644 --- a/src/libjin/graphics/je_texture.h +++ b/src/libjin/graphics/je_texture.h @@ -3,8 +3,6 @@ #include "../core/je_configuration.h" #if defined(jin_graphics) -#include "GLee/GLee.h" - #include "je_color.h" #include "je_graphic.h" #include "je_bitmap.h" diff --git a/src/libjin/graphics/je_window.cpp b/src/libjin/graphics/je_window.cpp index 1ccf1fb..fcca1b7 100644 --- a/src/libjin/graphics/je_window.cpp +++ b/src/libjin/graphics/je_window.cpp @@ -85,8 +85,12 @@ namespace JinEngine ctx = SDL_GL_CreateContext(mWnd); if (ctx == NULL) return false; + + gl.initContext(); + SDL_GL_SetSwapInterval(vsync ? 1 : 0); SDL_GL_MakeCurrent(mWnd, ctx); + // Default configuration. gl.init(); diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp index 3df5a86..65ad8c7 100644 --- a/src/libjin/graphics/shaders/je_shader.cpp +++ b/src/libjin/graphics/shaders/je_shader.cpp @@ -88,7 +88,7 @@ namespace JinEngine sendInt(SHADER_MAIN_TEXTURE, MAIN_TEXTURE_UNIT); sendVec2(SHADER_TIME, Time::getSecond(), Time::getDeltaTime()); Canvas* rt = gl.getCanvas(); - if (rt == OpenGL::DEFAULT_CANVAS) + if (rt == OpenGL::SCREEN) { sendVec2(SHADER_RENDERTARGET_SIZE, Window::get()->getW(), Window::get()->getH()); } diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h index 402805a..240f24f 100644 --- a/src/libjin/graphics/shaders/je_shader.h +++ b/src/libjin/graphics/shaders/je_shader.h @@ -7,8 +7,6 @@ #include <string> #include <map> -#include "GLee/GLee.h" - #include "../../common/je_string.h" #include "../je_color.h" |