From b33080b0ead22779ba585633771a6a325e945696 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 20 Oct 2023 00:37:00 +0200 Subject: [PATCH] remove immediate mode from quad rendering. breaks a couple rendering details too. WIP. --- BBGE/Quad.cpp | 25 ++++++++----------------- BBGE/Texture.cpp | 14 ++++++++++++++ BBGE/Texture.h | 1 + BBGE/Tile.cpp | 13 ++----------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 04479ff..5464586 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -116,29 +116,18 @@ void Quad::_renderBorder(const RenderState& rs, Vector color, float borderalpha) { glBindTexture(GL_TEXTURE_2D, 0); + glColor4f(color.x, color.y, color.z, borderalpha*alpha.x*alphaMod); + + core->getDefaultQuadBorderBuf()->apply(); + if (rs.forceRenderCenter || renderCenter) { - glColor4f(color.x, color.y, color.z, borderalpha*alpha.x*alphaMod); glPointSize(16); - glBegin(GL_POINTS); - glVertex2f(0,0); - glEnd(); + glDrawArrays(GL_POINTS, 4, 1); } - glColor4f(color.x, color.y, color.z, alpha.x*alphaMod); glLineWidth(2); - const float _w2 = width*0.5f; - const float _h2 = height*0.5f; - glBegin(GL_LINES); - glVertex2f(-_w2, _h2); - glVertex2f(_w2, _h2); - glVertex2f(_w2, -_h2); - glVertex2f(_w2, _h2); - glVertex2f(-_w2, -_h2); - glVertex2f(-_w2, _h2); - glVertex2f(-_w2, -_h2); - glVertex2f(_w2, -_h2); - glEnd(); + glDrawArrays(GL_LINE_LOOP, 0, 4); RenderObject::lastTextureApplied = 0; } @@ -266,11 +255,13 @@ void Quad::refreshRepeatTextureToFill() texcoords.v1 = texOff.y; texcoords.u2 = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x; texcoords.v2 = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y; + //texcoords.fixflip(); if(!grid) { createGrid(2, 2)->gridType = GRID_UNDEFINED; } + grid->setTexCoords(texcoords); } else { diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index dd5a898..b8235b8 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -43,6 +43,20 @@ void TexCoordBox::setStandard() v2 = 1; } +void TexCoordBox::fixflip() +{ + // HACK: partially repeated textures have a weird Y axis. assuming a repeat factor of 0.4, + // instead of texcoords from 0 -> 0.4 everything is biased towards the opposite end, ie. 0.6 -> 1. + // This is especially true for partial repeats, we always need to bias towards the other end. + // I have no idea why this has to be like this for tiles, but this is NOT the case for fonts. + // And NOTE: without this, maps may look deceivingly correct, but they really are not. + const float percentY = v2 - v1; + const float remainder = 1.0f - fmodf(percentY, 1.0f); + v1 += remainder; // bias towards next int + v2 += remainder; + +} + Texture::Texture() { diff --git a/BBGE/Texture.h b/BBGE/Texture.h index 6469af0..53358b8 100644 --- a/BBGE/Texture.h +++ b/BBGE/Texture.h @@ -31,6 +31,7 @@ struct TexCoordBox bool isStandard() const; void setStandard(); + void fixflip(); // call this after setting up, in case flip is desired }; enum TextureLoadResult diff --git a/BBGE/Tile.cpp b/BBGE/Tile.cpp index c91638e..e599025 100644 --- a/BBGE/Tile.cpp +++ b/BBGE/Tile.cpp @@ -168,7 +168,7 @@ void TileStorage::deleteSome(const size_t* indices, size_t n) for(size_t i = 0; i < tmp.size(); ++i) { - for(size_t k = 0; k < n; ++i) // not particularly efficient, could be much better by sorting first but eh + for(size_t k = 0; k < n; ++k) // not particularly efficient, could be much better by sorting first but eh if(indices[k] == i) { dropAll(tmp[i]); @@ -630,16 +630,7 @@ TexCoordBox TileRepeatData::calcTexCoords(const TileData& t) const tc.v1 = texOffY; tc.u2 = (et.w*t.scalex*texscaleX)/tw + texOffX; tc.v2 = (et.h*t.scaley*texscaleY)/th + texOffY; - - // HACK: partially repeated textures have a weird Y axis. assuming a repeat factor of 0.4, - // instead of texcoords from 0 -> 0.4 everything is biased towards the opposite end, ie. 0.6 -> 1. - // This is especially true for partial repeats, we always need to bias towards the other end. - // I have no idea why this has to be like this for tiles, but this is NOT the case for fonts. - // And NOTE: without this, maps may look deceivingly correct, but they really are not. - const float percentY = tc.v2 - tc.v1; - const float remainder = 1.0f - fmodf(percentY, 1.0f); - tc.v1 += remainder; // bias towards next int - tc.v2 += remainder; + //tc.fixflip(); return tc; }