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

Author Topic: Good praxis for editing and drawing  (Read 2452 times)

0 Members and 1 Guest are viewing this topic.

Karleon

  • Newbie
  • *
  • Posts: 18
    • View Profile
Good praxis for editing and drawing
« on: March 20, 2013, 01:25:22 pm »
Hello,


I have several questions about efficency and praxis in general. I know (more or less) how to use the different classes, but i'm not sure about what kind of component to use for different tasks.
(SFML 2.0)

  • Dynamic FOV:
Please excuse my cruce and inaccurate MS paint drawins :)

I have the scenario (1), and I draw the shadows the scenario would cast (2), then draw the shadows over the scenario (3).
The shadows (2) have to be redrawn each time the light source moves, which could be every game cicle. This means that I need to draw over a texture and then draw the texture over the screen.

Which classes fit this task. Currently I'm using a RenderTexture and a Sprite that share the same texture. I draw the primitives over the renderTexture, and then draw the Sprite over the window.
Is there a better class for this kind of task?

  • Map representation:
My map is tile based. Currently, when I load the map, I draw all the tiles over a RenderTexture, then load it's texture into a sprite. I use this sprite during the execution to draw the map in the screen. This is ok for a small map, but if the map grows bigger this will turn into a problem, or so I think.
I was considerng having a matrix of textures, of 500x500 pixels, and load the sections as you advance and unload them as you leave them behind.
Is there a better approach for this matter? I keep reading about Vertex Arrays, but I fail how they are helpful in this scenario (related to last point).

  • Image manipulation:
As a rule of thumb, when I want to manipulate an image regulary and display it, I make a RenderTexture and a Sprite share a texture, and use the RenderTexture to draw on it, and the Sprite to display it on screen.
I have seen the Image class, but I'm not really sure about the difference between it and the RenderTexture class. What kind of task do they fit better?

  • Vertex Arrays and ConvexShapes:
I'm drawing the shadows mentioned in the first point ConvexShapes. I have seen the VertexArray class, and using the trianglestrip primitive type could be used to draw the shadows, and it would let me draw non convex shadows in one go, but besides that I don't really see an advantage on using VertexArrays.
Are ConvexShapes heavier than Vertex Arrays?
[/list]


I bet most of my questions are dumb/basic, but until now I have just blited my way through using the allegro library for basic stuff ;D



Thanks for the help!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Good praxis for editing and drawing
« Reply #1 on: March 20, 2013, 01:45:03 pm »
Quote
Which classes fit this task. Currently I'm using a RenderTexture and a Sprite that share the same texture. I draw the primitives over the renderTexture, and then draw the Sprite over the window.
Is there a better class for this kind of task?
No. Since these classes are designed to do exactly what you want, why would there be other (and why "better"? what's wrong?) classes that do the same thing?

Quote
Is there a better approach for this matter? I keep reading about Vertex Arrays, but I fail how they are helpful in this scenario (related to last point).
Vertex arrays are the best solution. What's your problem with them?

Quote
I have seen the Image class, but I'm not really sure about the difference between it and the RenderTexture class. What kind of task do they fit better?
sf::Image is an array of pixels. You can only do basic things with it (set pixel, copy pixels from another image, ...). And it's super slow.
sf::RenderTexture is a render-target where you can draw. It's like an intermediate layer in the rendering process, you use it when you have extra stuff to do to the result before drawing it to the final window.

Quote
Are ConvexShapes heavier than Vertex Arrays?
Yes. But as long as you have no problem with sf::ConvexShape then you're not forced to change, use what works for you ;)
Laurent Gomila - SFML developer

Karleon

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Good praxis for editing and drawing
« Reply #2 on: March 20, 2013, 04:01:59 pm »
Quote
Why would there be other (and why "better"? what's wrong?) classes that do the same thing?
I was just wondering if there was another class that would be faster of less heavy weight that this one.


Quote
Vertex arrays are the best solution. What's your problem with them?
Currently I load my map in the following way:
1)I load my tileset into a Sprite
2)Create a RenderTexture
3)Iterate through my map info (a 2d array that contains integers representing each cell's type)
      3a) Move the textureRect in the sprite to hold the desired tile depending on the type of cell read
      3b) Move the position of the sprite to the position of the cell
      3c) Draw the sprite over the RenderTexture

This way I have a Texture that has the map representation, so it can be drawn into one big chunk instead of drawing each cell individually.

I say that i don't see how the VertexArray can help here because, intuitively, I think it would be faster to draw one big prerendered image, than composing the image from small chunks using a VertexArray.

Of course I could be wrong, but thats why I'm asking here on the forum about it :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Good praxis for editing and drawing
« Reply #3 on: March 20, 2013, 04:15:11 pm »
Don't forget that your graphics card can process hundreds of thousands triangles per second. So even if you end up with 100000 quads in your vertex array, it's still very light for the graphics card. Here the most important is to reduce the number of draw calls, and with either sf::VertexArray or sf::RenderTexture you end up with 1 call for your whole map. Except that with sf::RenderTexture you have some constraints, not with sf::VertexArray.
Laurent Gomila - SFML developer

Karleon

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Good praxis for editing and drawing
« Reply #4 on: March 20, 2013, 04:29:01 pm »
I see.

I guess the limitations of using a RenderTexture is the bigger the map grows, so does it's texture (which i guess can give you some problems depending on your graphic card), while the VertexArray will be using the same small tileset no matter how big the map is.

If that's the case then it surelly sounds like the best option!




Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Good praxis for editing and drawing
« Reply #5 on: March 20, 2013, 04:31:45 pm »
Quote
I guess the limitations of using a RenderTexture is the bigger the map grows, so does it's texture (which i guess can give you some problems depending on your graphic card), while the VertexArray will be using the same small tileset no matter how big the map is.
Absolutely.
Laurent Gomila - SFML developer

 

anything