aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-25 11:28:59 +0800
committerchai <chaifix@163.com>2018-11-25 11:28:59 +0800
commit25b394738f08bc2e7b23f8343096f8296b46c633 (patch)
tree886a81c260b7381e0355c077ef780d7e93200de1
parent89a7d8e2923776e59130b4d5c5e5f82ed425e828 (diff)
*gl
-rw-r--r--src/libjin/graphics/je_gl.cpp68
-rw-r--r--src/libjin/graphics/je_gl.h99
-rw-r--r--src/libjin/graphics/je_renderable.h18
-rw-r--r--src/libjin/graphics/je_sprite.cpp18
-rw-r--r--src/libjin/graphics/je_sprite_sheet.h2
5 files changed, 117 insertions, 88 deletions
diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp
index 68678e2..745bbb2 100644
--- a/src/libjin/graphics/je_gl.cpp
+++ b/src/libjin/graphics/je_gl.cpp
@@ -37,6 +37,21 @@ namespace JinEngine
glColor4ub(r, g, b, a);
}
+ void OpenGL::enable(GLenum cap)
+ {
+ glEnable(cap);
+ }
+
+ void OpenGL::disable(GLenum cap)
+ {
+ glDisable(cap);
+ }
+
+ void OpenGL::setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
+ {
+ glClearColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
+ }
+
void OpenGL::popColor()
{
memcpy(&mColor, &mPrecolor, sizeof(mPrecolor));
@@ -60,6 +75,11 @@ namespace JinEngine
glBindTexture(GL_TEXTURE_2D, texture);
}
+ GLuint OpenGL::curTexture()
+ {
+ return mTexture;
+ }
+
void OpenGL::deleteTexture(GLuint texture)
{
glDeleteTextures(1, &texture);
@@ -86,6 +106,54 @@ namespace JinEngine
glActiveTexture(GL_TEXTURE0 + unit);
}
+
+ void OpenGL::drawArrays(GLenum mode, GLint first, GLsizei count)
+ {
+ glDrawArrays(mode, first, count);
+ }
+
+ void OpenGL::drawBuffer(GLenum mode)
+ {
+
+ }
+
+ void OpenGL::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
+ {
+
+ }
+
+ void OpenGL::enableClientState(GLenum arr)
+ {
+ glEnableClientState(arr);
+ }
+
+ void OpenGL::disableClientState(GLenum arr)
+ {
+ glDisableClientState(arr);
+ }
+
+ GLuint OpenGL::genFrameBuffer()
+ {
+ GLuint fbo;
+ glGenFramebuffers(1, &fbo);
+ return fbo;
+ }
+
+ void OpenGL::bindFrameBuffer(GLuint fbo)
+ {
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ }
+
+ void OpenGL::ortho(int w, float radio)
+ {
+ glOrtho(0, w, w*radio, 0, -1, 1);
+ }
+
+ void OpenGL::orthox(int w, int h)
+ {
+ glOrtho(0, w, h, 0, -1, 1);
+ }
+
void OpenGL::setColor(Channel r, Channel g, Channel b, Channel a)
{
setColor(Color(r, g, b, a));
diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h
index 60b2396..4f53152 100644
--- a/src/libjin/graphics/je_gl.h
+++ b/src/libjin/graphics/je_gl.h
@@ -14,13 +14,11 @@ namespace JinEngine
{
namespace Graphics
{
-
// Wrap OpenGL API.
-/*
+
+ namespace Shaders { class Shader; };
+ namespace Fonts { class Font; };
class Canvas;
- class Shader;
- class Font;
-*/
class OpenGL
{
@@ -40,87 +38,51 @@ namespace JinEngine
OpenGL();
~OpenGL();
- inline void enable(GLenum cap)
- {
- glEnable(cap);
- }
+ void enable(GLenum cap);
- inline void disable(GLenum cap)
- {
- glDisable(cap);
- }
-/*
- inline void setBlendFunc(GLenum sfactor, GLenum dfactor)
- {
- glBlendFunc(sfactor, dfactor);
- }
-*/
- inline void setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
- {
- glClearColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
- }
+ void disable(GLenum cap);
+
+ void setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
void pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255);
+
void popColor();
+
void flushError();
+
GLuint genTexture();
+
void deleteTexture(GLuint texture);
+
void bindTexture(GLuint texture = 0);
- inline GLuint curTexture()
- {
- return mTexture;
- }
+
+ GLuint curTexture();
+
void setTexParameter(GLenum pname, GLint param);
+
void texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels = NULL);
+
void texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+
void activeTexUnit(unsigned int unit = 0);
- inline void drawArrays(GLenum mode, GLint first, GLsizei count)
- {
- glDrawArrays(mode, first, count);
- }
+ void drawArrays(GLenum mode, GLint first, GLsizei count);
- inline void drawBuffer(GLenum mode)
- {
+ void drawBuffer(GLenum mode);
- }
+ void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
- inline void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
- {
-
- }
+ void enableClientState(GLenum arr);
- inline void enableClientState(GLenum arr)
- {
- glEnableClientState(arr);
- }
-
- inline void disableClientState(GLenum arr)
- {
- glDisableClientState(arr);
- }
+ void disableClientState(GLenum arr);
- inline GLuint genFrameBuffer()
- {
- GLuint fbo;
- glGenFramebuffers(1, &fbo);
- return fbo;
- }
+ GLuint genFrameBuffer();
- inline void bindFrameBuffer(GLuint fbo)
- {
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- }
+ void bindFrameBuffer(GLuint fbo);
- inline void ortho(int w, float radio)
- {
- glOrtho(0, w, w*radio, 0, -1, 1);
- }
+ void ortho(int w, float radio);
- inline void orthox(int w, int h)
- {
- glOrtho(0, w, h, 0, -1, 1);
- }
+ void orthox(int w, int h);
void setColor(Channel r, Channel g, Channel b, Channel a);
@@ -226,7 +188,6 @@ namespace JinEngine
struct { GLubyte r, g, b, a; } mPrecolor; // previous draw color
GLuint mTexture; // current binded texture
-/*
///
///
///
@@ -235,13 +196,13 @@ namespace JinEngine
///
///
///
- Shader* mCurrentShader;
+ Shaders::Shader* mCurrentShader;
///
///
///
- Font* mCurrentFont;
-*/
+ Fonts::Font* mCurrentFont;
+
};
// Singleton.
diff --git a/src/libjin/graphics/je_renderable.h b/src/libjin/graphics/je_renderable.h
index e1d0ae8..ca785c3 100644
--- a/src/libjin/graphics/je_renderable.h
+++ b/src/libjin/graphics/je_renderable.h
@@ -8,15 +8,15 @@ namespace JinEngine
enum class Origin
{
- TopLeft,
- TopCenter,
- TopRight,
- MiddleLeft,
- MiddleCenter,
- MiddleRight,
- BottomLeft,
- BottomCenter,
- BottomRight
+ TOPLEFT,
+ TOPCENTER,
+ TOPRIGHT,
+ MIDDLELEFT,
+ MIDDLECENTER,
+ MIDDLERIGHT,
+ BOTTOMLEFT,
+ BOTTOMCENTER,
+ BOTTOMRIGHT
};
class IRenderable
diff --git a/src/libjin/graphics/je_sprite.cpp b/src/libjin/graphics/je_sprite.cpp
index 890dc63..789fd26 100644
--- a/src/libjin/graphics/je_sprite.cpp
+++ b/src/libjin/graphics/je_sprite.cpp
@@ -61,31 +61,31 @@ namespace JinEngine
Vector2<float>* org = const_cast<Vector2<float>*>(&mOrigin);
switch (origin)
{
- case Origin::TopLeft:
+ case Origin::TOPLEFT:
org->set(l, t);
break;
- case Origin::TopCenter:
+ case Origin::TOPCENTER:
org->set(r / 2.f, t);
break;
- case Origin::TopRight:
+ case Origin::TOPRIGHT:
org->set(r, t);
break;
- case Origin::MiddleLeft:
+ case Origin::MIDDLELEFT:
org->set(l, b / 2.f);
break;
- case Origin::MiddleCenter:
+ case Origin::MIDDLECENTER:
org->set(r / 2.f, b / 2.f);
break;
- case Origin::MiddleRight:
+ case Origin::MIDDLERIGHT:
org->set(r, b / 2.f);
break;
- case Origin::BottomLeft:
+ case Origin::BOTTOMLEFT:
org->set(l, b);
break;
- case Origin::BottomCenter:
+ case Origin::BOTTOMCENTER:
org->set(r / 2.f, b);
break;
- case Origin::BottomRight:
+ case Origin::BOTTOMRIGHT:
org->set(r, b);
break;
}
diff --git a/src/libjin/graphics/je_sprite_sheet.h b/src/libjin/graphics/je_sprite_sheet.h
index 57e31f7..8fee3f1 100644
--- a/src/libjin/graphics/je_sprite_sheet.h
+++ b/src/libjin/graphics/je_sprite_sheet.h
@@ -28,7 +28,7 @@ namespace JinEngine
///
///
///
- std::vector<Sprite*> createSprites(uint count, uint row, uint colum, uint w, uint h, Origin origin = Origin::TopLeft, uint offx = 0, uint offy = 0);
+ std::vector<Sprite*> createSprites(uint count, uint row, uint colum, uint w, uint h, Origin origin = Origin::TOPLEFT, uint offx = 0, uint offy = 0);
std::vector<Sprite*> createSprites(uint count, uint row, uint colum, uint w, uint h, float ox = 0, float oy = 0, uint offx = 0, uint offy = 0);