Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fralexxelarf

Pages: [1]
1
Graphics / Re: Entity/quad drawing order and VertexArrays
« on: March 14, 2017, 04:16:53 pm »
Ok nice, I think I got it then!

Thanks a lot! :)

2
Graphics / Re: Entity/quad drawing order and VertexArrays
« on: March 14, 2017, 03:35:10 pm »
Ahh ok! Then it basically becomes like ordering a vector of sf::Sprites, but vertices instead? But this assumes all sprites that could have different Z values use the same texture, right? (and then static Z value-Sprites/Vertices, like GUI and tiles in another texture & batch?)

Thanks for the fast reply.

Edit: clarification

3
Graphics / Entity/quad drawing order and VertexArrays
« on: March 14, 2017, 02:46:17 pm »
Hello!

I have a RenderingSystem that loops through a vector of SpriteBatches, one for each texture atlas/spritesheet. The SpriteBatch has a VertexArray that has quads for each instance of X-type entity that uses that texture.

Spritebatch
class SpriteBatch : public sf::Drawable, public sf::Transformable
{
public:
        unsigned int m_VerticesCount;
        sf::VertexArray m_Vertices;
        sf::Texture* m_pTexture;
public:
    SpriteBatch(sf::Texture* texture)
        m_pTexture(texture), m_VerticesCount(0)
    {
            m_Vertices.setPrimitiveType(sf::Quads);
    }

    void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
            // Apply the transform
            states.transform *= getTransform();

            // Apply the tileset texture
            states.texture = m_pTexture;

            // Draw the vertex array
            target.draw(m_Vertices, states);
    }
};

RenderingSystem render method.
// Loops through all spritebatches and draws them.
void RenderingSystem::render(sf::RenderWindow& window)
{
        for (auto spritebatch : m_SpriteBatches) window.draw(*spritebatch);
}

Do you have any tips on how I would go about ordering the individual quads above/below eachother?

I've come up with this idea about moving the quads(where Z != 0) to a new, temporary SpriteBatch, then loop through all new spritebatches and draw them in order, from lowest to highest Z. (Z values would be stored relative to quad positions and also in each new SpriteBatch.) Does that sound plausible? Or would it be too slow and better to just use some list of entities?

I hope your understand my question, otherwise tell me and I will try to clarify as well as I can. :)


Thanks!

Pages: [1]
anything