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

Pages: [1]
1
Graphics / Efficient sprite rendering?
« on: July 28, 2010, 08:01:05 pm »
Quote from: "Nexus"
Not directly related to your topic, but especially because you come from Java/C#: In C++, you have to free the memory you allocate dynamically. There is no garbage collector. So, each new must have a corresponding delete (the same applies to new[] respectively delete[]).

You could make your life a lot easier by using standard STL containers like std::vector. They manage the memory automatically, and you can just call comfortable member functions to insert/remove elements, get the size, iterate through all elements, and so on. ;)


Yeah getting the hang of interacting with memory more closely is definitely the hardest thing to adapt to. Was aware of the necessity of manually deleting but it is something I know I'll forget to do far too many times, so cheers. :)

2
Graphics / Efficient sprite rendering?
« on: July 28, 2010, 05:50:13 pm »
Built 2.0 dll's and fps up to ~80 for 200x200 grid. So thanks :).

3
Graphics / Efficient sprite rendering?
« on: July 28, 2010, 05:01:39 pm »
Ok, will build 2.0 and see if it improves anything. Thanks Laurent, appreciate the quick response.

4
Graphics / Efficient sprite rendering?
« on: July 28, 2010, 04:49:34 pm »
Hi there, found a few posts on this topic but nothing with the same issue as mine, so thought I'd start a new thread.

I'm reasonably new to C++, although I have a lot of experience with Java/C#. I've gone through the tutorials and have a pretty good handle on pointers/references etc. I'm attempting a learn by doing approach with a project using sfml, but I'm finding the sprite drawing routines to not be as efficient as I would have hoped. I'm sure it's probably something in my code so I was wondering if someone wouldn't mind telling me if I'm doing something wrong.

None of this is final architecture, more of a test run for rendering tiles. If I make an array of 200x200 sprites, (all with the same image instance I think) and draw I get around 10 fps. I'll put in some clipping or whatever to cut out the offscreen ones but my concern is that the same app in xna doing 200x200 gets around 50 fps. Is this something I'll have to live with or is there something I'm doing that's drastically wrong?

Sprite Creation Code:
Code: [Select]
sf::Sprite ** tileMap;
tileMap = new sf::Sprite * [tileCount];
for(int i = 0; i < tileCount; i++)
{
tileMap[i] = new sf::Sprite [tileCount];
}
string strPath = "content" + string(PATH_SEPERATOR);
static sf::Image imageTest;
imageTest.LoadFromFile(strPath + "template.PNG");
imageTest.SetSmooth(false);

for(int i = 0; i < tileCount; i++)
{
for(int j = 0; j < tileCount; j++)
{
sf::Sprite sprite;
sprite.SetImage(imageTest);
tileMap[i][j] = sprite;
}
}


Drawing Code:
Code: [Select]
for(int i = 0; i < tileCount; i++)
{
for(int j = 0; j < tileCount; j++)
{
app.Draw(tileMap[i][j]);
}
}


Obviously if I cut out the app.Draw call it runs at 2000fps or something similar. It's definitely the drawing call that's slowing everything down.

Edit: All with SFML 1.6 and yes I'm testing fps with release build.

Pages: [1]