mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-27 16:44:00 +00:00
ensure that texcoords are always updated when changing things that affect them
This commit is contained in:
parent
f1796475f1
commit
4c941419b4
6 changed files with 44 additions and 30 deletions
|
@ -3419,8 +3419,8 @@ void Game::toggleHelpScreen(bool on, const std::string &label)
|
|||
helpBG = new Quad;
|
||||
//helpBG->color = 0;
|
||||
helpBG->setTexture("brick");
|
||||
helpBG->setRepeatScale(Vector(2, 2));
|
||||
helpBG->repeatTextureToFill(true);
|
||||
helpBG->repeatToFillScale = Vector(2, 2);
|
||||
//helpBG->alphaMod = 0.75;
|
||||
helpBG->autoWidth = AUTO_VIRTUALWIDTH;
|
||||
helpBG->autoHeight = AUTO_VIRTUALHEIGHT;
|
||||
|
|
|
@ -109,7 +109,7 @@ static void tileToQuad(Quad *q, const TileData& t)
|
|||
q->rotation.z = t.rotation;
|
||||
if(t.flags & TILEFLAG_REPEAT && t.rep)
|
||||
{
|
||||
q->repeatToFillScale = Vector(t.rep->texscaleX, t.rep->texscaleY);
|
||||
q->setRepeatScale(Vector(t.rep->texscaleX, t.rep->texscaleY));
|
||||
q->repeatTextureToFill(true);
|
||||
}
|
||||
q->texcoords = t.getTexcoords();
|
||||
|
@ -193,8 +193,8 @@ public:
|
|||
|
||||
void onUpdate(float dt)
|
||||
{
|
||||
for(size_t i = 0; i < _quads.size(); ++i)
|
||||
_quads[i]->refreshRepeatTextureToFill();
|
||||
//for(size_t i = 0; i < _quads.size(); ++i)
|
||||
// _quads[i]->refreshRepeatTextureToFill();
|
||||
}
|
||||
|
||||
void finish()
|
||||
|
|
|
@ -1889,13 +1889,19 @@ luaFunc(quad_setRepeatScale)
|
|||
{
|
||||
Quad *b = getQuad(L);
|
||||
if (b)
|
||||
{
|
||||
b->repeatToFillScale = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3));
|
||||
b->refreshRepeatTextureToFill();
|
||||
}
|
||||
b->setRepeatScale(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)));
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(quad_getRepeatScale)
|
||||
{
|
||||
Vector s;
|
||||
Quad *b = getQuad(L);
|
||||
if (b)
|
||||
s = b->getRepeatScale();
|
||||
luaReturnVec2(s.x, s.y);
|
||||
}
|
||||
|
||||
luaFunc(quad_isRepeatTexture)
|
||||
{
|
||||
Quad *b = getQuad(L);
|
||||
|
@ -1906,7 +1912,7 @@ luaFunc(quad_setTexOffset)
|
|||
{
|
||||
Quad *b = getQuad(L);
|
||||
if (b)
|
||||
b->texOff = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3));
|
||||
b->setRepeatOffset(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)));
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
|
@ -1915,7 +1921,7 @@ luaFunc(quad_getTexOffset)
|
|||
Quad *b = getQuad(L);
|
||||
Vector v;
|
||||
if (b)
|
||||
v = b->texOff;
|
||||
v = b->getRepeatOffset();
|
||||
luaReturnVec2(v.x, v.y);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,11 +89,9 @@ void WaterSurfaceRender::onUpdate(float dt)
|
|||
qSurface->setWidthHeight(width, height);
|
||||
|
||||
float bit = core->cameraPos.x/300.0f;
|
||||
|
||||
qLine->texOff.x = bit;
|
||||
|
||||
qLine->refreshRepeatTextureToFill();
|
||||
|
||||
Vector texoff = qLine->getRepeatOffset();
|
||||
texoff.x = bit;
|
||||
qLine->setRepeatOffset(texoff);
|
||||
|
||||
|
||||
if (dsq->useFrameBuffer && dsq->frameBuffer.isInited())
|
||||
|
|
|
@ -212,10 +212,22 @@ void Quad::renderGrid(const RenderState& rs) const
|
|||
void Quad::repeatTextureToFill(bool on)
|
||||
{
|
||||
repeatTexture = on;
|
||||
refreshRepeatTextureToFill();
|
||||
updateTexCoords();
|
||||
|
||||
}
|
||||
|
||||
void Quad::setRepeatScale(const Vector& repscale)
|
||||
{
|
||||
repeatToFillScale = repscale;
|
||||
updateTexCoords();
|
||||
}
|
||||
|
||||
void Quad::setRepeatOffset(const Vector& repoffs)
|
||||
{
|
||||
texOff = repoffs;
|
||||
updateTexCoords();
|
||||
}
|
||||
|
||||
void Quad::onRender(const RenderState& rs) const
|
||||
{
|
||||
if (!renderQuad) return;
|
||||
|
@ -247,7 +259,7 @@ void Quad::onRender(const RenderState& rs) const
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Quad::refreshRepeatTextureToFill()
|
||||
void Quad::updateTexCoords()
|
||||
{
|
||||
if (repeatTexture && texture)
|
||||
{
|
||||
|
@ -255,7 +267,6 @@ 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)
|
||||
{
|
||||
|
@ -265,16 +276,12 @@ void Quad::refreshRepeatTextureToFill()
|
|||
}
|
||||
else
|
||||
{
|
||||
if (fabsf(texcoords.u2) > 1 || fabsf(texcoords.v2) > 1)
|
||||
{
|
||||
texcoords.u2 = 1;
|
||||
texcoords.v2 = 1;
|
||||
|
||||
if(grid && grid->gridType == GRID_UNDEFINED && texcoords.isStandard())
|
||||
texcoords.setStandard();
|
||||
// don't delete when a wavy effect is going on, for example
|
||||
if(grid && grid->gridType == GRID_UNDEFINED)
|
||||
deleteGrid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Quad::reloadDevice()
|
||||
{
|
||||
|
|
11
BBGE/Quad.h
11
BBGE/Quad.h
|
@ -71,8 +71,11 @@ public:
|
|||
DynamicRenderGrid *setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo);
|
||||
void setDrawGridAlpha(size_t x, size_t y, float alpha);
|
||||
void repeatTextureToFill(bool on);
|
||||
void refreshRepeatTextureToFill();
|
||||
bool isRepeatingTextureToFill() const { return repeatTexture; }
|
||||
void setRepeatScale(const Vector& repscale);
|
||||
inline const Vector& getRepeatScale() const { return repeatToFillScale; }
|
||||
void setRepeatOffset(const Vector& repoffs);
|
||||
inline const Vector& getRepeatOffset() const { return texOff; }
|
||||
void setStripPoints(bool vert, const Vector *points, size_t n);
|
||||
DynamicRenderGrid *getGrid() { return grid; }
|
||||
const DynamicRenderGrid *getGrid() const { return grid; }
|
||||
|
@ -87,14 +90,14 @@ public:
|
|||
char autoWidth, autoHeight;
|
||||
bool renderQuad, renderCenter, renderBorder;
|
||||
|
||||
Vector texOff;
|
||||
|
||||
float borderAlpha;
|
||||
Vector renderBorderColor;
|
||||
Vector repeatToFillScale;
|
||||
|
||||
protected:
|
||||
void updateTexCoords();
|
||||
|
||||
Vector repeatToFillScale;
|
||||
Vector texOff;
|
||||
DynamicRenderGrid *grid;
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue