1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 22:44:32 +00:00

working on quad repeat, this probably breaks it but will continue later

This commit is contained in:
fgenesis 2023-09-13 23:39:22 +02:00
parent db8912cb16
commit 4013a9c09b
4 changed files with 44 additions and 65 deletions

View file

@ -116,8 +116,8 @@ AquariaSaveSlot::AquariaSaveSlot(int slot) : AquariaGuiQuad()
screen->alphaMod = 1; screen->alphaMod = 1;
core->resetTimer(); core->resetTimer();
screen->upperLeftTextureCoordinates = Vector(0, 1); //screen->upperLeftTextureCoordinates = Vector(0, 1);
screen->lowerRightTextureCoordinates = Vector(1, 0.25f); //screen->lowerRightTextureCoordinates = Vector(1, 0.25f);
if (screen->getWidth() == 0) if (screen->getWidth() == 0)

View file

@ -121,11 +121,11 @@ void WaterSurfaceRender::onUpdate(float dt)
const float v0 = 1 + reflectOffset - (reflectPos * core->globalScale.x) / coordDiv; const float v0 = 1 + reflectOffset - (reflectPos * core->globalScale.x) / coordDiv;
const float v1 = v0 + (reflectSize * core->globalScale.x) / coordDiv; const float v1 = v0 + (reflectSize * core->globalScale.x) / coordDiv;
upperLeftTextureCoordinates.y = v0 * core->frameBuffer.getHeightP(); /*upperLeftTextureCoordinates.y = v0 * core->frameBuffer.getHeightP();
lowerRightTextureCoordinates.y = v1 * core->frameBuffer.getHeightP(); lowerRightTextureCoordinates.y = v1 * core->frameBuffer.getHeightP();
upperLeftTextureCoordinates.x = 0; upperLeftTextureCoordinates.x = 0;
lowerRightTextureCoordinates.x = core->frameBuffer.getWidthP(); lowerRightTextureCoordinates.x = core->frameBuffer.getWidthP();*/
} }
} }

View file

@ -54,9 +54,8 @@ void Quad::initQuad()
renderBorder = false; renderBorder = false;
renderCenter = true; renderCenter = true;
width = 2; height = 2; width = 2; height = 2;
texcoords.setStandard();
upperLeftTextureCoordinates = Vector(0,0);
lowerRightTextureCoordinates = Vector(1,1);
renderQuad = true; renderQuad = true;
grid = NULL; grid = NULL;
} }
@ -89,13 +88,8 @@ DynamicRenderGrid *Quad::createGrid(int xd, int yd)
grid = NULL; grid = NULL;
if(xd && yd) if(xd && yd)
{ {
TexCoordBox tc;
tc.u1 = upperLeftTextureCoordinates.x;
tc.v1 = upperLeftTextureCoordinates.y;
tc.u2 = lowerRightTextureCoordinates.x;
tc.v2 = lowerRightTextureCoordinates.y;
grid = new DynamicRenderGrid(); grid = new DynamicRenderGrid();
grid->init(xd, yd, tc); grid->init(xd, yd, texcoords);
} }
return grid; return grid;
} }
@ -214,9 +208,6 @@ void Quad::renderGrid(const RenderState& rs) const
rx.color = rs.color * this->color; rx.color = rs.color * this->color;
rx.alpha = rs.alpha * this->alpha.x * this->alphaMod; rx.alpha = rs.alpha * this->alpha.x * this->alphaMod;
glPushMatrix();
glScalef(width, height, 1);
grid->render(rx); grid->render(rx);
// debug points // debug points
@ -226,8 +217,6 @@ void Quad::renderGrid(const RenderState& rs) const
grid->renderDebugPoints(rs); grid->renderDebugPoints(rs);
RenderObject::lastTextureApplied = 0; RenderObject::lastTextureApplied = 0;
} }
glPopMatrix();
} }
@ -242,26 +231,19 @@ void Quad::onRender(const RenderState& rs) const
{ {
if (!renderQuad) return; if (!renderQuad) return;
const float _w2 = width*0.5f;
const float _h2 = height*0.5f; // previously, vertical flip was implemented by texcoord inversion.
// ie. child objects were never affected. not sure if this is desirable behavior but it'll stay like
// this for now. should probably make it affect children as well.
glPushMatrix();
if(_fv)
glRotatef(180, 1, 0, 0);
glScalef(width, height, 1);
if (!grid) if (!grid)
{ {
glBegin(GL_QUADS); core->getDefaultQuadGrid()->render(rs);
{
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
glVertex2f(-_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
glVertex2f(+_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
glVertex2f(+_w2, -_h2);
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
glVertex2f(-_w2, -_h2);
}
glEnd();
} }
else else
{ {
@ -273,43 +255,33 @@ void Quad::onRender(const RenderState& rs) const
else if(rs.forceRenderBorder) else if(rs.forceRenderBorder)
_renderBorder(rs, rs.renderBorderColor, rs.renderBorderAlpha); _renderBorder(rs, rs.renderBorderColor, rs.renderBorderAlpha);
glPopMatrix();
}
void Quad::flipHorizontal()
{
RenderObject::flipHorizontal();
}
void Quad::flipVertical()
{
if (!_fv)
{
lowerRightTextureCoordinates.y = 0;
upperLeftTextureCoordinates.y = 1;
}
else
{
lowerRightTextureCoordinates.y = 1;
upperLeftTextureCoordinates.y = 0;
}
RenderObject::flipVertical();
} }
void Quad::refreshRepeatTextureToFill() void Quad::refreshRepeatTextureToFill()
{ {
if (repeatTexture && texture) if (repeatTexture && texture)
{ {
upperLeftTextureCoordinates.x = texOff.x; texcoords.u1 = texOff.x;
upperLeftTextureCoordinates.y = texOff.y; texcoords.v1 = texOff.y;
lowerRightTextureCoordinates.x = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x; texcoords.u2 = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x;
lowerRightTextureCoordinates.y = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y; texcoords.v2 = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y;
if(!grid)
{
createGrid(2, 2)->gridType = GRID_UNDEFINED;
}
} }
else else
{ {
if (fabsf(lowerRightTextureCoordinates.x) > 1 || fabsf(lowerRightTextureCoordinates.y)>1) if (fabsf(texcoords.u2) > 1 || fabsf(texcoords.v2) > 1)
lowerRightTextureCoordinates = Vector(1,1); {
texcoords.u2 = 1;
texcoords.v2 = 1;
if(grid && grid->gridType == GRID_UNDEFINED && texcoords.isStandard())
deleteGrid();
}
} }
} }

View file

@ -41,6 +41,15 @@ protected:
class DynamicRenderGrid; class DynamicRenderGrid;
/*class QuadRepeatData
{
DynamicRenderGrid grid; // need this here because a repeating tile WITH a grid-based tile effect is a special and annoying case to handle
// set by user
float texscaleX, texscaleY;
float texOffX, texOffY;
};*/
class Quad : public RenderObject class Quad : public RenderObject
{ {
public: public:
@ -53,8 +62,6 @@ public:
bool isCoordinateInsideWorld(const Vector &coord, int minSize=0) const; bool isCoordinateInsideWorld(const Vector &coord, int minSize=0) const;
bool isCoordinateInsideWorldRect(const Vector &coord, int w, int h) const; bool isCoordinateInsideWorldRect(const Vector &coord, int w, int h) const;
void flipVertical() OVERRIDE;
void flipHorizontal() OVERRIDE;
void setWidthHeight(float w, float h=-1); void setWidthHeight(float w, float h=-1);
void setWidth(float w); void setWidth(float w);
void setHeight(float h); void setHeight(float h);
@ -74,7 +81,7 @@ public:
void deleteGrid(); void deleteGrid();
Vector upperLeftTextureCoordinates, lowerRightTextureCoordinates; TexCoordBox texcoords;
// TODO: this should be a bitmask // TODO: this should be a bitmask
char autoWidth, autoHeight; char autoWidth, autoHeight;