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 - fundo

Pages: [1]
1
Graphics / Re: Framerate drops to 11fps when I draw a tilemap
« on: November 11, 2013, 04:58:42 pm »
That is exactly what I'm getting and when I  do 1/elapsedTime I'm getting 11fps like I said earlier... Why is the framerate dropping so much?

2
Graphics / Re: Framerate drops to 11fps when I draw a tilemap
« on: November 11, 2013, 03:41:29 pm »
here is the complete code


/* includes ommitted */

class TileMap : public sf::Drawable, public sf::Transformable
{
        public:
                bool Load(const std::string&, sf::Vector2u, const int* tiles, unsigned int, unsigned int);

        private:
                virtual void draw(sf::RenderTarget&, sf::RenderStates) const;

        private:
                sf::VertexArray m_vertices;
                sf::Texture m_tileset;
};

bool TileMap::Load(const std::string& filename, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{
        // Load the tileset texture

        if (!m_tileset.loadFromFile(filename))
                return false;

        // resize vertex array to fit the level size

        m_vertices.setPrimitiveType(sf::Quads);
        m_vertices.resize(width * height * 4);

        // populate the vertex array with one quad per tile

        for(unsigned int i = 0; i < width; ++i)
        {
                for (unsigned int j = 0; j < height; ++j)
                {
                        // get the current tile number

                        int tileNumber = tiles[i + j * width];

                        // find it's position in the tileset texture

                        int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                        int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);

                        // get a pointer to the current tile's quad

                        sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

                        // define the 4 corners

                        quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                        quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                        quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                        quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                        // define the texture coordinates

                        quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                        quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                        quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                        quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
                }
        }

        return true;
}

void TileMap::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
        // apply the tranform

        states.transform *= getTransform();

        // apply the tileset texture

        states.texture = &m_tileset;

        // draw the vertex array;

        target.draw(m_vertices, states);
}

template <typename T>
std::string ToString(T val)
{
        std::stringstream str;
        str << val;

        return str.str();
}

int main()
{
        sf::Font font;
        if (!font.loadFromFile("Showcard_Gothic.ttf"))
                return -1;

        sf::Text text;
        text.setFont(font);

        sf::Clock clock;

        // create the window

        sf::RenderWindow window(sf::VideoMode(800, 600), "TileMap");

        // define the level with an array of indexes

        const int level[] =
        {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                1, 3, 2, 1, 2, 3, 3, 2, 1, 1, 2, 3, 2, 1, 2, 2, 3, 2, 1, 1, 1, 3, 2, 1, 2, 3, 3, 2, 1, 1, 2, 3, 2, 1, 2, 2, 3, 2, 1, 1,
        };

        // create the tilemap from the level definition

        TileMap map;

        if (!map.Load("tileset.png", sf::Vector2u(40, 40), level, 40, 30))
                return -1;

        //run the main loop

        while (window.isOpen())
        {
                // handle events

                sf::Event event;

                while (window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                window.close();
                }

                float elapsedTime = clock.restart().asSeconds();
                sf::String str(ToString(elapsedTime));
                text.setString(str);

                // draw the map

                window.clear();
                window.draw(map);
                window.draw(text);
                window.display();
        }

        return 0;
}

 

I'm drawing the map bigger than the screen because i wanted to include scrolling later but even after i shorten the map i get the same prblem

3
Graphics / Re: Framerate drops to 11fps when I draw a tilemap
« on: November 11, 2013, 03:01:17 pm »
I'm using Widows 7
My graphics card is Mobile Intel (R) Express Chipset Family
I'm using SFML 2.1 the latest stable version
I'm using the dynamic library
My RAM is 2 gig

4
Graphics / Framerate drops to 11fps when I draw a tilemap
« on: November 11, 2013, 02:35:46 pm »
Hi

I went to the tutorials section of SFML 2.1 and in the "Designing your own entities with vertex arrays" tutorial they demonstrate how to create and draw a tilemap. So I implemented it exactly as it is. Changed nothing. But when I draw the framerate drops to 11fps. Has anyone else ecountered a problem where the framerate droped? I set the screen to 800x600 and the bigger the screen the worse the framerate drop. If you experienced this, how did you resolve it?

5
General / Re: [SOLVED]Loading a texture using Physfs
« on: October 18, 2013, 10:44:22 pm »
Noted. This I way much better than the nothing I was going on. Will make the necessary adjustments... thank you again

6
General / Re: Loading a texture using Physfs
« on: October 18, 2013, 08:58:16 pm »
omg... it is that easy?? thank you kind sir!

7
General / [SOLVED]Loading a texture using Physfs
« on: October 18, 2013, 06:59:48 pm »
I'm a noob so forgive me if this question has already been asked. Suppose I have a texture sprite.png in a zip file myZip.zip and I wanna grab it using Physfs and load it into a sf::Texture. Is this possible? if so, which Physfs function does this?

Pages: [1]