diff options
author | chai <chaifix@163.com> | 2018-10-05 15:40:31 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-05 15:40:31 +0800 |
commit | 789895b4b9f99668b8b772f271d07d1ce3115742 (patch) | |
tree | 3ae85381358445b2c29c9a0afb59375de9a7ce66 /src | |
parent | 846d6ab0ec1033481574e8324a43fc547ecf5882 (diff) |
*update
Diffstat (limited to 'src')
89 files changed, 2008 insertions, 694 deletions
diff --git a/src/libjin/3rdparty/ogl/OpenGL.h b/src/libjin/3rdparty/ogl/OpenGL.h new file mode 100644 index 0000000..33b14d2 --- /dev/null +++ b/src/libjin/3rdparty/ogl/OpenGL.h @@ -0,0 +1,529 @@ +#ifndef __OGL2D_H +#define __OGL2D_H +#include <vector> + +/* include gl.h before this file */ +namespace ogl2d +{ + /* 2d wrap of opengl 3.0 */ + class OpenGL + { + public: + OpenGL(); + ~OpenGL(); + + inline void enable(GLenum cap) + { + glEnable(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 pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255); + void popColor(); + void flushError(); + GLuint genTexture(); + void bindTexture(GLuint texture = 0); + inline GLuint curTexture() + { + return _texture; + } + 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 vertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) + { + glVertexPointer(size, type, stride, pointer); + } + + inline void texCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) + { + glTexCoordPointer(size, type, stride, pointer); + } + + inline void drawArrays(GLenum mode, GLint first, GLsizei count) + { + glDrawArrays(mode, first, count); + } + + inline void drawBuffer(GLenum mode) + { + + } + + inline void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) + { + + } + + inline void enableClientState(GLenum arr) + { + glEnableClientState(arr); + } + + inline void disableClientState(GLenum arr) + { + glDisableClientState(arr); + } + + inline GLuint genFrameBuffer() + { + GLuint fbo; + glGenFramebuffers(1, &fbo); + return fbo; + } + + inline void bindFrameBuffer(GLuint fbo) + { + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + } + + // Ļһ + inline void ortho(int w, float radio) + { + glOrtho(0, w, w*radio, 0, -1, 1); + } + + inline void orthox(int w, int h) + { + glOrtho(0, w, h, 0, -1, 1); + } + + protected: + struct { GLubyte r, g, b, a; } _color; // current draw color + struct { GLubyte r, g, b, a; } _precolor; // previous draw color + GLuint _texture; // current binded texture + + }; + + ///* OpenGL instance singleton */ + extern OpenGL gl; + +#if defined(OGL2D_IMPLEMENT) + + OpenGL gl; + + OpenGL::OpenGL() + { + memset(&_color, 0xff, sizeof(_color)); + memset(&_precolor, 0xff, sizeof(_precolor)); + } + + OpenGL::~OpenGL() + { + } + + void OpenGL::pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { + memcpy(&_precolor, &_color, sizeof(_precolor)); + _color.r = r; + _color.g = g; + _color.b = b; + _color.a = a; + glColor4ub(r, g, b, a); + } + + void OpenGL::popColor() + { + memcpy(&_color, &_precolor, sizeof(_precolor)); + glColor4ub(_color.r, _color.g, _color.b, _color.a); + } + + void OpenGL::flushError() + { + while (glGetError() != GL_NO_ERROR); + } + + GLuint OpenGL::genTexture() + { + GLuint t; + glGenTextures(1, &t); + return t; + } + + void OpenGL::bindTexture(GLuint texture) + { + glBindTexture(GL_TEXTURE_2D, texture); + } + + void OpenGL::setTexParameter(GLenum pname, GLint param) + { + glTexParameteri(GL_TEXTURE_2D, pname, param); + } + + void OpenGL::texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) + { + glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, pixels); + } + + void OpenGL::texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, format, type, pixels); + } + + void OpenGL::activeTexUnit(unsigned int unit) + { + // glActiveTexture selects which texture unit subsequent texture state calls will affect. + glActiveTexture(GL_TEXTURE0 + unit); + } + +#endif // OGL2D_IMPLEMENT +} + +#endif + + +/* GL.h + +WINGDIAPI void APIENTRY glAccum(GLenum op, GLfloat value); +WINGDIAPI void APIENTRY glAlphaFunc(GLenum func, GLclampf ref); +WINGDIAPI GLboolean APIENTRY glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences); +WINGDIAPI void APIENTRY glArrayElement(GLint i); +WINGDIAPI void APIENTRY glBegin(GLenum mode); +WINGDIAPI void APIENTRY glBindTexture(GLenum target, GLuint texture); +WINGDIAPI void APIENTRY glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap); +WINGDIAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor); +WINGDIAPI void APIENTRY glCallList(GLuint list); +WINGDIAPI void APIENTRY glCallLists(GLsizei n, GLenum type, const GLvoid *lists); +WINGDIAPI void APIENTRY glClear(GLbitfield mask); +WINGDIAPI void APIENTRY glClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +WINGDIAPI void APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +WINGDIAPI void APIENTRY glClearDepth(GLclampd depth); +WINGDIAPI void APIENTRY glClearIndex(GLfloat c); +WINGDIAPI void APIENTRY glClearStencil(GLint s); +WINGDIAPI void APIENTRY glClipPlane(GLenum plane, const GLdouble *equation); +WINGDIAPI void APIENTRY glColor3b(GLbyte red, GLbyte green, GLbyte blue); +WINGDIAPI void APIENTRY glColor3bv(const GLbyte *v); +WINGDIAPI void APIENTRY glColor3d(GLdouble red, GLdouble green, GLdouble blue); +WINGDIAPI void APIENTRY glColor3dv(const GLdouble *v); +WINGDIAPI void APIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue); +WINGDIAPI void APIENTRY glColor3fv(const GLfloat *v); +WINGDIAPI void APIENTRY glColor3i(GLint red, GLint green, GLint blue); +WINGDIAPI void APIENTRY glColor3iv(const GLint *v); +WINGDIAPI void APIENTRY glColor3s(GLshort red, GLshort green, GLshort blue); +WINGDIAPI void APIENTRY glColor3sv(const GLshort *v); +WINGDIAPI void APIENTRY glColor3ub(GLubyte red, GLubyte green, GLubyte blue); +WINGDIAPI void APIENTRY glColor3ubv(const GLubyte *v); +WINGDIAPI void APIENTRY glColor3ui(GLuint red, GLuint green, GLuint blue); +WINGDIAPI void APIENTRY glColor3uiv(const GLuint *v); +WINGDIAPI void APIENTRY glColor3us(GLushort red, GLushort green, GLushort blue); +WINGDIAPI void APIENTRY glColor3usv(const GLushort *v); +WINGDIAPI void APIENTRY glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); +WINGDIAPI void APIENTRY glColor4bv(const GLbyte *v); +WINGDIAPI void APIENTRY glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); +WINGDIAPI void APIENTRY glColor4dv(const GLdouble *v); +WINGDIAPI void APIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +WINGDIAPI void APIENTRY glColor4fv(const GLfloat *v); +WINGDIAPI void APIENTRY glColor4i(GLint red, GLint green, GLint blue, GLint alpha); +WINGDIAPI void APIENTRY glColor4iv(const GLint *v); +WINGDIAPI void APIENTRY glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha); +WINGDIAPI void APIENTRY glColor4sv(const GLshort *v); +WINGDIAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +WINGDIAPI void APIENTRY glColor4ubv(const GLubyte *v); +WINGDIAPI void APIENTRY glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha); +WINGDIAPI void APIENTRY glColor4uiv(const GLuint *v); +WINGDIAPI void APIENTRY glColor4us(GLushort red, GLushort green, GLushort blue, GLushort alpha); +WINGDIAPI void APIENTRY glColor4usv(const GLushort *v); +WINGDIAPI void APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +WINGDIAPI void APIENTRY glColorMaterial(GLenum face, GLenum mode); +WINGDIAPI void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); +WINGDIAPI void APIENTRY glCopyTexImage1D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); +WINGDIAPI void APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +WINGDIAPI void APIENTRY glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +WINGDIAPI void APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +WINGDIAPI void APIENTRY glCullFace(GLenum mode); +WINGDIAPI void APIENTRY glDeleteLists(GLuint list, GLsizei range); +WINGDIAPI void APIENTRY glDeleteTextures(GLsizei n, const GLuint *textures); +WINGDIAPI void APIENTRY glDepthFunc(GLenum func); +WINGDIAPI void APIENTRY glDepthMask(GLboolean flag); +WINGDIAPI void APIENTRY glDepthRange(GLclampd zNear, GLclampd zFar); +WINGDIAPI void APIENTRY glDisable(GLenum cap); +WINGDIAPI void APIENTRY glDisableClientState(GLenum array); +WINGDIAPI void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count); +WINGDIAPI void APIENTRY glDrawBuffer(GLenum mode); +WINGDIAPI void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +WINGDIAPI void APIENTRY glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glEdgeFlag(GLboolean flag); +WINGDIAPI void APIENTRY glEdgeFlagPointer(GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glEdgeFlagv(const GLboolean *flag); +WINGDIAPI void APIENTRY glEnable(GLenum cap); +WINGDIAPI void APIENTRY glEnableClientState(GLenum array); +WINGDIAPI void APIENTRY glEnd(void); +WINGDIAPI void APIENTRY glEndList(void); +WINGDIAPI void APIENTRY glEvalCoord1d(GLdouble u); +WINGDIAPI void APIENTRY glEvalCoord1dv(const GLdouble *u); +WINGDIAPI void APIENTRY glEvalCoord1f(GLfloat u); +WINGDIAPI void APIENTRY glEvalCoord1fv(const GLfloat *u); +WINGDIAPI void APIENTRY glEvalCoord2d(GLdouble u, GLdouble v); +WINGDIAPI void APIENTRY glEvalCoord2dv(const GLdouble *u); +WINGDIAPI void APIENTRY glEvalCoord2f(GLfloat u, GLfloat v); +WINGDIAPI void APIENTRY glEvalCoord2fv(const GLfloat *u); +WINGDIAPI void APIENTRY glEvalMesh1(GLenum mode, GLint i1, GLint i2); +WINGDIAPI void APIENTRY glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); +WINGDIAPI void APIENTRY glEvalPoint1(GLint i); +WINGDIAPI void APIENTRY glEvalPoint2(GLint i, GLint j); +WINGDIAPI void APIENTRY glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer); +WINGDIAPI void APIENTRY glFinish(void); +WINGDIAPI void APIENTRY glFlush(void); +WINGDIAPI void APIENTRY glFogf(GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glFogfv(GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glFogi(GLenum pname, GLint param); +WINGDIAPI void APIENTRY glFogiv(GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glFrontFace(GLenum mode); +WINGDIAPI void APIENTRY glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +WINGDIAPI GLuint APIENTRY glGenLists(GLsizei range); +WINGDIAPI void APIENTRY glGenTextures(GLsizei n, GLuint *textures); +WINGDIAPI void APIENTRY glGetBooleanv(GLenum pname, GLboolean *params); +WINGDIAPI void APIENTRY glGetClipPlane(GLenum plane, GLdouble *equation); +WINGDIAPI void APIENTRY glGetDoublev(GLenum pname, GLdouble *params); +WINGDIAPI GLenum APIENTRY glGetError(void); +WINGDIAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetIntegerv(GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetLightfv(GLenum light, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetLightiv(GLenum light, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetMapdv(GLenum target, GLenum query, GLdouble *v); +WINGDIAPI void APIENTRY glGetMapfv(GLenum target, GLenum query, GLfloat *v); +WINGDIAPI void APIENTRY glGetMapiv(GLenum target, GLenum query, GLint *v); +WINGDIAPI void APIENTRY glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetMaterialiv(GLenum face, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetPixelMapfv(GLenum map, GLfloat *values); +WINGDIAPI void APIENTRY glGetPixelMapuiv(GLenum map, GLuint *values); +WINGDIAPI void APIENTRY glGetPixelMapusv(GLenum map, GLushort *values); +WINGDIAPI void APIENTRY glGetPointerv(GLenum pname, GLvoid* *params); +WINGDIAPI void APIENTRY glGetPolygonStipple(GLubyte *mask); +WINGDIAPI const GLubyte * APIENTRY glGetString(GLenum name); +WINGDIAPI void APIENTRY glGetTexEnvfv(GLenum target, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexEnviv(GLenum target, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetTexGendv(GLenum coord, GLenum pname, GLdouble *params); +WINGDIAPI void APIENTRY glGetTexGenfv(GLenum coord, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexGeniv(GLenum coord, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +WINGDIAPI void APIENTRY glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glHint(GLenum target, GLenum mode); +WINGDIAPI void APIENTRY glIndexMask(GLuint mask); +WINGDIAPI void APIENTRY glIndexPointer(GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glIndexd(GLdouble c); +WINGDIAPI void APIENTRY glIndexdv(const GLdouble *c); +WINGDIAPI void APIENTRY glIndexf(GLfloat c); +WINGDIAPI void APIENTRY glIndexfv(const GLfloat *c); +WINGDIAPI void APIENTRY glIndexi(GLint c); +WINGDIAPI void APIENTRY glIndexiv(const GLint *c); +WINGDIAPI void APIENTRY glIndexs(GLshort c); +WINGDIAPI void APIENTRY glIndexsv(const GLshort *c); +WINGDIAPI void APIENTRY glIndexub(GLubyte c); +WINGDIAPI void APIENTRY glIndexubv(const GLubyte *c); +WINGDIAPI void APIENTRY glInitNames(void); +WINGDIAPI void APIENTRY glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer); +WINGDIAPI GLboolean APIENTRY glIsEnabled(GLenum cap); +WINGDIAPI GLboolean APIENTRY glIsList(GLuint list); +WINGDIAPI GLboolean APIENTRY glIsTexture(GLuint texture); +WINGDIAPI void APIENTRY glLightModelf(GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glLightModelfv(GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glLightModeli(GLenum pname, GLint param); +WINGDIAPI void APIENTRY glLightModeliv(GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glLightf(GLenum light, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glLighti(GLenum light, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glLightiv(GLenum light, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glLineStipple(GLint factor, GLushort pattern); +WINGDIAPI void APIENTRY glLineWidth(GLfloat width); +WINGDIAPI void APIENTRY glListBase(GLuint base); +WINGDIAPI void APIENTRY glLoadIdentity(void); +WINGDIAPI void APIENTRY glLoadMatrixd(const GLdouble *m); +WINGDIAPI void APIENTRY glLoadMatrixf(const GLfloat *m); +WINGDIAPI void APIENTRY glLoadName(GLuint name); +WINGDIAPI void APIENTRY glLogicOp(GLenum opcode); +WINGDIAPI void APIENTRY glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +WINGDIAPI void APIENTRY glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +WINGDIAPI void APIENTRY glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +WINGDIAPI void APIENTRY glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +WINGDIAPI void APIENTRY glMapGrid1d(GLint un, GLdouble u1, GLdouble u2); +WINGDIAPI void APIENTRY glMapGrid1f(GLint un, GLfloat u1, GLfloat u2); +WINGDIAPI void APIENTRY glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); +WINGDIAPI void APIENTRY glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); +WINGDIAPI void APIENTRY glMaterialf(GLenum face, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glMaterialfv(GLenum face, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glMateriali(GLenum face, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glMaterialiv(GLenum face, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glMatrixMode(GLenum mode); +WINGDIAPI void APIENTRY glMultMatrixd(const GLdouble *m); +WINGDIAPI void APIENTRY glMultMatrixf(const GLfloat *m); +WINGDIAPI void APIENTRY glNewList(GLuint list, GLenum mode); +WINGDIAPI void APIENTRY glNormal3b(GLbyte nx, GLbyte ny, GLbyte nz); +WINGDIAPI void APIENTRY glNormal3bv(const GLbyte *v); +WINGDIAPI void APIENTRY glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz); +WINGDIAPI void APIENTRY glNormal3dv(const GLdouble *v); +WINGDIAPI void APIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); +WINGDIAPI void APIENTRY glNormal3fv(const GLfloat *v); +WINGDIAPI void APIENTRY glNormal3i(GLint nx, GLint ny, GLint nz); +WINGDIAPI void APIENTRY glNormal3iv(const GLint *v); +WINGDIAPI void APIENTRY glNormal3s(GLshort nx, GLshort ny, GLshort nz); +WINGDIAPI void APIENTRY glNormal3sv(const GLshort *v); +WINGDIAPI void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +WINGDIAPI void APIENTRY glPassThrough(GLfloat token); +WINGDIAPI void APIENTRY glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values); +WINGDIAPI void APIENTRY glPixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values); +WINGDIAPI void APIENTRY glPixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values); +WINGDIAPI void APIENTRY glPixelStoref(GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glPixelStorei(GLenum pname, GLint param); +WINGDIAPI void APIENTRY glPixelTransferf(GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glPixelTransferi(GLenum pname, GLint param); +WINGDIAPI void APIENTRY glPixelZoom(GLfloat xfactor, GLfloat yfactor); +WINGDIAPI void APIENTRY glPointSize(GLfloat size); +WINGDIAPI void APIENTRY glPolygonMode(GLenum face, GLenum mode); +WINGDIAPI void APIENTRY glPolygonOffset(GLfloat factor, GLfloat units); +WINGDIAPI void APIENTRY glPolygonStipple(const GLubyte *mask); +WINGDIAPI void APIENTRY glPopAttrib(void); +WINGDIAPI void APIENTRY glPopClientAttrib(void); +WINGDIAPI void APIENTRY glPopMatrix(void); +WINGDIAPI void APIENTRY glPopName(void); +WINGDIAPI void APIENTRY glPrioritizeTextures(GLsizei n, const GLuint *textures, const GLclampf *priorities); +WINGDIAPI void APIENTRY glPushAttrib(GLbitfield mask); +WINGDIAPI void APIENTRY glPushClientAttrib(GLbitfield mask); +WINGDIAPI void APIENTRY glPushMatrix(void); +WINGDIAPI void APIENTRY glPushName(GLuint name); +WINGDIAPI void APIENTRY glRasterPos2d(GLdouble x, GLdouble y); +WINGDIAPI void APIENTRY glRasterPos2dv(const GLdouble *v); +WINGDIAPI void APIENTRY glRasterPos2f(GLfloat x, GLfloat y); +WINGDIAPI void APIENTRY glRasterPos2fv(const GLfloat *v); +WINGDIAPI void APIENTRY glRasterPos2i(GLint x, GLint y); +WINGDIAPI void APIENTRY glRasterPos2iv(const GLint *v); +WINGDIAPI void APIENTRY glRasterPos2s(GLshort x, GLshort y); +WINGDIAPI void APIENTRY glRasterPos2sv(const GLshort *v); +WINGDIAPI void APIENTRY glRasterPos3d(GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glRasterPos3dv(const GLdouble *v); +WINGDIAPI void APIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glRasterPos3fv(const GLfloat *v); +WINGDIAPI void APIENTRY glRasterPos3i(GLint x, GLint y, GLint z); +WINGDIAPI void APIENTRY glRasterPos3iv(const GLint *v); +WINGDIAPI void APIENTRY glRasterPos3s(GLshort x, GLshort y, GLshort z); +WINGDIAPI void APIENTRY glRasterPos3sv(const GLshort *v); +WINGDIAPI void APIENTRY glRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w); +WINGDIAPI void APIENTRY glRasterPos4dv(const GLdouble *v); +WINGDIAPI void APIENTRY glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); +WINGDIAPI void APIENTRY glRasterPos4fv(const GLfloat *v); +WINGDIAPI void APIENTRY glRasterPos4i(GLint x, GLint y, GLint z, GLint w); +WINGDIAPI void APIENTRY glRasterPos4iv(const GLint *v); +WINGDIAPI void APIENTRY glRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w); +WINGDIAPI void APIENTRY glRasterPos4sv(const GLshort *v); +WINGDIAPI void APIENTRY glReadBuffer(GLenum mode); +WINGDIAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +WINGDIAPI void APIENTRY glRectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); +WINGDIAPI void APIENTRY glRectdv(const GLdouble *v1, const GLdouble *v2); +WINGDIAPI void APIENTRY glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); +WINGDIAPI void APIENTRY glRectfv(const GLfloat *v1, const GLfloat *v2); +WINGDIAPI void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2); +WINGDIAPI void APIENTRY glRectiv(const GLint *v1, const GLint *v2); +WINGDIAPI void APIENTRY glRects(GLshort x1, GLshort y1, GLshort x2, GLshort y2); +WINGDIAPI void APIENTRY glRectsv(const GLshort *v1, const GLshort *v2); +WINGDIAPI GLint APIENTRY glRenderMode(GLenum mode); +WINGDIAPI void APIENTRY glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height); +WINGDIAPI void APIENTRY glSelectBuffer(GLsizei size, GLuint *buffer); +WINGDIAPI void APIENTRY glShadeModel(GLenum mode); +WINGDIAPI void APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask); +WINGDIAPI void APIENTRY glStencilMask(GLuint mask); +WINGDIAPI void APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass); +WINGDIAPI void APIENTRY glTexCoord1d(GLdouble s); +WINGDIAPI void APIENTRY glTexCoord1dv(const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord1f(GLfloat s); +WINGDIAPI void APIENTRY glTexCoord1fv(const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord1i(GLint s); +WINGDIAPI void APIENTRY glTexCoord1iv(const GLint *v); +WINGDIAPI void APIENTRY glTexCoord1s(GLshort s); +WINGDIAPI void APIENTRY glTexCoord1sv(const GLshort *v); +WINGDIAPI void APIENTRY glTexCoord2d(GLdouble s, GLdouble t); +WINGDIAPI void APIENTRY glTexCoord2dv(const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord2f(GLfloat s, GLfloat t); +WINGDIAPI void APIENTRY glTexCoord2fv(const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord2i(GLint s, GLint t); +WINGDIAPI void APIENTRY glTexCoord2iv(const GLint *v); +WINGDIAPI void APIENTRY glTexCoord2s(GLshort s, GLshort t); +WINGDIAPI void APIENTRY glTexCoord2sv(const GLshort *v); +WINGDIAPI void APIENTRY glTexCoord3d(GLdouble s, GLdouble t, GLdouble r); +WINGDIAPI void APIENTRY glTexCoord3dv(const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord3f(GLfloat s, GLfloat t, GLfloat r); +WINGDIAPI void APIENTRY glTexCoord3fv(const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord3i(GLint s, GLint t, GLint r); +WINGDIAPI void APIENTRY glTexCoord3iv(const GLint *v); +WINGDIAPI void APIENTRY glTexCoord3s(GLshort s, GLshort t, GLshort r); +WINGDIAPI void APIENTRY glTexCoord3sv(const GLshort *v); +WINGDIAPI void APIENTRY glTexCoord4d(GLdouble s, GLdouble t, GLdouble r, GLdouble q); +WINGDIAPI void APIENTRY glTexCoord4dv(const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q); +WINGDIAPI void APIENTRY glTexCoord4fv(const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord4i(GLint s, GLint t, GLint r, GLint q); +WINGDIAPI void APIENTRY glTexCoord4iv(const GLint *v); +WINGDIAPI void APIENTRY glTexCoord4s(GLshort s, GLshort t, GLshort r, GLshort q); +WINGDIAPI void APIENTRY glTexCoord4sv(const GLshort *v); +WINGDIAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glTexEnvf(GLenum target, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glTexEnviv(GLenum target, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glTexGend(GLenum coord, GLenum pname, GLdouble param); +WINGDIAPI void APIENTRY glTexGendv(GLenum coord, GLenum pname, const GLdouble *params); +WINGDIAPI void APIENTRY glTexGenf(GLenum coord, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glTexGeni(GLenum coord, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glTexGeniv(GLenum coord, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTranslated(GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glVertex2d(GLdouble x, GLdouble y); +WINGDIAPI void APIENTRY glVertex2dv(const GLdouble *v); +WINGDIAPI void APIENTRY glVertex2f(GLfloat x, GLfloat y); +WINGDIAPI void APIENTRY glVertex2fv(const GLfloat *v); +WINGDIAPI void APIENTRY glVertex2i(GLint x, GLint y); +WINGDIAPI void APIENTRY glVertex2iv(const GLint *v); +WINGDIAPI void APIENTRY glVertex2s(GLshort x, GLshort y); +WINGDIAPI void APIENTRY glVertex2sv(const GLshort *v); +WINGDIAPI void APIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glVertex3dv(const GLdouble *v); +WINGDIAPI void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glVertex3fv(const GLfloat *v); +WINGDIAPI void APIENTRY glVertex3i(GLint x, GLint y, GLint z); +WINGDIAPI void APIENTRY glVertex3iv(const GLint *v); +WINGDIAPI void APIENTRY glVertex3s(GLshort x, GLshort y, GLshort z); +WINGDIAPI void APIENTRY glVertex3sv(const GLshort *v); +WINGDIAPI void APIENTRY glVertex4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w); +WINGDIAPI void APIENTRY glVertex4dv(const GLdouble *v); +WINGDIAPI void APIENTRY glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); +WINGDIAPI void APIENTRY glVertex4fv(const GLfloat *v); +WINGDIAPI void APIENTRY glVertex4i(GLint x, GLint y, GLint z, GLint w); +WINGDIAPI void APIENTRY glVertex4iv(const GLint *v); +WINGDIAPI void APIENTRY glVertex4s(GLshort x, GLshort y, GLshort z, GLshort w); +WINGDIAPI void APIENTRY glVertex4sv(const GLshort *v); +WINGDIAPI void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height); + +*/ diff --git a/src/libjin/Audio/Audio.cpp b/src/libjin/Audio/Audio.cpp index c9a3e40..798269a 100644 --- a/src/libjin/Audio/Audio.cpp +++ b/src/libjin/Audio/Audio.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include "SDL2/SDL.h" diff --git a/src/libjin/Audio/Audio.h b/src/libjin/Audio/Audio.h index 9faf0bc..b9812dd 100644 --- a/src/libjin/Audio/Audio.h +++ b/src/libjin/Audio/Audio.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_AUDIO_H #define __LIBJIN_AUDIO_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include "SDL2/SDL.h" diff --git a/src/libjin/Audio/SDL/SDLAudio.cpp b/src/libjin/Audio/SDL/SDLAudio.cpp index d457dca..9a256b1 100644 --- a/src/libjin/Audio/SDL/SDLAudio.cpp +++ b/src/libjin/Audio/SDL/SDLAudio.cpp @@ -1,4 +1,4 @@ -#include "../../modules.h" +#include "../../jin_configuration.h" #if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO #include <iostream> diff --git a/src/libjin/Audio/SDL/SDLAudio.h b/src/libjin/Audio/SDL/SDLAudio.h index 97ed664..db232b7 100644 --- a/src/libjin/Audio/SDL/SDLAudio.h +++ b/src/libjin/Audio/SDL/SDLAudio.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_AUDIO_SDL_H #define __LIBJIN_AUDIO_SDL_H -#include "../../modules.h" +#include "../../jin_configuration.h" #if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO #include "SDLSource.h" diff --git a/src/libjin/Audio/SDL/SDLSource.cpp b/src/libjin/Audio/SDL/SDLSource.cpp index 00193a4..251ef27 100644 --- a/src/libjin/Audio/SDL/SDLSource.cpp +++ b/src/libjin/Audio/SDL/SDLSource.cpp @@ -1,4 +1,4 @@ -#include "../../modules.h" +#include "../../jin_configuration.h" #if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO #include <exception> diff --git a/src/libjin/Audio/SDL/SDLSource.h b/src/libjin/Audio/SDL/SDLSource.h index 7e407ee..3feef9f 100644 --- a/src/libjin/Audio/SDL/SDLSource.h +++ b/src/libjin/Audio/SDL/SDLSource.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_SOURCE_SDL_H #define __LIBJIN_SOURCE_SDL_H -#include "../../modules.h" +#include "../../jin_configuration.h" #if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO #include <vector> @@ -64,7 +64,7 @@ namespace audio int pitch; // pitch int state; // ǰ״̬ bool loop; // loop or not - float volume; // + float volume; // } status; }; diff --git a/src/libjin/Audio/Source.cpp b/src/libjin/Audio/Source.cpp index 7ac4e60..1dcd482 100644 --- a/src/libjin/Audio/Source.cpp +++ b/src/libjin/Audio/Source.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include <cstring> diff --git a/src/libjin/Audio/Source.h b/src/libjin/Audio/Source.h index b227db2..e1ca6d0 100644 --- a/src/libjin/Audio/Source.h +++ b/src/libjin/Audio/Source.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_AUDIO_SOURCE_H #define __LIBJIN_AUDIO_SOURCE_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include "SDL2/SDL.h" diff --git a/src/libjin/Common/Array.hpp b/src/libjin/Common/Array.hpp index 7c0f058..45082db 100644 --- a/src/libjin/Common/Array.hpp +++ b/src/libjin/Common/Array.hpp @@ -28,7 +28,7 @@ namespace jin return data; } - T operator[](int index) + T& operator[](int index) { return data[index]; } diff --git a/src/libjin/Common/types.h b/src/libjin/Common/types.h new file mode 100644 index 0000000..7e335c0 --- /dev/null +++ b/src/libjin/Common/types.h @@ -0,0 +1,23 @@ +#ifndef __LIBJIN_TYPES_H +#define __LIBJIN_TYPES_H +#include <stdint.h> + +namespace jin +{ +namespace common +{ + + typedef int8_t int8; + typedef uint8_t uint8; + typedef uint8 byte; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; + +} +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Common/utf8.cpp b/src/libjin/Common/utf8.cpp index 8c05da8..f00d03c 100644 --- a/src/libjin/Common/utf8.cpp +++ b/src/libjin/Common/utf8.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_OS == LIBJIN_WINDOWS #include "utf8.h" diff --git a/src/libjin/Common/utf8.h b/src/libjin/Common/utf8.h index 5985684..fd6ce1f 100644 --- a/src/libjin/Common/utf8.h +++ b/src/libjin/Common/utf8.h @@ -1,7 +1,7 @@ #ifndef __LIBJIN_COMMON_UTF8_H #define __LIBJIN_COMMON_UTF8_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_OS == LIBJIN_WINDOWS #include <string> diff --git a/src/libjin/Core/Core.h b/src/libjin/Core/Core.h deleted file mode 100644 index 4b4df8f..0000000 --- a/src/libjin/Core/Core.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __LIBJIN_CORE_H -#define __LIBJIN_CORE_H - -#include "game.h" - -#endif
\ No newline at end of file diff --git a/src/libjin/Core/game.cpp b/src/libjin/Core/game.cpp deleted file mode 100644 index 3f905f2..0000000 --- a/src/libjin/Core/game.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "game.h" -#include "../Time/Timer.h" -#include "../input/Event.h" -#include "../Graphics/Window.h" -#include "../Math/Math.h" -#include <iostream> - -namespace jin -{ -namespace core -{ - - using namespace jin::graphics; - using namespace jin::input; - using namespace jin::time; - using namespace jin::math; - - Game::Game() :_running(true) {}; - - void Game::run() - { - if (_onLoad != nullptr) - _onLoad(); - Window* wnd = Window::get(); - const int FPS = wnd ? wnd->getFPS() : 60; - const int MS_PER_UPDATE = 1000.0f / FPS; - _running = true; - Event e; - int previous = getMilliSecond(); - int dt = MS_PER_UPDATE; - while (_running) - { - while (jin::input::pollEvent(&e)) - { - if (_onEvent != nullptr) - _onEvent(&e); - if (!_running) goto quitloop; - } - if (_onUpdate != nullptr) _onUpdate(dt); - if (_onDraw != nullptr) _onDraw(); - wnd->swapBuffers(); - const int current = getMilliSecond(); - dt = current - previous; - const int wait = MS_PER_UPDATE - (current - previous); - previous += MS_PER_UPDATE; - if (wait > 0) - { - sleep(wait); - dt = MS_PER_UPDATE; - } - else - previous = current; - } - quitloop:; - } - - bool Game::initSystem(const SettingBase* setting) - { - if (setting == nullptr) - return false; - Game::Setting* s = (Game::Setting*) setting; - _onEvent = s->eventHandler; - _onUpdate = s->updater; - _onDraw = s->drawer; - _onLoad = s->loader; - return true; - } - - void Game::quitSystem() - { - } - -} // core -} // jin
\ No newline at end of file diff --git a/src/libjin/Filesystem/Buffer.h b/src/libjin/Filesystem/Buffer.h index 15ea665..5598f66 100644 --- a/src/libjin/Filesystem/Buffer.h +++ b/src/libjin/Filesystem/Buffer.h @@ -2,6 +2,7 @@ #define __LIBJIN_BUFFER_H #include <string.h> +#include <stdlib.h> namespace jin { @@ -47,6 +48,14 @@ namespace filesystem memcpy(data, buffer.data, size); } + void clear() + { + if (data == nullptr) + return; + free(data); + data = nullptr; + } + void* data; unsigned int size; diff --git a/src/libjin/Filesystem/Filesystem.h b/src/libjin/Filesystem/Filesystem.h index ffc0c52..3ae984d 100644 --- a/src/libjin/Filesystem/Filesystem.h +++ b/src/libjin/Filesystem/Filesystem.h @@ -5,7 +5,7 @@ namespace jin { namespace filesystem { - + /* Դ */ class Filesystem { public: diff --git a/src/libjin/Core/Game.cpp b/src/libjin/Game/Game.cpp index 3f905f2..3f905f2 100644 --- a/src/libjin/Core/Game.cpp +++ b/src/libjin/Game/Game.cpp diff --git a/src/libjin/Core/Game.h b/src/libjin/Game/Game.h index 725c62c..725c62c 100644 --- a/src/libjin/Core/Game.h +++ b/src/libjin/Game/Game.h diff --git a/src/libjin/Graphics/Bitmap.h b/src/libjin/Graphics/Bitmap.h index ab84388..af7f376 100644 --- a/src/libjin/Graphics/Bitmap.h +++ b/src/libjin/Graphics/Bitmap.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_BITMAP_H #define __LIBJIN_BITMAP_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "../Math/Vector2.hpp" @@ -16,6 +16,7 @@ namespace graphics public: static Bitmap* createBitmap(const void* imgData, size_t size); static Bitmap* createBitmap(int w, int h, Color color = Color::BLACK); + static void destroyBitmap(Bitmap* bitmap); static Bitmap* clone(const Bitmap* bitmap); ~Bitmap(); @@ -42,8 +43,8 @@ namespace graphics }; -} -} +} // graphics +} // jin #endif #endif
\ No newline at end of file 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, ¤t_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 diff --git a/src/libjin/Graphics/Canvas.h b/src/libjin/Graphics/Canvas.h index a6a52ea..09ae7aa 100644 --- a/src/libjin/Graphics/Canvas.h +++ b/src/libjin/Graphics/Canvas.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_CANVAS_H #define __LIBJIN_CANVAS_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "drawable.h" @@ -29,6 +29,7 @@ namespace graphics GLuint fbo; + }; } // render diff --git a/src/libjin/Graphics/Color.h b/src/libjin/Graphics/Color.h index a5bc5d0..6f9e887 100644 --- a/src/libjin/Graphics/Color.h +++ b/src/libjin/Graphics/Color.h @@ -3,7 +3,7 @@ */ #ifndef __LIBJIN_COLOR_H #define __LIBJIN_COLOR_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "../utils/endian.h" @@ -13,6 +13,8 @@ namespace jin namespace graphics { + typedef unsigned char Channel; + class Color { public: @@ -46,6 +48,14 @@ namespace graphics a = c.a; } + void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a) + { + r = _r; + g = _g; + b = _b; + a = _a; + } + void operator = (const Color& c) { r = c.r; @@ -64,7 +74,7 @@ namespace graphics return !(r == c.r && g == c.g && b == c.b && a == c.a); } - unsigned char r, g, b, a; + Channel r, g, b, a; //#if LIBJIN_BYTEORDER == LIBJIN_BIG_ENDIAN // unsigned char r, g, b, a; diff --git a/src/libjin/Graphics/Drawable.cpp b/src/libjin/Graphics/Drawable.cpp index 675c54d..9f52f0a 100644 --- a/src/libjin/Graphics/Drawable.cpp +++ b/src/libjin/Graphics/Drawable.cpp @@ -1,6 +1,7 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER +#include "Shader.h" #include "drawable.h" #include "../math/matrix.h" #include <stdlib.h> @@ -15,6 +16,15 @@ namespace graphics , size(w, h) , anchor(0, 0) { + vertex_coords[0] = 0; vertex_coords[1] = 0; + vertex_coords[2] = 0; vertex_coords[3] = h; + vertex_coords[4] = w; vertex_coords[5] = h; + vertex_coords[6] = w; vertex_coords[7] = 0; + + texture_coords[0] = 0; texture_coords[1] = 0; + texture_coords[2] = 0; texture_coords[3] = 1; + texture_coords[4] = 1; texture_coords[5] = 1; + texture_coords[6] = 1; texture_coords[7] = 0; } Drawable::~Drawable() @@ -30,31 +40,17 @@ namespace graphics void Drawable::draw(int x, int y, float sx, float sy, float r) { - /* Must set textCoord and vertCoord before renderring */ - if (! textCoord||! vertCoord) return; - - static jin::math::Matrix t; - t.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y); - - glBindTexture(GL_TEXTURE_2D, texture); - - /* push modle matrix */ - glPushMatrix(); - glMultMatrixf((const GLfloat*)t.getElements()); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, textCoord); - glVertexPointer(2, GL_FLOAT, 0, vertCoord); - glDrawArrays(GL_QUADS, 0, 4); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - /* pop the model matrix */ - glPopMatrix(); - - /* bind texture to default screen */ - glBindTexture(GL_TEXTURE_2D, 0); + gl.ModelMatrix.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y); + + Shader* shader = Shader::getCurrentJSL(); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, vertex_coords); + shader->bindUVPointer(2, GL_FLOAT, 0, texture_coords); + + gl.bindTexture(texture); + gl.drawArrays(GL_QUADS, 0, 4); + gl.bindTexture(0); } } // render diff --git a/src/libjin/Graphics/Drawable.h b/src/libjin/Graphics/Drawable.h index ff82365..c77068c 100644 --- a/src/libjin/Graphics/Drawable.h +++ b/src/libjin/Graphics/Drawable.h @@ -1,10 +1,10 @@ #ifndef __LIBJIN_DRAWABLE #define __LIBJIN_DRAWABLE -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "../math/Vector2.hpp" -#include "../3rdparty/GLee/GLee.h" +#include "OpenGL.h" namespace jin { @@ -27,12 +27,13 @@ namespace graphics static const int DRAWABLE_V_SIZE = 8; GLuint texture; + GLuint vbo; /* TODO: vertex buffer object */ /* GLuint vbo; */ jin::math::Vector2<unsigned int> size; jin::math::Vector2<int> anchor; - float vertCoord[DRAWABLE_V_SIZE]; - float textCoord[DRAWABLE_V_SIZE]; + float vertex_coords[DRAWABLE_V_SIZE]; + float texture_coords[DRAWABLE_V_SIZE]; }; diff --git a/src/libjin/Graphics/Font.cpp b/src/libjin/Graphics/Font.cpp index bb767db..a3a46dd 100644 --- a/src/libjin/Graphics/Font.cpp +++ b/src/libjin/Graphics/Font.cpp @@ -1,24 +1,28 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER +#include "OpenGL.h" #include "font.h" #include <stdio.h> -#define STB_TRUETYPE_IMPLEMENTATION -#include "../3rdparty/stb/stb_truetype.h" #include "color.h" +#include "Shader.h" +#include "../Common/Array.hpp" namespace jin { namespace graphics { + #include "Shaders/font.shader.h" + using namespace std; using namespace jin::math; - + const int Font::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 }; const int Font::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 }; - static const char *ttf_utf8toCodepoint(const char *p, unsigned *res) { + /* utf8 byte string to unicode codepoint */ + static const char* utf8toCodepoint(const char *p, unsigned *res) { unsigned x, mask, shift; switch (*p & 0xf0) { case 0xf0: mask = 0x07; shift = 18; break; @@ -31,7 +35,6 @@ namespace graphics } x = (*p & mask) << shift; do { - /* Return early if we reach an unexpected NULL */ if (*(++p) == '\0') { *res = x; return p; @@ -43,80 +46,322 @@ namespace graphics return p + 1; } - /*static*/ Font* Font::createFont(const char* font, size_t size) + /* little endian unicode */ + static const char* unicodeLittleEndian(const char* p, unsigned* res) { } - /*static*/ Font* Font::createFont(const char* file) + /*static*/ Font* Font::createFont(FontData* fontData, unsigned int fontSzie) { - + Font* font; + try + { + font = new Font(fontData, fontSzie); + } + catch (...) + { + return nullptr; + } + return font; } - Font::Font() - : textureLevel(TEXTURE_SIZE_LEVEL_MAX) + void Font::destroyFont(Font* font) + { + if (font != nullptr) + delete font; + } + + Font::Font(FontData* f, unsigned int fontSize) + : cursor(0, 0) + , font(f) + , fontsize(fontSize) { - + font->pushFontsize(fontsize); + font->getVMetrics(&baseline, &descent); + estimateSize(); + font->popFontsize(); + /* create a default texture */ + createAtlas(); } - bool Font::createTexture() + /* estimate the size of atlas texture */ + void Font::estimateSize() { - GLuint t; - glGenTextures(1, &t); - glBindTexture(GL_TEXTURE_2D, t); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - /*Initialize the texture, attempting smaller sizes if initialization fails.*/ - bool initialized = false; - while (textureLevel >= 0) + for (int level = 0; level <= TEXTURE_SIZE_LEVEL_MAX; ++level) { - /*clear errors before initializing*/ - while (glGetError() != GL_NO_ERROR); - textureWidth = TEXTURE_WIDTHS[textureLevel]; - textureHeight = TEXTURE_HEIGHTS[textureLevel]; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - initialized = (glGetError() == GL_NO_ERROR); - if (initialized || textureLevel <= 0) + if (descent * (descent*0.8) * 96 <= TEXTURE_WIDTHS[level] * TEXTURE_HEIGHTS[level]) + { + textureWidth = TEXTURE_WIDTHS[level]; + textureHeight = TEXTURE_HEIGHTS[level]; break; - --textureLevel; + } } - if (!initialized) + } + + Font::~Font() + { + map<unsigned int, Glyph*>::iterator it = glyphs.begin(); + for (; it != glyphs.end(); ++it) + { + delete it->second; + } + } + + GLuint Font::createAtlas() + { + GLuint t; + gl.flushError(); + t = gl.genTexture(); + gl.bindTexture(t); + gl.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl.setTexParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl.setTexParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl.texImage(GL_RGBA8, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE); + if (glGetError() != GL_NO_ERROR) { glDeleteTextures(1, &t); - glBindTexture(GL_TEXTURE_2D, 0); - return false; + gl.bindTexture(0); + return 0; } - textures.push_back(t); - glBindTexture(GL_TEXTURE_2D, 0); - return true; + atlases.push_back(t); + gl.bindTexture(0); + return t; + } + + void Font::print(const char* t, int x, int y, int lineheight, int spacing) + { + Page* page = typeset(t, lineheight, spacing); + print(page, x, y); + delete page; } - void Font::print(const char* text, int x, int y) + Page* Font::typeset(const char* text, int lineheight, int spacing) { - int len = strlen(text); - /* xy and uv list */ - vector<GlyphVertex> glyphvertices(len*4); - /* texture binded along with glyphvertices */ - vector<GlyphArrayDrawInfo> glyphinfolist; - float dx = 0; - float dy = 0; - //float lineheihgt = ; + // typesetting, for reducing draw call + const char* t = text; + Page* page = new Page(); + vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; + vector<GlyphVertex>& glyphvertices = page->glyphvertices; + Vector2<int> p(0, 0); + Codepoint c; + int texture = -1; + Glyph* glyph = nullptr; + GlyphVertex vertex; + for (int i = 0; *t != NULL; i += 4) + { + t = utf8toCodepoint(t, &c); + if (c == 0x0D) + { + i -= 4; + continue; + } + /* new line */ + if (c == 0x0A) + { + p.y += lineheight; + p.x = 0; + i -= 4; + continue; + } + glyph = findGlyph(c); + if (texture != glyph->atlas) + { + GlyphArrayDrawInfo info; + info.start = i; + info.count = 0; + info.texture = glyph->atlas; + texture = glyph->atlas; + glyphinfolist.push_back(info); + } + glyphinfolist[glyphinfolist.size() - 1].count += 4; + Glyph::Bbox& bbox = glyph->bbox; + // 1 + vertex.x = p.x; vertex.y = p.y; + vertex.u = bbox.x; vertex.v = bbox.y; + glyphvertices.push_back(vertex); + // 2 + vertex.x = p.x; vertex.y = p.y + glyph->height; + vertex.u = bbox.x; vertex.v = bbox.y + bbox.height; + glyphvertices.push_back(vertex); + // 3 + vertex.x = p.x + glyph->width; vertex.y = p.y + glyph->height; + vertex.u = bbox.x + bbox.width; vertex.v = bbox.y + bbox.height; + glyphvertices.push_back(vertex); + // 4 + vertex.x = p.x + glyph->width; vertex.y = p.y; + vertex.u = bbox.x + bbox.width; vertex.v = bbox.y; + glyphvertices.push_back(vertex); + + p.x += glyph->width + spacing; + } + getTextBox(text, &page->width, &page->height, lineheight, spacing); + return page; } - /** - * unicodeȾļtextureϣglyphs - */ - Glyph* Font::addGlyph(unsigned int character) + void Font::print(const Page* page, int x, int y) { - GLuint texture = textures.back(); + Shader* shader = Shader::getCurrentJSL(); + const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; + const vector<GlyphVertex>& glyphvertices = page->glyphvertices; + gl.ModelMatrix.setTransformation(x, y, 0, 1, 1, 0, 0); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + for (int i = 0; i < glyphinfolist.size(); ++i) + { + const GlyphArrayDrawInfo& info = glyphinfolist[i]; + shader->bindVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x); + shader->bindUVPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u); + gl.bindTexture(info.texture); + gl.drawArrays(GL_QUADS, 0, info.count); + gl.bindTexture(0); + } + } + int Font::getCharWidth(int c) + { + int adw, lsb; + font->pushFontsize(fontsize); + font->getHMetrics(c, &adw, &lsb); + font->popFontsize(); + return adw; } - Glyph* Font::findGlyph(unsigned int character) + int Font::getCharHeight(int c) + { + return descent; + } + + int Font::getTextWidth(const char* t, int spacing) + { + font->pushFontsize(fontsize); + int res = 0; + int tmp = 0; + const char *p = t; + while (*p) { + unsigned c; + p = utf8toCodepoint(p, &c); + if (*p == 0x0D) + continue; + if (*p == 0x0A) + { + tmp = 0; + continue; + } + tmp += getCharWidth(c) + spacing; + if (tmp > res) res = tmp; + } + font->popFontsize(); + return res; + } + + int Font::getTextHeight(const char* t, int lineheight) + { + font->pushFontsize(fontsize); + int res = 0; + bool newline = true; + while (*t) + { + unsigned c; + t = utf8toCodepoint(t, &c); + if (*t == 0x0A) + newline = true; + else if (*t == 0x0D); + else if (newline) + { + newline = false; + res += lineheight; + } + } + font->popFontsize(); + return res; + } + + void Font::getTextBox(const char* text, int* w, int* h, int lineheight, int spacing) + { + font->pushFontsize(fontsize); + *w = 0; + *h = 0; + int tmp = 0; + const char* p = text; + const char* pt = nullptr; + bool nl = true; + while (*p) { + unsigned c; + pt = p; + p = utf8toCodepoint(p, &c); + if (*pt == 0x0D) + continue; + if (*pt == 0x0A) + { + tmp = 0; + nl = true; + continue; + } + else if(nl) + { + nl = false; + *h += lineheight; + } + tmp += getCharWidth(c) + spacing; + if (tmp > *w) *w = tmp; + } + font->popFontsize(); + } + + Glyph* Font::bakeGlyph(unsigned int character) { + Glyph* glyph = (Glyph*)malloc(sizeof(Glyph)); + int w, h, xoff, yoff; + font->pushFontsize(fontsize); + GLuint atlas = atlases.back(); + const Color* bitmap = font->getCodepointBitmap(character, &w, &h, &xoff, &yoff); + int adw, lsb; + { + font->getHMetrics(character, &adw, &lsb); + font->popFontsize(); + if (cursor.x + adw > textureWidth ) + { + cursor.x = 0; + cursor.y += descent; + if (cursor.y + descent * 2 > textureHeight) + { + /* create new atlas */ + atlas = createAtlas(); + cursor.y = 0; + } + } + gl.bindTexture(atlas); + gl.texSubImage(cursor.x + xoff, cursor.y + yoff + baseline, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bitmap); + gl.bindTexture(); + delete[] bitmap; + } + glyph->atlas = atlas; + glyph->bbox.x = cursor.x / (float)textureWidth; + glyph->bbox.y = cursor.y / (float)textureHeight; + glyph->bbox.width = adw / (float)textureWidth; + glyph->bbox.height = descent / (float)textureHeight; + glyph->width = adw; + glyph->height = descent; + glyphs.insert(std::pair<unsigned int, Glyph*>(character, glyph)); + cursor.x += adw; + return glyph; + } + + Glyph* Font::findGlyph(unsigned int character) + { + map<unsigned int, Glyph*>::iterator it = glyphs.find(character); + if (it != glyphs.end()) + { + return it->second; + } + else + { + Glyph* glyph = bakeGlyph(character); + return glyph; + } } } // graphics diff --git a/src/libjin/Graphics/Font.h b/src/libjin/Graphics/Font.h index 10fd242..2bd51a5 100644 --- a/src/libjin/Graphics/Font.h +++ b/src/libjin/Graphics/Font.h @@ -1,79 +1,100 @@ #ifndef __LIBJIN_FONT_H #define __LIBJIN_FONT_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include <vector> #include <map> #include "drawable.h" -#include "../3rdparty/stb/stb_truetype.h" +#include "FontData.h" #include "../math/quad.h" namespace jin { namespace graphics { - /** - * original from love2d font and graphics modules - * the basic idea is storing glyphs in several mipmap - * http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html - */ - + struct GlyphVertex { - float x, y; // screen coordinates - float u, v; // texture coordinates + int x, y; // screen coordinates + float u, v; // texture uv }; - /* track when to change texutre binded in render array */ - /* casue switch texture is expensive */ - /* std::vector<GlyphVertex> list */ struct GlyphArrayDrawInfo { - GLuint texture; - int startvertex; - int vertexcount; + GLuint texture; // atlas + unsigned int start; // glyph vertex indecies + unsigned int count; // glyph vertex count }; - /* glyph texture */ struct Glyph { - GLuint texture; // texture where this glyph rendered - int spacing; // spacing of glyph - GlyphVertex vertices[4]; // quad of glyph render region + GLuint atlas; + /* normalized coordinates */ + struct Bbox + { + float x, y; + float width, height; + } bbox; + /* glyph size in pixel */ + unsigned int width, height; + }; + + struct Page + { + std::vector<GlyphArrayDrawInfo> glyphinfolist; + std::vector<GlyphVertex> glyphvertices; + int width, height; }; class Font { - public: - static Font* createFont(const char* file); - static Font* createFont(const char* data, size_t size); + public: + typedef unsigned int Codepoint; + + static Font* createFont(FontData* fontData, unsigned int fontSzie); + static void destroyFont(Font* font); - void print(const char* text, int x, int y); + Page* typeset(const char* text, int lineheight, int spacing); + void print(const char* text, int x, int y, int lineheight, int spacing = 0); + void print(const Page* page, int x, int y); + //Bitmap* bake(const char* text); +#if defined(font_debug) + void drawAtlas(); +#endif + ~Font(); private: - /* font atlas levels */ static const int TEXTURE_SIZE_LEVELS_COUNT = 7; static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1; static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT]; static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT]; - static const int SPACES_PER_TAB = 4; - - /* create a new mipmap to render glyph and push it on textures */ - bool createTexture(); - /* create a glyph for a unicode and return it */ - Glyph* addGlyph(unsigned int character); - /* find glyph by unicode */ - Glyph* findGlyph(unsigned int character); - - /* list of textures where glyphs rendered, always operate the last one */ - /* map character to its render area */ - std::vector<GLuint> textures; - std::map<unsigned int, Glyph*> glyphs; - /* mipmap size level */ - int textureLevel; - int textureWidth; + + Font(FontData* font, Codepoint fontSize); + + void estimateSize(); + GLuint createAtlas(); + Glyph* bakeGlyph(Codepoint character); + Glyph* findGlyph(Codepoint character); + + int getCharWidth(int c); + int getCharHeight(int c); + int getTextWidth(const char* text, int spacing = 0); + int getTextHeight(const char* text, int lineheight); + void getTextBox(const char* text, int* w, int* h, int lineheight, int spacing = 0); + + int textureWidth; int textureHeight; + std::vector<GLuint> atlases; + /* map unicode codepoint to glyph */ + std::map<Codepoint, Glyph*> glyphs; + FontData* font; + const unsigned int fontsize; + int baseline; + int descent; + + /* cursor helped render to texture */ + math::Vector2<float> cursor; }; diff --git a/src/libjin/Graphics/FontData.cpp b/src/libjin/Graphics/FontData.cpp new file mode 100644 index 0000000..1b66b12 --- /dev/null +++ b/src/libjin/Graphics/FontData.cpp @@ -0,0 +1,115 @@ +#include "FontData.h" +#define STB_TRUETYPE_IMPLEMENTATION +#include "../3rdparty/stb/stb_truetype.h" +#include <stdio.h> + +namespace jin +{ +namespace graphics +{ + + FontData* FontData::createFontData(const unsigned char* data, unsigned int size) + { + FontData* font = nullptr; + try + { + font = new FontData(data, size); + return font; + } + catch (...) + { + return nullptr; + } + } + + FontData::FontData(const unsigned char* d, unsigned int s) + { + raw.size = s; + raw.data = (unsigned char*)malloc(s); + memcpy(raw.data, d, s); + if (!stbtt_InitFont(&info, (const unsigned char*)raw.data, 0)) + { + delete raw.data; + throw 0; + } + /* push default fontsize */ + pushFontsize(FONT_SIZE); + } + + FontData::~FontData() + { + free(raw.data); + } + + /* + * (0, 0) + * +--------------+ ascent + * | +--------+ | + * | | | | + * | | bitmap | | + * +--|--------|--+ baseline + * | +--------+ | + * +--|-----------+ decent + * | | + * leftSideBearing | + * | + * advanceWidth + */ + void FontData::getVMetrics(int* baseline, int* descent) + { + float scale = scales.back(); + int ascent; + stbtt_GetFontVMetrics(&info, &ascent, descent, 0); + *baseline = (int)(ascent*scale) + 1; // slight adjustment + *descent = *baseline - (int)(*descent*scale) + 1; + } + + void FontData::getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing) + { + float scale = scales.back(); + int adw, lsb; + stbtt_GetCodepointHMetrics(&info, codepoint, &adw, &lsb); + *advanceWidth = (int)(adw*scale); + *leftSideBearing = (int)(lsb*scale); + } + + void FontData::pushFontsize(unsigned int fs) + { + float sc = stbtt_ScaleForPixelHeight(&info, fs); + scales.push_back(sc); + } + + void FontData::popFontsize() + { + /* always keep default font size on the bottom of stack */ + if(scales.size() > 1) + scales.pop_back(); + } + + Channel* FontData::getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const + { + float scale = scales.back(); + Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff); + return bitmap; + } + + Color* FontData::getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const + { + float scale = scales.back(); + Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff); + int w = *width, h = *height; + //int xo = *xoff, yo = *yoff; + Color* bitmap32 = new Color[w*h]; + for (int y = 0; y < h; ++y) + { + for (int x = 0; x < w; ++x) + { + bitmap32[x + y * w].set(0xff, 0xff, 0xff, bitmap[x + y * w]); + } + } + free(bitmap); + return bitmap32; + } + +} +}
\ No newline at end of file diff --git a/src/libjin/Graphics/FontData.h b/src/libjin/Graphics/FontData.h new file mode 100644 index 0000000..c75b9a1 --- /dev/null +++ b/src/libjin/Graphics/FontData.h @@ -0,0 +1,45 @@ +#ifndef __LIBJIN_FONTDATA_H +#define __LIBJIN_FONTDATA_H +#include "../3rdparty/stb/stb_truetype.h" +#include "Color.h" +#include <vector> + +namespace jin +{ +namespace graphics +{ + + class FontData + { + public: + static FontData* createFontData(const unsigned char* data, unsigned int size); + + ~FontData(); + + void pushFontsize(unsigned int fontsize); + void popFontsize(); + + Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const; + Color* getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const; + void getVMetrics(int* baseline, int* descent); + void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing); + + private: + static const unsigned int FONT_SIZE = 12; + + FontData(const unsigned char* data, unsigned int size); + + stbtt_fontinfo info; + struct + { + unsigned char* data; + unsigned int size; + } raw; + std::vector<float> scales; + + }; + +} +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/Graphics.h b/src/libjin/Graphics/Graphics.h index dfd6048..a4bf98b 100644 --- a/src/libjin/Graphics/Graphics.h +++ b/src/libjin/Graphics/Graphics.h @@ -1,11 +1,12 @@ #ifndef __LIBJIN_GRAPHICS_H #define __LIBJIN_GRAPHICS_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "canvas.h" #include "color.h" -#include "font.h" +#include "FontData.h" +#include "Font.h" #include "Shapes.h" #include "texture.h" #include "Shader.h" diff --git a/src/libjin/Graphics/Mesh.cpp b/src/libjin/Graphics/Mesh.cpp new file mode 100644 index 0000000..503a189 --- /dev/null +++ b/src/libjin/Graphics/Mesh.cpp @@ -0,0 +1,11 @@ +#include "Mesh.h" + +namespace jin +{ +namespace graphics +{ + + + +} +}
\ No newline at end of file diff --git a/src/libjin/Graphics/Mesh.h b/src/libjin/Graphics/Mesh.h new file mode 100644 index 0000000..d0bb93e --- /dev/null +++ b/src/libjin/Graphics/Mesh.h @@ -0,0 +1,17 @@ +#ifndef __LIBJIN_MESH_H +#define __LIBJIN_MESH_H + +namespace jin +{ +namespace graphics +{ + + class Mesh + { + + }; + +} +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/OpenGL.cpp b/src/libjin/Graphics/OpenGL.cpp new file mode 100644 index 0000000..f7bed9f --- /dev/null +++ b/src/libjin/Graphics/OpenGL.cpp @@ -0,0 +1,12 @@ +#define OGL2D_IMPLEMENT +#include "OpenGL.h" + +namespace jin +{ +namespace graphics +{ + + OpenGL gl; + +} +} diff --git a/src/libjin/Graphics/OpenGL.h b/src/libjin/Graphics/OpenGL.h new file mode 100644 index 0000000..51395ba --- /dev/null +++ b/src/libjin/Graphics/OpenGL.h @@ -0,0 +1,29 @@ +#ifndef __LIBJIN_OPENGL_H +#define __LIBJIN_OPENGL_H +#include "../3rdparty/GLee/GLee.h" +#include "../3rdparty/ogl/OpenGL.h" +#include "../Math/Matrix.h" + +namespace jin +{ +namespace graphics +{ + + class OpenGL : public ogl2d::OpenGL + { + public: + math::Matrix ProjectionMatrix; + math::Matrix ModelMatrix; + + OpenGL() : ogl2d::OpenGL() + { + } + + }; + + extern OpenGL gl; + +} +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/Shader.cpp b/src/libjin/Graphics/Shader.cpp index e882d35..6c8e3b5 100644 --- a/src/libjin/Graphics/Shader.cpp +++ b/src/libjin/Graphics/Shader.cpp @@ -1,6 +1,9 @@ -#include "../modules.h" +#include <regex> +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER +#include <iostream> + #include "../utils/macros.h" #include "Shader.h" #include "../Filesystem/Buffer.h" @@ -10,6 +13,7 @@ namespace graphics { using namespace jin::filesystem; + using namespace std; /** * default_texture @@ -17,7 +21,14 @@ namespace graphics * SHADER_FORMAT_SIZE * formatShader */ - #include "base.shader.h" + #include "Shaders/base.shader.h" + #include "Shaders/default.shader.h" + + const char* Shader::PROJECTION_MATRIX = "_projectionMatrix_"; + const char* Shader::MODEL_MATRIX = "_modelMatrix_"; + const char* Shader::MAIN_TEXTURE = "_main_texture_"; + const char* Shader::VERTEX_COORDS = "_vert_coord_"; + const char* Shader::TEXTURE_COORDS = "_tex_coord_"; /** * https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value @@ -44,46 +55,84 @@ namespace graphics */ const int DEFAULT_TEXTURE_UNIT = 0; - /*static*/ JSLProgram* JSLProgram::currentJSLProgram = nullptr; + /*static*/ Shader* Shader::currentShader = nullptr; - JSLProgram* JSLProgram::createJSLProgram(const char* program) + Shader* Shader::createShader(const string& program) { - JSLProgram* jsl = nullptr; + Shader* shader = nullptr; try { - jsl = new JSLProgram(program); + shader = new Shader(program); } catch(...) { return nullptr; } - return jsl; + return shader; } - JSLProgram::JSLProgram(const char* program) + Shader::Shader(const string& program) : currentTextureUnit(DEFAULT_TEXTURE_UNIT) { - Buffer b = Buffer(strlen(program) + SHADER_FORMAT_SIZE); - formatShader((char*)b.data, program); - GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(shader, 1, (const GLchar**)&b.data, NULL); - glCompileShader(shader); + if (!compile(program)) + throw 0; + } + + Shader::~Shader() + { + if (currentShader == this) + unuse(); + } + + bool Shader::compile(const string& program) + { + int loc_VERTEX_SHADER = program.find("#VERTEX_SHADER"); + int loc_END_VERTEX_SHADER = program.find("#END_VERTEX_SHADER"); + int loc_FRAGMENT_SHADER = program.find("#FRAGMENT_SHADER"); + int loc_END_FRAGMENT_SHADER = program.find("#END_FRAGMENT_SHADER"); + if (loc_VERTEX_SHADER == string::npos + || loc_END_VERTEX_SHADER == string::npos + || loc_FRAGMENT_SHADER == string::npos + || loc_END_FRAGMENT_SHADER == string::npos + ) + return false; + int p = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER"); + string vertex_shader = program.substr(p, loc_END_VERTEX_SHADER - p); + Buffer vbuffer = Buffer(vertex_shader.length() + BASE_VERTEX_SHADER_SIZE); + formatVertexShader((char*)vbuffer.data, vertex_shader.c_str()); + p = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER"); + string fragment_shader = program.substr(p, loc_END_FRAGMENT_SHADER - p); + Buffer fbuffer = Buffer(fragment_shader.length() + BASE_FRAGMENT_SHADER_SIZE); + formatFragmentShader((char*)fbuffer.data, fragment_shader.c_str()); + /* compile */ GLint success; - glGetShaderiv(shader, GL_COMPILE_STATUS, &success); + GLuint vshader = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vshader, 1, (const GLchar**)&vbuffer.data, NULL); + glCompileShader(vshader); + glGetShaderiv(vshader, GL_COMPILE_STATUS, &success); + //std::cout << (char*)vbuffer.data << std::endl; + //Buffer log = Buffer(1024); + //int len; + //glGetShaderInfoLog(vshader, sizeof(log), &len, (GLchar*)log.data); + //std::cout << (char*)log.data << std::endl; if (success == GL_FALSE) - throw 0; + return false; + GLuint fshader = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fshader, 1, (const GLchar**)&fbuffer.data, NULL); + glCompileShader(fshader); + glGetShaderiv(fshader, GL_COMPILE_STATUS, &success); + //std::cout << (char*)fbuffer.data << std::endl; + if (success == GL_FALSE) + return false; pid = glCreateProgram(); - glAttachShader(pid, shader); + glAttachShader(pid, vshader); + glAttachShader(pid, fshader); glLinkProgram(pid); glGetProgramiv(pid, GL_LINK_STATUS, &success); + //glGetProgramInfoLog(pid, 1024, &len, (GLchar*)log.data); + //std::cout << (char*)log.data << std::endl; if (success == GL_FALSE) - throw 0; - } - - JSLProgram::~JSLProgram() - { - if (currentJSLProgram == this) - unuse(); + throw false; } static inline GLint getMaxTextureUnits() @@ -93,22 +142,20 @@ namespace graphics return maxTextureUnits; } - void JSLProgram::use() + void Shader::use() { glUseProgram(pid); - currentJSLProgram = this; - /* bind default texture */ - int loc = glGetUniformLocation(pid, default_texture); - glUniform1i(loc, DEFAULT_TEXTURE_UNIT); + currentShader = this; + sendInt(Shader::MAIN_TEXTURE, DEFAULT_TEXTURE_UNIT); } - /*static*/ void JSLProgram::unuse() + /*static*/ void Shader::unuse() { glUseProgram(0); - currentJSLProgram = nullptr; + currentShader = nullptr; } - GLint JSLProgram::claimTextureUnit(const std::string& name) + GLint Shader::claimTextureUnit(const std::string& name) { std::map<std::string, GLint>::iterator unit = textureUnits.find(name); if (unit != textureUnits.end()) @@ -121,10 +168,17 @@ namespace graphics } #define checkJSL() \ - if (currentJSLProgram != this) \ + if (currentShader != this) \ return - void JSLProgram::sendFloat(const char* variable, float number) + void Shader::sendInt(const char* name, int value) + { + checkJSL(); + int loc = glGetUniformLocation(pid, name); + glUniform1i(loc, value); + } + + void Shader::sendFloat(const char* variable, float number) { checkJSL(); int loc = glGetUniformLocation(pid, variable); @@ -145,7 +199,7 @@ namespace graphics * TextureUnit textureUnits[GL_MAX_TEXTURE_IMAGE_UNITS] * GLuint currentTextureUnit = 0; */ - void JSLProgram::sendTexture(const char* variable, const Texture* tex) + void Shader::sendTexture(const char* variable, const Texture* tex) { checkJSL(); GLint location = glGetUniformLocation(pid, variable); @@ -157,14 +211,13 @@ namespace graphics // TODO: 쳣 return; } + gl.activeTexUnit(unit); glUniform1i(location, unit); - glActiveTexture(GL_TEXTURE0 + unit); - glBindTexture(GL_TEXTURE_2D, tex->getTexture()); - - glActiveTexture(GL_TEXTURE0); + gl.bindTexture(tex->getTexture()); + gl.activeTexUnit(0); } - void JSLProgram::sendCanvas(const char* variable, const Canvas* canvas) + void Shader::sendCanvas(const char* variable, const Canvas* canvas) { checkJSL(); GLint location = glGetUniformLocation(pid, variable); @@ -178,33 +231,33 @@ namespace graphics } glUniform1i(location, unit); glActiveTexture(GL_TEXTURE0 + unit); - glBindTexture(GL_TEXTURE_2D, canvas->getTexture()); + gl.bindTexture(canvas->getTexture()); glActiveTexture(GL_TEXTURE0); } - void JSLProgram::sendVec2(const char* name, float x, float y) + void Shader::sendVec2(const char* name, float x, float y) { checkJSL(); int loc = glGetUniformLocation(pid, name); glUniform2f(loc, x, y); } - void JSLProgram::sendVec3(const char* name, float x, float y, float z) + void Shader::sendVec3(const char* name, float x, float y, float z) { checkJSL(); int loc = glGetUniformLocation(pid, name); glUniform3f(loc, x, y, z); } - void JSLProgram::sendVec4(const char* name, float x, float y, float z, float w) + void Shader::sendVec4(const char* name, float x, float y, float z, float w) { checkJSL(); int loc = glGetUniformLocation(pid, name); glUniform4f(loc, x, y, z, w); } - void JSLProgram::sendColor(const char* name, const Color* col) + void Shader::sendColor(const char* name, const Color* col) { checkJSL(); int loc = glGetUniformLocation(pid, name); @@ -216,6 +269,26 @@ namespace graphics ); } + void Shader::sendMatrix4(const char* name, const math::Matrix* mat4) + { + int loc = glGetUniformLocation(pid, name); + glUniformMatrix4fv(loc, 1, GL_FALSE, mat4->getElements()); + } + + void Shader::bindVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers) + { + GLint loc = glGetAttribLocation(pid, VERTEX_COORDS); + glEnableVertexAttribArray(0); + glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers); + } + + void Shader::bindUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers) + { + GLint loc = glGetAttribLocation(pid, TEXTURE_COORDS); + glEnableVertexAttribArray(1); + glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers); + } + } // graphics } // jin diff --git a/src/libjin/Graphics/Shader.h b/src/libjin/Graphics/Shader.h index 83a2831..2ea9e04 100644 --- a/src/libjin/Graphics/Shader.h +++ b/src/libjin/Graphics/Shader.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_JSL_H #define __LIBJIN_JSL_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include <string> @@ -15,30 +15,42 @@ namespace jin namespace graphics { - /* Jin Shader Language Program*/ - class JSLProgram + /* Jin Shading Language Program*/ + class Shader { public: - static JSLProgram* createJSLProgram(const char* program); - static inline JSLProgram* getCurrentJSL() { return currentJSLProgram; } + static Shader* createShader(const std::string& program); + static inline Shader* getCurrentJSL() { return currentShader; } static void unuse(); - virtual ~JSLProgram(); + static const char* PROJECTION_MATRIX; + static const char* MODEL_MATRIX; + static const char* MAIN_TEXTURE; + static const char* VERTEX_COORDS; + static const char* TEXTURE_COORDS; + + virtual ~Shader(); void use(); void sendFloat(const char* name, float number); void sendTexture(const char* name, const Texture* image); + void sendInt(const char* name, int value); void sendVec2(const char* name, float x, float y); void sendVec3(const char* name, float x, float y, float z); void sendVec4(const char* name, float x, float y, float z, float w); void sendCanvas(const char* name, const Canvas* canvas); void sendColor(const char* name, const Color* col); + void sendMatrix4(const char* name, const math::Matrix* mat4); + + void bindVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers); + void bindUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers); protected: - static JSLProgram* currentJSLProgram; + static Shader* currentShader; GLint claimTextureUnit(const std::string& name); - JSLProgram(const char* program); + Shader(const std::string& program); + bool compile(const std::string& program); GLuint pid; GLint currentTextureUnit; diff --git a/src/libjin/Graphics/Shaders/base.shader.h b/src/libjin/Graphics/Shaders/base.shader.h new file mode 100644 index 0000000..3790a47 --- /dev/null +++ b/src/libjin/Graphics/Shaders/base.shader.h @@ -0,0 +1,104 @@ +/* + * https://stackoverflow.com/questions/10868958/what-does-sampler2d-store + * The sampler2D is bound to a texture unit. The glUniform call binds it to texture + * unit zero. The glActiveTexture call is only needed if you are going to use multiple + * texture units (because GL_TEXTURE0 is the default anyway). +*/ +/* +#VERTEX_SHADER + +vertex vert(vertex v) +{ + return v; +} + +#END_VERTEX_SHADER + +#FRAGMENT_SHADER + +vec4 frag(vec4 color, Texture tex, vertex v) +{ + return Texel(tex, v.uv); +} + +#END_FRAGMENT_SHADER + +*/ + +static const char* base_shared = R"( +#define Number float +#define Texture sampler2D +#define Canvas sampler2D +#define Color vec4 +#define Vec2 vec2 +#define Vec3 vec3 +#define Vec4 vec4 + +#define texel texture2D + +struct Vertex +{ + vec2 xy; + vec2 uv; +}; + +)"; + +static const int BASE_SHARED_SIZE = strlen(base_shared); + +static const char* base_vertex = R"( +#version 130 core + +%s + +uniform mat4 _projectionMatrix_; +uniform mat4 _modelMatrix_; + +in vec2 _vert_coord_; +in vec2 _tex_coord_; + +out vec4 _color; +out vec2 _xy; +out vec2 _uv; + +%s + +void main() +{ + vec4 v = _modelMatrix_ * vec4(_vert_coord_, 0, 1.0); + Vertex _v = vert(Vertex(v.xy, _tex_coord_)); + gl_Position = _projectionMatrix_ * vec4(_v.xy, 0, 1.0f); + _color = gl_Color; + _xy = _v.xy; + _uv = _v.uv; +} +)"; + +static const int BASE_VERTEX_SHADER_SIZE = strlen(base_vertex) + BASE_SHARED_SIZE; + +#define formatVertexShader(buf, program) sprintf(buf,base_vertex, base_shared, program) + +static const char* base_fragment = R"( +#version 130 core + +%s + +uniform Texture _main_texture_; + +in vec4 _color; +in vec2 _xy; +in vec2 _uv; + +out vec4 _outColor_; + +%s + +void main() +{ + _outColor_ = frag(_color, _main_texture_, Vertex(_xy, _uv)); +} +)"; + +static const int BASE_FRAGMENT_SHADER_SIZE = strlen(base_fragment) + BASE_SHARED_SIZE; + +#define formatFragmentShader(buf, program) sprintf(buf, base_fragment, base_shared, program) diff --git a/src/libjin/Graphics/Shaders/default.shader.h b/src/libjin/Graphics/Shaders/default.shader.h new file mode 100644 index 0000000..f0175d7 --- /dev/null +++ b/src/libjin/Graphics/Shaders/default.shader.h @@ -0,0 +1,21 @@ +// Ĭshader +static const char* default_shader = R"( + +#VERTEX_SHADER + +Vertex vert(Vertex v) +{ + return v; +} + +#END_VERTEX_SHADER + +#FRAGMENT_SHADER + +Color frag(Color col, Texture tex, Vertex v) +{ + return col; +} + +#END_FRAGMENT_SHADER +)";
\ No newline at end of file diff --git a/src/libjin/Graphics/Shaders/font.shader.h b/src/libjin/Graphics/Shaders/font.shader.h new file mode 100644 index 0000000..e04c225 --- /dev/null +++ b/src/libjin/Graphics/Shaders/font.shader.h @@ -0,0 +1,21 @@ +// shader +static const char* font_shader = R"( + +#VERTEX_SHADER + +Vertex vert(Vertex v) +{ + return v; +} + +#END_VERTEX_SHADER + +#FRAGMENT_SHADER + +Color frag(Color col, Texture tex, Vertex v) +{ + return Color(col.rgb, texel(tex, v.uv).a); +} + +#END_FRAGMENT_SHADER +)";
\ No newline at end of file diff --git a/src/libjin/Graphics/Shaders/texture.shader.h b/src/libjin/Graphics/Shaders/texture.shader.h new file mode 100644 index 0000000..d1fc86f --- /dev/null +++ b/src/libjin/Graphics/Shaders/texture.shader.h @@ -0,0 +1,21 @@ +// ͼshader +static const char* texture_shader = R"( + +#VERTEX_SHADER + +Vertex vert(Vertex v) +{ + return v; +} + +#END_VERTEX_SHADER + +#FRAGMENT_SHADER + +Color frag(Color col, Texture tex, Vertex v) +{ + return col * texel(tex, v.uv); +} + +#END_FRAGMENT_SHADER +)";
\ No newline at end of file diff --git a/src/libjin/Graphics/Shapes.cpp b/src/libjin/Graphics/Shapes.cpp index 2cb33a2..cf47e00 100644 --- a/src/libjin/Graphics/Shapes.cpp +++ b/src/libjin/Graphics/Shapes.cpp @@ -1,6 +1,7 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER +#include "Shader.h" #include "Shapes.h" #include "../math/matrix.h" #include "../math/constant.h" @@ -11,21 +12,30 @@ namespace jin namespace graphics { + using namespace math; + void point(int x, int y) { - float vers[] = { x + 0.5f , y + 0.5f }; - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)vers); + float verts[] = { x + 0.5f , y + 0.5f }; + + Shader* shader = Shader::getCurrentJSL(); + shader->bindVertexPointer(2, GL_FLOAT, 0, verts); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + glDrawArrays(GL_POINTS, 0, 1); - glDisableClientState(GL_VERTEX_ARRAY); } void points(int n, GLshort* p) { - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_SHORT, 0, (GLvoid*)p); - glDrawArrays(GL_POINTS, 0, n); - glDisableClientState(GL_VERTEX_ARRAY); + Shader* shader = Shader::getCurrentJSL(); + shader->bindVertexPointer(2, GL_SHORT, 0, p); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + + glDrawArrays(GL_POINTS, 0, n); } void line(int x1, int y1, int x2, int y2) @@ -34,11 +44,14 @@ namespace graphics x1, y1, x2, y2 }; - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)verts); - glDrawArrays(GL_LINES, 0, 2); - glDisableClientState(GL_VERTEX_ARRAY); + + Shader* shader = Shader::getCurrentJSL(); + shader->bindVertexPointer(2, GL_FLOAT, 0, verts); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + + glDrawArrays(GL_LINES, 0, 2); } void circle(RenderMode mode, int x, int y, int r) @@ -80,10 +93,13 @@ namespace graphics void polygon_line(float* p, int count) { - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p); + Shader* shader = Shader::getCurrentJSL(); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, p); + glDrawArrays(GL_LINE_LOOP, 0, count); - glDisableClientState(GL_VERTEX_ARRAY); } void polygon(RenderMode mode, float* p, int count) @@ -94,10 +110,13 @@ namespace graphics } else if (mode == FILL) { - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p); + Shader* shader = Shader::getCurrentJSL(); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(Shader::MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(Shader::PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, p); + glDrawArrays(GL_POLYGON, 0, count); - glDisableClientState(GL_VERTEX_ARRAY); } } diff --git a/src/libjin/Graphics/Shapes.h b/src/libjin/Graphics/Shapes.h index dc9f272..b248cca 100644 --- a/src/libjin/Graphics/Shapes.h +++ b/src/libjin/Graphics/Shapes.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_GEOMETRY_H #define __LIBJIN_GEOMETRY_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "color.h" diff --git a/src/libjin/Graphics/Texture.cpp b/src/libjin/Graphics/Texture.cpp index 9958935..5a39f77 100644 --- a/src/libjin/Graphics/Texture.cpp +++ b/src/libjin/Graphics/Texture.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include <fstream> @@ -15,35 +15,23 @@ namespace graphics /*static*/ Texture* Texture::createTexture(Bitmap* bitmap) { - Texture* tex = new Texture(); - const Color* pixels = bitmap->getPixels(); - tex->size.w = bitmap->getWidth(); - tex->size.h = bitmap->getHeight(); - unsigned int w = tex->size.w; - unsigned int h = tex->size.h; - - glGenTextures(1, &tex->texture); - glBindTexture(GL_TEXTURE_2D, tex->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - tex->vertCoord[0] = 0; tex->vertCoord[1] = 1; - tex->vertCoord[2] = 0; tex->vertCoord[3] = h; - tex->vertCoord[4] = w; tex->vertCoord[5] = h; - tex->vertCoord[6] = w; tex->vertCoord[7] = 1; - - tex->textCoord[0] = 0; tex->textCoord[1] = 0; - tex->textCoord[2] = 0; tex->textCoord[3] = 1; - tex->textCoord[4] = 1; tex->textCoord[5] = 1; - tex->textCoord[6] = 1; tex->textCoord[7] = 0; - + Texture* tex = new Texture(bitmap); return tex; } - Texture::Texture() - : Drawable() + Texture::Texture(const Bitmap* bitmap) + : Drawable(bitmap->getWidth(), bitmap->getHeight()) { + unsigned int w = size.w; + unsigned int h = size.h; + const Color* pixels = bitmap->getPixels(); + + texture = gl.genTexture(); + gl.bindTexture(texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + gl.bindTexture(0); } Texture::~Texture() diff --git a/src/libjin/Graphics/Texture.h b/src/libjin/Graphics/Texture.h index f2e45f0..8498666 100644 --- a/src/libjin/Graphics/Texture.h +++ b/src/libjin/Graphics/Texture.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_IMAGE_H #define __LIBJIN_IMAGE_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "../3rdparty/GLee/GLee.h" @@ -20,7 +20,7 @@ namespace graphics ~Texture(); private: - Texture(); + Texture(const Bitmap* bitmap); }; diff --git a/src/libjin/Graphics/Utf8.cpp b/src/libjin/Graphics/Utf8.cpp new file mode 100644 index 0000000..1a79d43 --- /dev/null +++ b/src/libjin/Graphics/Utf8.cpp @@ -0,0 +1,68 @@ +#include <stdlib.h> +#include <string.h> +#include "Utf8.h" + +namespace jin +{ +namespace graphics +{ + + /* utf8 byte string to unicode codepoint */ + static const char *utf8toCodepoint(const char *p, unsigned *res) { + unsigned x, mask, shift; + switch (*p & 0xf0) { + case 0xf0: mask = 0x07; shift = 18; break; + case 0xe0: mask = 0x0f; shift = 12; break; + case 0xc0: + case 0xd0: mask = 0x1f; shift = 6; break; + default: + *res = *p; + return p + 1; + } + x = (*p & mask) << shift; + do { + if (*(++p) == '\0') { + *res = x; + return p; + } + shift -= 6; + x |= (*p & 0x3f) << shift; + } while (shift); + *res = x; + return p + 1; + } + + Utf8::Utf8(const char* raw, unsigned int length) + { + _length = length; + _raw = (char*)calloc(1, length); + memcpy(_raw, raw, length); + } + + Utf8::Iterator Utf8::getIterator() + { + return Iterator(*this); + } + + Utf8::~Utf8() + { + free(_raw); + _raw = nullptr; + _length = 0; + } + + Utf8::Iterator::Iterator(const Utf8& utf8) + : _utf8(utf8) + { + _p = utf8._raw; + } + + Codepoint Utf8::Iterator::get() + { + Codepoint c; + _p = utf8toCodepoint(_p, &c); + return c; + } + +} +}
\ No newline at end of file diff --git a/src/libjin/Graphics/Utf8.h b/src/libjin/Graphics/Utf8.h new file mode 100644 index 0000000..d2d11fb --- /dev/null +++ b/src/libjin/Graphics/Utf8.h @@ -0,0 +1,44 @@ +#ifndef __LIBJIN_UTF8_H +#define __LIBJIN_UTF8_H + +namespace jin +{ +namespace graphics +{ + + typedef unsigned int Codepoint; + + class Utf8 + { + public: + class Iterator + { + public: + /* unicode codepoint */ + Codepoint get(); + + private: + friend class Utf8; + Iterator(const Utf8&); + + const char* _p; + const Utf8& _utf8; + }; + + /* rawıսij */ + Utf8(const char* raw, unsigned int length); + Iterator getIterator(); + + private: + friend class Utf8::Iterator; + ~Utf8(); + + char* _raw; + unsigned int _length; + + }; + +} +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/Window.cpp b/src/libjin/Graphics/Window.cpp index 1fb60cc..6ebc9f9 100644 --- a/src/libjin/Graphics/Window.cpp +++ b/src/libjin/Graphics/Window.cpp @@ -1,10 +1,11 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include <iostream> #include "window.h" -#include "../3rdparty/GLee/GLee.h" +#include "OpenGL.h" #include "canvas.h" +#include "Shader.h" #include "../utils/utils.h" #include "../audio/sdl/SDLAudio.h" #include "../utils/log.h" @@ -68,23 +69,24 @@ namespace graphics SDL_GL_SetSwapInterval(vsync ? 1 : 0); SDL_GL_MakeCurrent(wnd, ctx); /* default configuration */ - glClearColor(0.f, 0.f, 0.f, 1.f); - glColor4f(1, 1, 1, 1); - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + gl.setClearColor(0, 0, 0, 0xff); + gl.pushColor(0xff, 0xff, 0xff, 0xff); + gl.enable(GL_BLEND); + gl.enable(GL_TEXTURE_2D); + gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* avoid white screen blink on windows */ swapBuffers(); /* bind to default canvas */ Canvas::unbind(); + Shader::unuse(); return true; } void Window::quitSystem() { /* disable opengl */ - glDisable(GL_BLEND); - glDisable(GL_TEXTURE_2D); + gl.disable(GL_BLEND); + gl.disable(GL_TEXTURE_2D); /* close window */ SDL_DestroyWindow(wnd); SDL_Quit(); diff --git a/src/libjin/Graphics/Window.h b/src/libjin/Graphics/Window.h index 6b247a6..301b0b5 100644 --- a/src/libjin/Graphics/Window.h +++ b/src/libjin/Graphics/Window.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_RENDER_WINDOW #define __LIBJIN_RENDER_WINDOW -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_RENDER #include "SDL2/SDL.h" diff --git a/src/libjin/Graphics/base.shader.h b/src/libjin/Graphics/base.shader.h deleted file mode 100644 index 080e27e..0000000 --- a/src/libjin/Graphics/base.shader.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * https://stackoverflow.com/questions/10868958/what-does-sampler2d-store - * The sampler2D is bound to a texture unit. The glUniform call binds it to texture - * unit zero. The glActiveTexture call is only needed if you are going to use multiple - * texture units (because GL_TEXTURE0 is the default anyway). -*/ - -static const char* default_texture = "_tex0_"; - -static const char* base_shader = R"( -#define number float -#define Texture sampler2D -#define Canvas sampler2D -#define Color vec4 -#define Texel texture2D -#define extern uniform -#define Vec2 vec2 -#define Vec3 vec3 -#define Vec4 vec4 -#define Number number -#define Image Texture - -extern Texture %s; -%s -void main() -{ - gl_FragColor = effect(gl_Color, %s, gl_TexCoord[0].xy, gl_FragCoord.xy); -} -)"; - -static const int SHADER_FORMAT_SIZE = strlen(base_shader) + strlen(default_texture) * 2; - -#define formatShader(buf, program)\ - sprintf(buf, base_shader, default_texture, program, default_texture) diff --git a/src/libjin/Input/Event.h b/src/libjin/Input/Event.h index cef6b88..7ab07da 100644 --- a/src/libjin/Input/Event.h +++ b/src/libjin/Input/Event.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_EVENT_H #define __LIBJIN_EVENT_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_INPUT namespace jin diff --git a/src/libjin/Input/Mouse.cpp b/src/libjin/Input/Mouse.cpp index 892d140..31c29f9 100644 --- a/src/libjin/Input/Mouse.cpp +++ b/src/libjin/Input/Mouse.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #ifdef LIBJIN_MODULES_INPUT #include "SDL.h" diff --git a/src/libjin/Input/Mouse.h b/src/libjin/Input/Mouse.h index 25dd4c3..09db5d2 100644 --- a/src/libjin/Input/Mouse.h +++ b/src/libjin/Input/Mouse.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_MOUSE_H #define __LIBJIN_MOUSE_H -#include "../modules.h" +#include "../jin_configuration.h" #ifdef LIBJIN_MODULES_INPUT #include "../Common/Singleton.hpp" diff --git a/src/libjin/Math/Matrix.cpp b/src/libjin/Math/Matrix.cpp index 39042f0..a80f37a 100644 --- a/src/libjin/Math/Matrix.cpp +++ b/src/libjin/Math/Matrix.cpp @@ -8,6 +8,8 @@ namespace jin namespace math { + const Matrix Matrix::Identity; + // | e0 e4 e8 e12 | // | e1 e5 e9 e13 | // | e2 e6 e10 e14 | @@ -22,6 +24,21 @@ namespace math { } + void Matrix::setOrtho(float l, float r, float b, float t, float n, float f) + { + float w = r - l; + float h = t - b; + float z = f - n; + setIdentity(); + e[0] = 2 / w; + e[5] = 2 / h; + e[10] = -2 / z; + e[12] = -(r + l) / w; + e[13] = -(t + b) / h; + e[14] = -(f + n) / z; + e[15] = 1; + } + // | e0 e4 e8 e12 | // | e1 e5 e9 e13 | // | e2 e6 e10 e14 | diff --git a/src/libjin/Math/Matrix.h b/src/libjin/Math/Matrix.h index b9a55d4..52fc9c8 100644 --- a/src/libjin/Math/Matrix.h +++ b/src/libjin/Math/Matrix.h @@ -16,6 +16,8 @@ namespace math * This class is the basis for all transformations in LOVE. Althought not * really needed for 2D, it contains 4x4 elements to be compatible with * OpenGL without conversions. + * Ҫתõľ + * https://blog.csdn.net/candycat1992/article/details/8830894 **/ class Matrix { @@ -31,6 +33,8 @@ namespace math public: + static const Matrix Identity; + /** * Creates a new identity matrix. **/ @@ -41,6 +45,8 @@ namespace math **/ ~Matrix(); + void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); + /** * Multiplies this Matrix with another Matrix, changing neither. * @param m The Matrix to multiply with this Matrix. diff --git a/src/libjin/Net/Net.h b/src/libjin/Net/Net.h index 4727667..27353dc 100644 --- a/src/libjin/Net/Net.h +++ b/src/libjin/Net/Net.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_NET_H #define __LIBJIN_NET_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_NET #include "../Common/Subsystem.hpp" diff --git a/src/libjin/Net/Socket.h b/src/libjin/Net/Socket.h index 1a2256c..32ef86f 100644 --- a/src/libjin/Net/Socket.h +++ b/src/libjin/Net/Socket.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_NET_SOCKET_H #define __LIBJIN_NET_SOCKET_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_NET #include "../3rdparty/tekcos/tekcos.h" diff --git a/src/libjin/Net/net.h b/src/libjin/Net/net.h index 4727667..27353dc 100644 --- a/src/libjin/Net/net.h +++ b/src/libjin/Net/net.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_NET_H #define __LIBJIN_NET_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_NET #include "../Common/Subsystem.hpp" diff --git a/src/libjin/Thread/Thread.cpp b/src/libjin/Thread/Thread.cpp index c2b7b91..971fc03 100644 --- a/src/libjin/Thread/Thread.cpp +++ b/src/libjin/Thread/Thread.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_THREAD #include "Thread.h" diff --git a/src/libjin/Thread/Thread.h b/src/libjin/Thread/Thread.h index 3c41949..3a7b4ba 100644 --- a/src/libjin/Thread/Thread.h +++ b/src/libjin/Thread/Thread.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_THREAD_H #define __LIBJIN_THREAD_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_THREAD #include <string> diff --git a/src/libjin/Thread/thread.cpp b/src/libjin/Thread/thread.cpp index c2b7b91..971fc03 100644 --- a/src/libjin/Thread/thread.cpp +++ b/src/libjin/Thread/thread.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_THREAD #include "Thread.h" diff --git a/src/libjin/Thread/thread.h b/src/libjin/Thread/thread.h index 3c41949..3a7b4ba 100644 --- a/src/libjin/Thread/thread.h +++ b/src/libjin/Thread/thread.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_THREAD_H #define __LIBJIN_THREAD_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_THREAD #include <string> diff --git a/src/libjin/Time/Timer.cpp b/src/libjin/Time/Timer.cpp index e5d0799..94d790d 100644 --- a/src/libjin/Time/Timer.cpp +++ b/src/libjin/Time/Timer.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_TIME #include "Timer.h" diff --git a/src/libjin/Time/Timer.h b/src/libjin/Time/Timer.h index aff2f70..7a58e14 100644 --- a/src/libjin/Time/Timer.h +++ b/src/libjin/Time/Timer.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_TIMER_H #define __LIBJIN_TIMER_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_TIME #include "SDL2/SDL.h" diff --git a/src/libjin/audio/audio.cpp b/src/libjin/audio/audio.cpp index c9a3e40..798269a 100644 --- a/src/libjin/audio/audio.cpp +++ b/src/libjin/audio/audio.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include "SDL2/SDL.h" diff --git a/src/libjin/audio/audio.h b/src/libjin/audio/audio.h index 9faf0bc..b9812dd 100644 --- a/src/libjin/audio/audio.h +++ b/src/libjin/audio/audio.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_AUDIO_H #define __LIBJIN_AUDIO_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include "SDL2/SDL.h" diff --git a/src/libjin/audio/source.cpp b/src/libjin/audio/source.cpp index 7ac4e60..1dcd482 100644 --- a/src/libjin/audio/source.cpp +++ b/src/libjin/audio/source.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include <cstring> diff --git a/src/libjin/audio/source.h b/src/libjin/audio/source.h index b227db2..e1ca6d0 100644 --- a/src/libjin/audio/source.h +++ b/src/libjin/audio/source.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_AUDIO_SOURCE_H #define __LIBJIN_AUDIO_SOURCE_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_AUDIO #include "SDL2/SDL.h" diff --git a/src/libjin/core/core.h b/src/libjin/core/core.h deleted file mode 100644 index 4b4df8f..0000000 --- a/src/libjin/core/core.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __LIBJIN_CORE_H -#define __LIBJIN_CORE_H - -#include "game.h" - -#endif
\ No newline at end of file diff --git a/src/libjin/core/game.cpp b/src/libjin/core/game.cpp deleted file mode 100644 index 3f905f2..0000000 --- a/src/libjin/core/game.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "game.h" -#include "../Time/Timer.h" -#include "../input/Event.h" -#include "../Graphics/Window.h" -#include "../Math/Math.h" -#include <iostream> - -namespace jin -{ -namespace core -{ - - using namespace jin::graphics; - using namespace jin::input; - using namespace jin::time; - using namespace jin::math; - - Game::Game() :_running(true) {}; - - void Game::run() - { - if (_onLoad != nullptr) - _onLoad(); - Window* wnd = Window::get(); - const int FPS = wnd ? wnd->getFPS() : 60; - const int MS_PER_UPDATE = 1000.0f / FPS; - _running = true; - Event e; - int previous = getMilliSecond(); - int dt = MS_PER_UPDATE; - while (_running) - { - while (jin::input::pollEvent(&e)) - { - if (_onEvent != nullptr) - _onEvent(&e); - if (!_running) goto quitloop; - } - if (_onUpdate != nullptr) _onUpdate(dt); - if (_onDraw != nullptr) _onDraw(); - wnd->swapBuffers(); - const int current = getMilliSecond(); - dt = current - previous; - const int wait = MS_PER_UPDATE - (current - previous); - previous += MS_PER_UPDATE; - if (wait > 0) - { - sleep(wait); - dt = MS_PER_UPDATE; - } - else - previous = current; - } - quitloop:; - } - - bool Game::initSystem(const SettingBase* setting) - { - if (setting == nullptr) - return false; - Game::Setting* s = (Game::Setting*) setting; - _onEvent = s->eventHandler; - _onUpdate = s->updater; - _onDraw = s->drawer; - _onLoad = s->loader; - return true; - } - - void Game::quitSystem() - { - } - -} // core -} // jin
\ No newline at end of file diff --git a/src/libjin/core/game.h b/src/libjin/core/game.h deleted file mode 100644 index 725c62c..0000000 --- a/src/libjin/core/game.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __LIBJIN_CORE_GAME_H -#define __LIBJIN_CORE_GAME_H - -#include "SDL2/SDL.h" - -#include "../Common/Subsystem.hpp" -#include "../utils/macros.h" -#include "../Input/Event.h" - -namespace jin -{ -namespace core -{ - - class Game : public Subsystem<Game> - { - public: - - typedef void(*onLoad)(); - typedef void(*onEvent)(jin::input::Event* e); - typedef void(*onUpdate)(int dt); - typedef void(*onDraw)(); - - struct Setting : SettingBase - { - onEvent eventHandler; - onUpdate updater; - onDraw drawer; - onLoad loader; - }; - - void run(); - inline void stop() { _running = false; }; - inline bool running() { return _running; }; - - private: - - Game(); - ~Game() {}; - - SINGLETON(Game); - - onEvent _onEvent; - onUpdate _onUpdate; - onDraw _onDraw; - onLoad _onLoad; - - bool _running; - - bool initSystem(const SettingBase* setting); - void quitSystem(); - - }; - -} // core -} // jin - -#endif // __LIBJIN_CORE_GAME_H diff --git a/src/libjin/input/event.h b/src/libjin/input/event.h index cef6b88..7ab07da 100644 --- a/src/libjin/input/event.h +++ b/src/libjin/input/event.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_EVENT_H #define __LIBJIN_EVENT_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_INPUT namespace jin diff --git a/src/libjin/input/mouse.cpp b/src/libjin/input/mouse.cpp index 892d140..31c29f9 100644 --- a/src/libjin/input/mouse.cpp +++ b/src/libjin/input/mouse.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #ifdef LIBJIN_MODULES_INPUT #include "SDL.h" diff --git a/src/libjin/input/mouse.h b/src/libjin/input/mouse.h index 25dd4c3..09db5d2 100644 --- a/src/libjin/input/mouse.h +++ b/src/libjin/input/mouse.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_MOUSE_H #define __LIBJIN_MOUSE_H -#include "../modules.h" +#include "../jin_configuration.h" #ifdef LIBJIN_MODULES_INPUT #include "../Common/Singleton.hpp" diff --git a/src/libjin/jin.h b/src/libjin/jin.h index a4bb37f..255616c 100644 --- a/src/libjin/jin.h +++ b/src/libjin/jin.h @@ -1,13 +1,13 @@ #ifndef __LIBJIN_H #define __LIBJIN_H -#include "modules.h" +#include "jin_configuration.h" #include "Utils/utils.h" #ifdef LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO #include "Audio/SDL/SDLAudio.h" #endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO -#include "Core/Core.h" +#include "Game/Game.h" #include "Filesystem/Filesystem.h" #include "Filesystem/Buffer.h" #include "Input/Input.h" diff --git a/src/libjin/modules.h b/src/libjin/jin_configuration.h index 83eb90b..83eb90b 100644 --- a/src/libjin/modules.h +++ b/src/libjin/jin_configuration.h diff --git a/src/libjin/math/matrix.cpp b/src/libjin/math/matrix.cpp index 39042f0..a80f37a 100644 --- a/src/libjin/math/matrix.cpp +++ b/src/libjin/math/matrix.cpp @@ -8,6 +8,8 @@ namespace jin namespace math { + const Matrix Matrix::Identity; + // | e0 e4 e8 e12 | // | e1 e5 e9 e13 | // | e2 e6 e10 e14 | @@ -22,6 +24,21 @@ namespace math { } + void Matrix::setOrtho(float l, float r, float b, float t, float n, float f) + { + float w = r - l; + float h = t - b; + float z = f - n; + setIdentity(); + e[0] = 2 / w; + e[5] = 2 / h; + e[10] = -2 / z; + e[12] = -(r + l) / w; + e[13] = -(t + b) / h; + e[14] = -(f + n) / z; + e[15] = 1; + } + // | e0 e4 e8 e12 | // | e1 e5 e9 e13 | // | e2 e6 e10 e14 | diff --git a/src/libjin/math/matrix.h b/src/libjin/math/matrix.h index b9a55d4..52fc9c8 100644 --- a/src/libjin/math/matrix.h +++ b/src/libjin/math/matrix.h @@ -16,6 +16,8 @@ namespace math * This class is the basis for all transformations in LOVE. Althought not * really needed for 2D, it contains 4x4 elements to be compatible with * OpenGL without conversions. + * Ҫתõľ + * https://blog.csdn.net/candycat1992/article/details/8830894 **/ class Matrix { @@ -31,6 +33,8 @@ namespace math public: + static const Matrix Identity; + /** * Creates a new identity matrix. **/ @@ -41,6 +45,8 @@ namespace math **/ ~Matrix(); + void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far); + /** * Multiplies this Matrix with another Matrix, changing neither. * @param m The Matrix to multiply with this Matrix. diff --git a/src/libjin/net/net.h b/src/libjin/net/net.h index 4727667..27353dc 100644 --- a/src/libjin/net/net.h +++ b/src/libjin/net/net.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_NET_H #define __LIBJIN_NET_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_NET #include "../Common/Subsystem.hpp" diff --git a/src/libjin/thread/thread.cpp b/src/libjin/thread/thread.cpp index c2b7b91..971fc03 100644 --- a/src/libjin/thread/thread.cpp +++ b/src/libjin/thread/thread.cpp @@ -1,4 +1,4 @@ -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_THREAD #include "Thread.h" diff --git a/src/libjin/thread/thread.h b/src/libjin/thread/thread.h index 3c41949..3a7b4ba 100644 --- a/src/libjin/thread/thread.h +++ b/src/libjin/thread/thread.h @@ -1,6 +1,6 @@ #ifndef __LIBJIN_THREAD_H #define __LIBJIN_THREAD_H -#include "../modules.h" +#include "../jin_configuration.h" #if LIBJIN_MODULES_THREAD #include <string> diff --git a/src/lua/common/Proxy.h b/src/lua/common/Proxy.h index 8323ead..101fe9c 100644 --- a/src/lua/common/Proxy.h +++ b/src/lua/common/Proxy.h @@ -33,6 +33,13 @@ namespace lua return *(Ref<T>*) reference; } + template<class T> + T* getObject() + { + Ref<T>& ref = getRef<T>(); + return ref.getObject(); + } + const char* getObjectType() { return reference->type; diff --git a/src/lua/embed/graphics.lua.h b/src/lua/embed/graphics.lua.h index 1414efc..1bad4f5 100644 --- a/src/lua/embed/graphics.lua.h +++ b/src/lua/embed/graphics.lua.h @@ -1,4 +1,37 @@ /* graphics.lua */ static const char* graphics_lua = R"( jin.graphics = jin.graphics or {} + +local default_shader = nil +local default_shader_source = [[ +#VERTEX_SHADER + +Vertex vert(Vertex v) +{ + return v; +} + +#END_VERTEX_SHADER + +#FRAGMENT_SHADER + +Color frag(Color col, Texture tex, Vertex v) +{ + return col; +} + +#END_FRAGMENT_SHADER +]] +local _init = jin.graphics.init + +jin.graphics.init = function(setting) + _init(setting); + default_shader = jin.graphics.newShader(default_shader_source) + jin.graphics.useShader(default_shader) +end + +jin.graphics.unuseShader = function() + jin.graphics.useShader(default_shader) +end + )"; diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp index c3dabad..e388ae1 100644 --- a/src/lua/modules/filesystem/filesystem.cpp +++ b/src/lua/modules/filesystem/filesystem.cpp @@ -120,13 +120,13 @@ namespace lua } static const luaL_Reg f[] = { - { "init", l_init }, - { "mount", l_mount }, - { "isDir", l_isDir }, - { "isFile", l_isFile }, - { "exist", l_exist }, - { "read", l_read }, - { 0, 0 } + { "init", l_init }, + { "mount", l_mount }, + { "isDirectory", l_isDir }, + { "isFile", l_isFile }, + { "exist", l_exist }, + { "read", l_read }, + { 0, 0 } }; int luaopen_filesystem(lua_State* L) diff --git a/src/lua/modules/graphics/font.cpp b/src/lua/modules/graphics/font.cpp index 042eb19..15aa04e 100644 --- a/src/lua/modules/graphics/font.cpp +++ b/src/lua/modules/graphics/font.cpp @@ -19,25 +19,37 @@ namespace lua return 0; } - static int l_box(lua_State* L) + static int l_typeset(lua_State* L) { - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Proxy)); - FontRef ref = proxy->getRef<Font>(); - const char* text = luax_checkstring(L, 2); - int fheight = luax_checknumber(L, 3); - int spacing = luax_checknumber(L, 4); - int lheight = luax_checknumber(L, 5); - int w, h; - ref->box(text, fheight, lheight, spacing, &w, &h); - luax_pushnumber(L, w); - luax_pushnumber(L, h); - return 2; + Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_FONT); + const char* text = luax_checkstring(L, 2); + int lineheight = luax_checkinteger(L, 3); + int spacing = luax_checkinteger(L, 4); + Ref<Font>& refFont = p->getRef<Font>(); + Font* font = refFont.getObject(); + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy)); + Page* page = font->typeset(text, lineheight, spacing); + proxy->bind(new Ref<Page>(page, JIN_GRAPHICS_PAGE)); + return 1; + } + + static int l_print(lua_State* L) + { + Proxy* pFont = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_FONT); + Font* font = pFont->getObject<Font>(); + Proxy* p = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_PAGE); + Page* page = p->getObject<Page>(); + int x = luax_checkinteger(L, 3); + int y = luax_checkinteger(L, 4); + font->print(page, x, y); + return 0; } static const luaL_Reg f[] = { - { "__gc", l_gc }, - { "box", l_box }, - { 0, 0 } + { "__gc", l_gc }, + { "typeset", l_typeset }, + { "print", l_print }, + { 0, 0 } }; int luaopen_Font(lua_State* L) diff --git a/src/lua/modules/graphics/fontData.cpp b/src/lua/modules/graphics/fontData.cpp new file mode 100644 index 0000000..85704d7 --- /dev/null +++ b/src/lua/modules/graphics/fontData.cpp @@ -0,0 +1,45 @@ +#include "lua/modules/luax.h" +#include "lua/modules/types.h" +#include "lua/common/common.h" +#include "libjin/jin.h" + +namespace jin +{ +namespace lua +{ + + using namespace jin::graphics; + + static int l_newFont(lua_State* L) + { + Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_FONTDATA); + int fontsize = luax_checkinteger(L, 2); + Ref<FontData>& refFontData = p->getRef<FontData>(); + FontData* fontData = refFontData.getObject(); + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Proxy)); + Font* font = Font::createFont(fontData, fontsize); + proxy->bind(new Ref<Font>(font, JIN_GRAPHICS_FONT)); + return 1; + } + + static int l_gc(lua_State* L) + { + Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_FONTDATA); + p->release(); + return 0; + } + + static const luaL_Reg f[] = { + { "__gc", l_gc }, + { "newFont", l_newFont }, + { 0, 0 } + }; + + int luaopen_FontData(lua_State* L) + { + luax_newtype(L, JIN_GRAPHICS_FONTDATA, f); + return 0; + } + +} // lua +} // jin
\ No newline at end of file diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 679b820..5c67421 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -145,7 +145,7 @@ namespace lua static int l_newShader(lua_State* L) { const char* program = luax_checkstring(L, 1); - JSLProgram* jsl = JSLProgram::createJSLProgram(program); + Shader* jsl = Shader::createShader(program); if (jsl == nullptr) { error(L, "Failed to compile shader"); @@ -153,7 +153,7 @@ namespace lua return 1; } Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy)); - proxy->bind(new Ref<JSLProgram>(jsl, JIN_GRAPHICS_SHADER)); + proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER)); return 1; } @@ -252,7 +252,6 @@ namespace lua context.curRenderColor.a = luax_checknumber(L, 4); else context.curClearColor.a = 255; - glColor4f(context.curRenderColor.r / 255.f, context.curRenderColor.g / 255.f, context.curRenderColor.b / 255.f, @@ -293,13 +292,13 @@ namespace lua { if (luax_gettop(L) == 0) { - JSLProgram::unuse(); + Shader::unuse(); return 0; } if (luax_istype(L, 1, JIN_GRAPHICS_SHADER)) { Proxy* proxy = (Proxy*)luax_toudata(L, 1); - Ref<JSLProgram>& jsl = proxy->getRef<JSLProgram>(); + Ref<Shader>& jsl = proxy->getRef<Shader>(); jsl->use(); } else @@ -308,13 +307,13 @@ namespace lua } return 0; } - +/* static int l_unuseShader(lua_State* L) { - JSLProgram::unuse(); + Shader::unuse(); return 0; } - +*/ static int l_setBlend(lua_State* L) { @@ -451,10 +450,10 @@ namespace lua return 0; } - static int l_newFont(lua_State* L) + static int l_newFontData(lua_State* L) { - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Proxy)); - Font* font = new Font(); + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONTDATA, sizeof(Proxy)); + FontData* fd = nullptr; { const char* path = luax_checkstring(L, 1); Filesystem* fs = Filesystem::get(); @@ -464,64 +463,14 @@ namespace lua luax_pushnil(L); return 1; } - Buffer b = {}; + Buffer b; fs->read(path, &b); - font->loadMemory((const unsigned char*)b.data); + fd = FontData::createFontData((unsigned char*)b.data, b.size); } - proxy->bind(new Ref<Font>(font, JIN_GRAPHICS_FONT)); + proxy->bind(new Ref<FontData>(fd, JIN_GRAPHICS_FONTDATA)); return 1; } - static int l_setFont(lua_State* L) - { - int n = luax_gettop(L); - if (n == 0) - { - if (context.defaultFont == 0) - { - #include "lua/resources/font.ttf.h" - context.defaultFont = new Font(); - context.defaultFont->loadMemory(font_ttf); - } - context.curFont = context.defaultFont; - return 0; - } - Font* font = (Font*)luax_checktype(L, 1, JIN_GRAPHICS_FONT); - context.curFont = font; - return 0; - } - - static int l_write(lua_State* L) - { - if (context.curFont == 0) - return 0; - - const char* text = luax_checkstring(L, 1); - int x = luax_checknumber(L, 2); - int y = luax_checknumber(L, 3); - - int fh = luax_optnumber(L, 4, 15); - int spacing = luax_optnumber(L, 5, 1); - int lh = luax_optnumber(L, 6, 18); - - context.curFont->render(text, x, y, fh, spacing, lh); - - return 0; - } - - static int l_box(lua_State* L) - { - const char* text = luax_checkstring(L, 1); - int fontheight = luax_checknumber(L, 2); - int spacing = luax_checknumber(L, 3); - int lineheight = luax_checknumber(L, 4); - int w, h; - context.curFont->box(text, fontheight, spacing, lineheight, &w, &h); - luax_pushnumber(L, w); - luax_pushnumber(L, h); - return 2; - } - static const luaL_Reg f[] = { /* window */ { "init", l_init }, @@ -535,7 +484,7 @@ namespace lua { "newTexture", l_newTexture }, { "newShader", l_newShader }, { "newCanvas", l_newCanvas }, - { "newFont", l_newFont }, + { "newFontData", l_newFontData }, /* render */ { "setClearColor", l_setClearColor }, { "clear", l_clear }, @@ -543,16 +492,12 @@ namespace lua { "setColor", l_setColor }, { "getColor", l_getColor }, { "present", l_present }, - /* font */ - { "box", l_box }, - { "write", l_write }, - { "setFont", l_setFont }, /* canvas */ { "bindCanvas", l_bindCanvas }, { "unbindCanvas", l_unbindCanvas }, /* shader */ { "useShader", l_useShader }, - { "unuseShader", l_unuseShader }, + //{ "unuseShader", l_unuseShader }, /* shapes */ { "point", l_point }, { "line", l_line }, @@ -565,6 +510,8 @@ namespace lua extern int luaopen_Texture(lua_State* L); extern int luaopen_Font(lua_State* L); + extern int luaopen_FontData(lua_State* L); + extern int luaopen_Page(lua_State* L); extern int luaopen_Canvas(lua_State* L); extern int luaopen_JSL(lua_State* L); extern int luaopen_Bitmap(lua_State* L); @@ -575,7 +522,9 @@ namespace lua luaopen_Bitmap(L); luaopen_Texture(L); luaopen_Canvas(L); + luaopen_FontData(L); luaopen_Font(L); + luaopen_Page(L); luaopen_JSL(L); // load whole lib diff --git a/src/lua/modules/graphics/page.cpp b/src/lua/modules/graphics/page.cpp new file mode 100644 index 0000000..fd96448 --- /dev/null +++ b/src/lua/modules/graphics/page.cpp @@ -0,0 +1,65 @@ +#include "lua/modules/luax.h" +#include "lua/modules/types.h" +#include "lua/common/common.h" +#include "libjin/jin.h" + +namespace jin +{ +namespace lua +{ + + using namespace jin::graphics; + + typedef Ref<Font>& FontRef; + + Page* getPage(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE); + return proxy->getObject<Page>(); + } + + static int l_gc(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE); + proxy->release(); + return 0; + } + + static int l_getSize(lua_State* L) + { + Page* page = getPage(L); + luax_pushinteger(L, page->width); + luax_pushinteger(L, page->height); + return 2; + } + + static int l_getWidth(lua_State* L) + { + Page* page = getPage(L); + luax_pushinteger(L, page->width); + return 1; + } + + static int l_getHeight(lua_State* L) + { + Page* page = getPage(L); + luax_pushinteger(L, page->height); + return 1; + } + + static const luaL_Reg f[] = { + { "__gc", l_gc }, + { "getSize", l_getSize }, + { "getWidth", l_getWidth }, + { "getHeight", l_getHeight }, + { 0, 0 } + }; + + int luaopen_Page(lua_State* L) + { + luax_newtype(L, JIN_GRAPHICS_PAGE, f); + return 0; + } + +} // lua +} // jin
\ No newline at end of file diff --git a/src/lua/modules/graphics/shader.cpp b/src/lua/modules/graphics/shader.cpp index db78c4d..a9603bc 100644 --- a/src/lua/modules/graphics/shader.cpp +++ b/src/lua/modules/graphics/shader.cpp @@ -10,12 +10,12 @@ namespace lua using namespace jin::graphics; - typedef Ref<JSLProgram>& JSLRef; + typedef Ref<Shader>& ShaderRef; - static inline JSLRef checkJSLProgram(lua_State* L) + static inline ShaderRef checkShader(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER); - return proxy->getRef<JSLProgram>(); + return proxy->getRef<Shader>(); } /** @@ -23,7 +23,7 @@ namespace lua */ static int l_sendNumber (lua_State* L) { - JSLRef ref = checkJSLProgram(L); + ShaderRef ref = checkShader(L); const char* variable = luax_checkstring(L, 2); float number = luax_checknumber(L, 3); ref->sendFloat(variable, number); @@ -32,7 +32,7 @@ namespace lua static int l_sendTexture (lua_State* L) { - JSLRef ref = checkJSLProgram(L); + ShaderRef ref = checkShader(L); const char* variable = luax_checkstring(L, 2); Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE); Ref<Texture>& tex = proxy->getRef<Texture>(); @@ -42,7 +42,7 @@ namespace lua static int l_sendCanvas (lua_State* L) { - JSLRef ref = checkJSLProgram(L); + ShaderRef ref = checkShader(L); const char* variable = luax_checkstring(L, 2); Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS); Ref<Canvas>& canvas = proxy->getRef<Canvas>(); @@ -52,7 +52,7 @@ namespace lua static int l_sendVec2 (lua_State* L) { - JSLRef ref = checkJSLProgram(L); + ShaderRef ref = checkShader(L); const char* variable = luax_checkstring(L, 2); if (!luax_istable(L, 3)) { @@ -67,7 +67,7 @@ namespace lua static int l_sendVec3 (lua_State* L) { - JSLRef ref = checkJSLProgram(L); + ShaderRef ref = checkShader(L); const char* variable = luax_checkstring(L, 2); if (!luax_istable(L, 3)) { @@ -83,7 +83,7 @@ namespace lua static int l_sendVec4 (lua_State* L) { - JSLRef ref = checkJSLProgram(L); + ShaderRef ref = checkShader(L); const char* variable = luax_checkstring(L, 2); if (!luax_istable(L, 3)) { diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h index d61ce38..59b8ed6 100644 --- a/src/lua/modules/types.h +++ b/src/lua/modules/types.h @@ -2,20 +2,22 @@ #define __JIN_MODULES_TYPES_H // graphics module -#define JIN_GRAPHICS_TEXTURE "jin.graphics.Texture" -#define JIN_GRAPHICS_SHADER "jin.graphics.Shader" -#define JIN_GRAPHICS_CANVAS "jin.graphics.Canvas" -#define JIN_GRAPHICS_FONT "jin.graphics.Font" -#define JIN_GRAPHICS_BITMAP "jin.graphics.Bitmap" +#define JIN_GRAPHICS_TEXTURE "jin.graphics.Texture" +#define JIN_GRAPHICS_SHADER "jin.graphics.Shader" +#define JIN_GRAPHICS_CANVAS "jin.graphics.Canvas" +#define JIN_GRAPHICS_FONTDATA "jin.graphics.FontData" +#define JIN_GRAPHICS_FONT "jin.graphics.Font" +#define JIN_GRAPHICS_PAGE "jin.graphics.Page" +#define JIN_GRAPHICS_BITMAP "jin.graphics.Bitmap" // audio module -#define JIN_AUDIO_SOURCE "jin.Audio.Source" - -// thread module -#define JIN_THREAD_THREAD "jin.thread.Thread" - -// network module -#define JIN_NETWORK_SOCKET "jin.net.Socket" -#define JIN_NETWORK_BUFFER "jin.net.Buffer" +#define JIN_AUDIO_SOURCE "jin.Audio.Source" + +// thread module +#define JIN_THREAD_THREAD "jin.thread.Thread" + +// network module +#define JIN_NETWORK_SOCKET "jin.net.Socket" +#define JIN_NETWORK_BUFFER "jin.net.Buffer" #endif
\ No newline at end of file |