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

Author Topic: Looking tips, for draving tiled background  (Read 4647 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Looking tips, for draving tiled background
« on: January 09, 2013, 10:37:57 pm »
Hello.
What i have problem is, that i draw 32x32 tiles on 1024x768 screen and i get high CPU usage during this operation. The obvious cause is that i call sf::RenderWindow::draw() function too many times (768 times to be exact).
By commenting out the sf::RenderWindow::draw() calls decrease CPU usage from 60-70% down to 10%.

I currently conflict this problem by decreasing the amount of tiles i draw to screen.
Any suggestions, tips?
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Looking tips, for draving tiled background
« Reply #1 on: January 09, 2013, 10:59:00 pm »
Compiler version? SFML version?
This has to do with graphics, so next time please choose the right section post it in. ;)

Did you make your benchmarks debug or release mode? Because in the end what's important is the release mode.

A quick search in the forum would've gotten you to topics like:
http://en.sfml-dev.org/forums/index.php?topic=10205.0
http://en.sfml-dev.org/forums/index.php?topic=9846.0
...

That is use a sf::VertexArray.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Looking tips, for draving tiled background
« Reply #2 on: January 09, 2013, 11:15:15 pm »
https://github.com/SFML/SFML/wiki/Source%3A-TileMap
Quote
Compiler version?
For non-troubleshooting question? Seriously?
« Last Edit: January 09, 2013, 11:17:22 pm by FRex »
Back to C++ gamedev with SFML in May 2023

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Looking tips, for draving tiled background
« Reply #3 on: January 09, 2013, 11:23:21 pm »
Compiler version? SFML version?
This has to do with graphics, so next time please choose the right section post it in. ;)

Did you make your benchmarks debug or release mode? Because in the end what's important is the release mode.

A quick search in the forum would've gotten you to topics like:
http://en.sfml-dev.org/forums/index.php?topic=10205.0
http://en.sfml-dev.org/forums/index.php?topic=9846.0
...

That is use a sf::VertexArray.
Oh silly me...
Using SFML 2.0 with Visual studio 2010. yesterday i used CMake to build the dll files.
The fps i get is
470 - 480 on release
270 - 280 on debug
with 32x24 tiles per second

What i was asking for any cool ideas how not to call sf::RenderWindow.draw() function so many times.

What i am trying to achieve is decrease CPU usage. Even at the cost of memory.

Google hates me. How do i check what version my compiler is in Visual studio 2010?
« Last Edit: January 09, 2013, 11:25:44 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Looking tips, for draving tiled background
« Reply #4 on: January 09, 2013, 11:27:57 pm »
The fps i get is
470 - 480 on release
270 - 280 on debug
with 32x24 tiles per second
Then you don't have a performance issue, so I understood you wrong. :)

What i was asking for any cool ideas how not to call sf::RenderWindow.draw() function so many times.
Did you look into the posted links above?
Have you checkout what 'sf::VertexArray' is?
Or did you just ignore all that?

What i am trying to achieve is decrease CPU usage. Even at the cost of memory.
It's simply to fix, just limit your framerate. You screen anyways can't handle 300-400 images per second and thus the cycling is just a waste of power. ;)
This can be achieve either with window.setFramerateLimit(60) or window.setVerticalSync(true), but you shouldn't mix them!
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Looking tips, for draving tiled background
« Reply #5 on: January 09, 2013, 11:46:13 pm »
The fps i get is
470 - 480 on release
270 - 280 on debug
with 32x24 tiles per second
Then you don't have a performance issue, so I understood you wrong. :)

What i was asking for any cool ideas how not to call sf::RenderWindow.draw() function so many times.
Did you look into the posted links above?
Have you checkout what 'sf::VertexArray' is?
Or did you just ignore all that?

What i am trying to achieve is decrease CPU usage. Even at the cost of memory.
It's simply to fix, just limit your framerate. You screen anyways can't handle 300-400 images per second and thus the cycling is just a waste of power. ;)
This can be achieve either with window.setFramerateLimit(60) or window.setVerticalSync(true), but you shouldn't mix them!
I was checking documentation and what it actually is and does(refearring to 'sf::VertexArray'), its just a thing i was looking for.
And for performance issues, well i ... uh, depends what performance issues is defined as, and i have one am trying to improve/reduce.

I was just looking for way to decrease CPU usage. So weaker devices can handle my application.

Thank on help.
« Last Edit: January 09, 2013, 11:47:53 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Looking tips, for draving tiled background
« Reply #6 on: January 09, 2013, 11:55:42 pm »
uh, depends what performance issues is defined as, and i have one am trying to improve/reduce.
You have a performance issue, if the CPU and the GPU can't process the given data fast enough, thus you don't have a performance issue, because you're FPS are around 300-400 and the usual lower bound is 60 fps.
Running at such high FPS lets the CPU go crazy and thus you get to see a higher load.

By limiting the framerate to 60 fps or similar, you'll give the CPU time to breath and the load can go down to less than 1% CPU usage.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Looking tips, for draving tiled background
« Reply #7 on: January 10, 2013, 09:42:10 am »
Thanks on the information   ;D.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Looking tips, for draving tiled background
« Reply #8 on: January 10, 2013, 03:22:56 pm »
By any chance got minimal code of doing sf::Vertex or sf::VertexArray to draw sf::Texture or part of sf::Texture to sf::RenderWindow?


EDIT 1:
When using
sf::Vertex vertices[] =
    {
        sf::Vertex(sf::Vector2f(  0,   0), sf::Color::Red, sf::Vector2f( 0,  0)),
        sf::Vertex(sf::Vector2f(  0, 100), sf::Color::Red, sf::Vector2f( 0, 10)),
        sf::Vertex(sf::Vector2f(100, 100), sf::Color::Blue, sf::Vector2f(0, 10)),
        sf::Vertex(sf::Vector2f(100,   0), sf::Color::Red, sf::Vector2f(10,  0))
    };

What is third argument for? in documentation it says it texture coordinates and changing the number does not provide visible result. What is 3rd argument for? and what does it modify.
« Last Edit: January 10, 2013, 03:31:11 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Looking tips, for draving tiled background
« Reply #9 on: January 10, 2013, 05:02:25 pm »
Do you draw with texture? Also, i think 3rd vertex should have 10:10 texcoords, not 0:10.

Texture coords are useful for spritesheets.
« Last Edit: January 10, 2013, 09:04:00 pm by krzat »
SFML.Utils - useful extensions for SFML.Net

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Looking tips, for draving tiled background
« Reply #10 on: January 10, 2013, 08:54:23 pm »
You need to draw with either of two draws in renderwindow but pass texture pointer as last argument, read through wiki carefuly, it's just few pages worth of text.
Back to C++ gamedev with SFML in May 2023