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

Author Topic: Semi technical question about loading a sprite from a file.  (Read 1803 times)

0 Members and 2 Guests are viewing this topic.

Vect0rZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Semi technical question about loading a sprite from a file.
« on: August 15, 2014, 04:53:40 pm »
Hey guys,

If I have used the method to load a sprite from file, does the sprite writes itself in to the memory after it's being loaded?
Or when running the *.exe file it reads them from the file and there is no need for it to write itself in to the RAM or VRAM?

Thanks in advance, and sorry for the bad structure of my question.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Semi technical question about loading a sprite from a file.
« Reply #1 on: August 15, 2014, 05:06:43 pm »
You can't load a sprite from a file. ::)
Are you talking about an image?

SFML always loads an image via sf::Image, which uses stb_image to load the image data from your harddisk to the memory (RAM). Then if you use an sf::Texture it will load the memory into the VRAM where you can then use it with an sf::Sprite to render to your screen.

Side note: An sf::Sprite is just a lightweight class, with which you can easily position the texture data on your screen. It has essentially nothing to do with the actual image information.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Vect0rZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Semi technical question about loading a sprite from a file.
« Reply #2 on: August 15, 2014, 05:15:20 pm »
Thank you for the reply.

About the sprite: Yes, my bad, I was speaking about Texture.

I understand what you mean. I asked because let's imagine the scenario if a level have for example 90 items wich have Textures (pngs) wich are 1mb. That makes 90mb and it sure seems alot. Or is it normal?




eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Semi technical question about loading a sprite from a file.
« Reply #3 on: August 15, 2014, 05:50:19 pm »
It will be even more than 90 MiB because while a PNG is a compressed image the information loaded into VRAM is uncompressed. ;)

As for the size, 90 MiB isn't very large. Just think of the AAA games and their piles of textures etc. A "normsl" dedicated GPU usually ships with at least 1 GiB of VRAM. And at last think of a uncompressed HD image, it's by itself already roughly 8 MiB (1920*1080*4*1byte). ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Vect0rZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Semi technical question about loading a sprite from a file.
« Reply #4 on: August 15, 2014, 06:25:05 pm »
Thanks again =]]

Sorry for my endless questions, but let me ask something else,

Is it normal if I do Tile maps this way? Like every tile is a textured sprite, and position a little less than thousand of those on the screen? Or use the Quads and primitives as in the SFML Documentation tutorial?

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Semi technical question about loading a sprite from a file.
« Reply #5 on: August 15, 2014, 07:12:02 pm »
you usually put all the tiles in a single image (a tileset), and assign a single segment of it to each tile in the game.
the tiles can be made each one of a sprite (which becomes very slow). note that you can have many sf::Sprites using the same sf::Texture.  or you can use a VertexArray, which is the best option in my opinion.
also, it's a good idea not to draw things that are out of your view.
Visit my game site (and hopefully help funding it? )
Website | IndieDB