diff --git a/BBGE/OpenGLStubs.h b/BBGE/OpenGLStubs.h index 494f34f..48b013b 100644 --- a/BBGE/OpenGLStubs.h +++ b/BBGE/OpenGLStubs.h @@ -53,6 +53,7 @@ GL_FUNC(void,glPixelZoom,(GLfloat xfactor, GLfloat yfactor),(xfactor,yfactor),) GL_FUNC(void,glPointSize,(GLfloat size),(size),) GL_FUNC(void,glPopMatrix,(void),(),) GL_FUNC(void,glPushMatrix,(void),(),) +GL_FUNC(void,glLoadMatrixf,(const GLfloat *m),(m),) GL_FUNC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels),(x,y,width,height,format,type,pixels),) GL_FUNC(void,glRotatef,(GLfloat angle, GLfloat x, GLfloat y, GLfloat z),(angle,x,y,z),) GL_FUNC(void,glScalef,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),) diff --git a/BBGE/TileRender.cpp b/BBGE/TileRender.cpp index fc15152..f5ecc7b 100644 --- a/BBGE/TileRender.cpp +++ b/BBGE/TileRender.cpp @@ -5,6 +5,21 @@ #include "RenderGrid.h" #include "RenderObject.h" +#include +#include + +struct StaticData +{ + glm::mat4 fh, fv; + StaticData() + : fh(glm::rotate(glm::mat4(), 180.0f, glm::vec3(0,1,0))) + , fv(glm::rotate(glm::mat4(), 180.0f, glm::vec3(1,0,0))) + { + } +}; + +static const StaticData staticdata; + TileRender::TileRender(const TileStorage& tiles) : storage(tiles), renderBorders(false) @@ -58,6 +73,10 @@ void TileRender::onRender(const RenderState& rs) const RenderState rx(rs); + // FIXME: this is such a hack. remove this once we pass matrices explicitly + glm::mat4 originalMat; + glGetFloatv(GL_MODELVIEW_MATRIX, &originalMat[0][0]); + // prepare. get parallax scroll factors const RenderObjectLayer& rl = core->renderObjectLayers[this->layer]; const Vector M = rl.followCameraMult; // affected by parallaxLock @@ -131,8 +150,7 @@ void TileRender::onRender(const RenderState& rs) const glColor4f(rs.color.x, rs.color.y, rs.color.z, alpha); } - glPushMatrix(); - glTranslatef(pos.x, pos.y, pos.z); + glm::mat4 m = glm::translate(originalMat, glm::vec3(pos.x, pos.y, pos.z)); // HACK: Due to a renderer bug in older versions, vertical flip is ignored // when a grid-based tile effect is applied. @@ -148,22 +166,25 @@ void TileRender::onRender(const RenderState& rs) const if ((effflag & (TILEFLAG_FH | TILEFLAG_FV)) == (TILEFLAG_FH | TILEFLAG_FV)) effrot += 180; - glRotatef(effrot, 0, 0, 1); + m = glm::rotate(m, effrot, glm::vec3(0,0,1)); + switch(effflag & (TILEFLAG_FH | TILEFLAG_FV)) { case TILEFLAG_FH: - glRotatef(180, 0, 1, 0); + m *= staticdata.fh; break; case TILEFLAG_FV: - glRotatef(180, 1, 0, 0); + m *= staticdata.fv; break; default: ; // both or none set, nothing to do } - glScalef(sw, sh, 1); + m = glm::scale(m, glm::vec3(sw, sh, 1)); + + glLoadMatrixf(&m[0][0]); const RenderGrid *grid = tile.getGrid(); @@ -199,12 +220,9 @@ void TileRender::onRender(const RenderState& rs) const glDrawArrays(GL_LINE_LOOP, 0, 4); } } - - glPopMatrix(); } - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glLoadMatrixf(&originalMat[0][0]); RenderObject::lastTextureApplied = lastTexId; }