aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Canvas.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-05 15:40:31 +0800
committerchai <chaifix@163.com>2018-10-05 15:40:31 +0800
commit789895b4b9f99668b8b772f271d07d1ce3115742 (patch)
tree3ae85381358445b2c29c9a0afb59375de9a7ce66 /src/libjin/Graphics/Canvas.cpp
parent846d6ab0ec1033481574e8324a43fc547ecf5882 (diff)
*update
Diffstat (limited to 'src/libjin/Graphics/Canvas.cpp')
-rw-r--r--src/libjin/Graphics/Canvas.cpp66
1 files changed, 17 insertions, 49 deletions
diff --git a/src/libjin/Graphics/Canvas.cpp b/src/libjin/Graphics/Canvas.cpp
index efcd12d..d34731a 100644
--- a/src/libjin/Graphics/Canvas.cpp
+++ b/src/libjin/Graphics/Canvas.cpp
@@ -1,4 +1,4 @@
-#include "../modules.h"
+#include "../jin_configuration.h"
#if LIBJIN_MODULES_RENDER
#include "../utils/macros.h"
@@ -26,36 +26,26 @@ namespace graphics
Canvas::Canvas(int w, int h)
: Drawable(w, h)
{
- vertCoord[0] = 0; vertCoord[1] = 0;
- vertCoord[2] = 0; vertCoord[3] = h;
- vertCoord[4] = w; vertCoord[5] = h;
- vertCoord[6] = w; vertCoord[7] = 0;
-
- textCoord[0] = 0; textCoord[1] = 1;
- textCoord[2] = 0; textCoord[3] = 0;
- textCoord[4] = 1; textCoord[5] = 0;
- textCoord[6] = 1; textCoord[7] = 1;
-
GLint current_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
/* generate a new render buffer object */
- glGenFramebuffers(1, &fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ fbo = gl.genFrameBuffer();
+ gl.bindFrameBuffer(fbo);
/* generate texture save target */
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
+ texture = gl.genTexture();
+ gl.bindTexture(texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
+ gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ gl.bindTexture(0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
/* unbind framebuffer */
- glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
+ gl.bindFrameBuffer(current_fbo);
}
Canvas::~Canvas()
@@ -74,25 +64,12 @@ namespace graphics
{
if (isBinded(canvas)) return;
current = canvas;
- glBindFramebuffer(GL_FRAMEBUFFER, canvas->fbo);
-
+ gl.bindFrameBuffer(canvas->fbo);
int w = canvas->size.w;
int h = canvas->size.h;
/* set view port to canvas */
glViewport(0, 0, w, h);
-
- /* set projection matrix */
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(0, w, h, 0, -1, 1);
-
- /* set (model*view) matrix */
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- /* ready to draw */
+ gl.ProjectionMatrix.setOrtho(0, w, 0, h, -1, 1);
}
/**
@@ -107,25 +84,16 @@ namespace graphics
current = DEFAULT_CANVAS;
/* get window size as viewport */
Window* wnd = Window::get();
- int ww = wnd->getW();
- int wh = wnd->getH();
+ int w = wnd->getW();
+ int h = wnd->getH();
glBindFramebuffer(GL_FRAMEBUFFER, DEFAULT_CANVAS->fbo);
- glViewport(0, 0, ww, wh);
-
- /* set projection matrix */
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(0, ww, wh, 0, -1, 1);
-
- /* set (model*view) matrix */
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- /* ready to draw */
+ /* set viewport on screen */
+ glViewport(0, 0, w, h);
+
+ gl.ProjectionMatrix.setOrtho(0, w, h, 0, -1, 1);
+
}
} // render