Madour / LDtkLoader

A C++11 loader for levels and tile maps created with LDtk (Level Designer ToolKit)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why do the examples use render textures?

derpyzza opened this issue · comments

hi there! in all the examples, the tilemaps are rendered on a render texture, which is then blown up to the screen's size.
but, why is it done like that?
why not just blow up the textures themselves in code, rather than drawing everything to a render texture, and then drawing that to the screen. im quite confused by this, and would love an explanation! thanks :D

Hi ! I am not sure I understood the "why not just blow up the textures themselves in code" question, but about the render texture, there are multiple advantages to drawing the map on an off screen render texture first before drawing it to the window :

It helps getting rid of visual artifacts (like vertical or horizontal white line) that can appear when scrollling the map.

It also allows to apply post process effects on the whole map.

And of course, prerendering the map on a render texture allows to draw it in a single draw call (instead of one per tile) and results most of the time in better performance (well, at least it when you have big maps)

ohhhhhh that makes so much sense! i've always wondered what people meant by drawing a map in one draw call, it always seemed impossible to me, thanks!
also, by why not just blow up the textures themselves in code, i meant instead of rendering everything to a render texture and making it fit the screen, just scaling up every individual tile texture to fit the screen

Well, if your tile map changes a lot (like in a terraria like game), you can probably batch draw only the visible tiles instead of using a render texture.

In the examples, I prerender to an offscreen texture because the map doesn't change, if we had animated or interractable tiles then drawing the visible tiles one by one can be a solution :)

(I'll let you close the issue if your question is answered)

ah, i understand now! thank you :D
i think i can close this issue now, right? im not sure how github works 😅