I have one last question. I am almost finished with the class, as soon as I fix a bug that's occurring I'll get it done and get to document and upload. I've minimized the problem as much as I could yet I know not why the bug is occurring.
When displaying the texture it gets folded like if the quad was a trapezoid, yet it's a rectangle defined by the texture's rect.
I'll post the minimal test program and the code that powers it.
Here's main.
sf::RenderWindow window(sf::VideoMode(1280, 800, 32), "Bullet Testing", sf::Style::Fullscreen);
unsigned MaxNum = 1;
AltSpriteHolder ASH(MaxNum);
sf::Texture T;
if(!T.loadFromFile("C:/Users/Carlos/Desktop/Sprites/White Mana.png"))
return -1;
ASH.setTexture(T);
window.setFramerateLimit(60);
while (window.isOpen())
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.draw(ASH);
window.display();
///Events
}
And here's the remaining code:
AltSpriteHolder::AltSpriteHolder(const unsigned amount)
:VertexHolder(), PositionHolder(), Quantity(amount), ScaleHolder(), AngleHolder(), Tex(nullptr)
{
VertexHolder.reserve(amount*4);
PositionHolder.reserve(amount);
ScaleHolder.reserve(amount);
AngleHolder.reserve(amount);
for(unsigned i = 0; i < amount; ++i)
{
for(unsigned j = 0; j < 4; ++j)
{ VertexHolder.push_back(sf::Vertex(sf::Vector2f(0.f, 0.f), sf::Color(255, 255, 255, 255))); }
///Filling the remaining containers, not relevant.
}
}
void AltSpriteHolder::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.texture = Tex;
target.draw(&VertexHolder[0], static_cast<unsigned>(VertexHolder.size()), sf::Quads, states);
}
void AltSpriteHolder::setTexture(sf::Texture& T)
{
Tex = &T;
setGlobalTextureRect(sf::IntRect(0, 0, Tex->getSize().x, Tex->getSize().y) );
}
void AltSpriteHolder::setTextureRect(const unsigned index, const sf::IntRect& IR)
{
TexRectHolder[index] = IR;
updateTexCoords(index);
updateVertexCoords(index, false);
}
void AltSpriteHolder::setGlobalTextureRect(const sf::IntRect& IR)
{
for(unsigned i = 0; i < Quantity; ++i)
{ setTextureRect(i, IR); }
}
void AltSpriteHolder::updateTexCoords(const unsigned index)
{
float left = static_cast<float>(TexRectHolder[index].left);
float right = left + TexRectHolder[index].width;
float top = static_cast<float>(TexRectHolder[index].top);
float bottom = top + TexRectHolder[index].height;
unsigned I = index * 4;
VertexHolder[I].texCoords = sf::Vector2f(left, top);
++I;
VertexHolder[I].texCoords = sf::Vector2f(left, bottom);
++I;
VertexHolder[I].texCoords = sf::Vector2f(right, bottom);
++I;
VertexHolder[I].texCoords = sf::Vector2f(right, top);
}
void AltSpriteHolder::updateVertexCoords(const unsigned index, const bool Reset)
{
sf::Vector2u S;
S.x = TexRectHolder[index].width * ScaleHolder[index].x;
S.y = TexRectHolder[index].height * ScaleHolder[index].y;
unsigned I = index * 4;
VertexHolder[I].position = sf::Vector2f( -(S.x/2.f), -(S.y/2.f) );
++I;
VertexHolder[I].position = sf::Vector2f( -(S.x/2.f), (S.y/2.f) );
++I;
VertexHolder[I].position = sf::Vector2f( (S.x/2.f), -(S.y/2.f) );
++I;
VertexHolder[I].position = sf::Vector2f( (S.x/2.f), (S.y/2.f) );
if(Reset)
{
PositionHolder[index].x = 0.f;
PositionHolder[index].y = 0.f;
}
else
{ move(index, PositionHolder[index]); }
}
I've attached the bug image and the image as it's supposed to be. Note that the good image is the clean png, not a displayed image so it clearly lacks background.
[attachment deleted by admin]