Target size

So, I´m pretty new at defold and I´m trying to adapt the size of the project in pixels to the actual size of the screen. Reading the API I found render.set_render_target_size() with an example of the precise line I need:

render.set_render_target_size(self.my_render_target, render.get_window_width(), render.get_window_height())

So, If I´m not mistaken (perhaps I am and that´s it), that line should be in the default.render_script, at the end of the init() section. But it throws an error:

Expected render targer as the second argument to render.set_render_target_size

The problem seems to be than the render target to resize is not well set, despite the error say second argument when it should be first because the second is a plain number. I tried passing “self”, “render”, “render_target” “render.RENDER_TARGET_DEFAULT”, but the same error is reached. What am I doing wrong?

Thx.

The render script can be a bit daunting at first but it will give much power.
In your case, I think it will be enough to send a couple of messages to it:

  • Setup your “design” resolution, let’s say 320x200, in project settings

  • Send a message to use fixed fit projection:
    msg.post("@render:", “use_fixed_fit_projection”, { near = -1, far = 1 })

  • Send a message to resize the window of your game (I’m using something arbitrary)
    msg.post("@render:", “resize”, {width = 1280, 720})

At this point the 320x200 will be scaled at best into the 1280x720 window. Don’t forget to set the texture filter if you’re dealing with pixel art.

2 Likes

Thanks for the guidelines but it will scale up the 320x200 render. My goal is to change the render to an actual 1280x720 pixels as for the example without scaling.

1 Like

render.set_render_target_size() is not what you want, that’s for something completely different.

If you set the display width/height to 1280x720 in your game.project, the game will start with a 1280x720 window, showing a 1280x720 area of your game world.

If you want to modify your render script, render.set_viewport sets the area inside the window that will be drawn to, and render.set_projection sets the area of the world that will be drawn.

1 Like

Ok, I´ll give a try to the viewport approach. :slight_smile:
But, since you say render.set_render_target_size() it´s for somenthing completely different… then what´s that for? :innocent:

Did setting the game.project settings not do what you want? It’s still not 100% clear what’s going wrong and what you are trying to do instead.


In the field of 3D computer graphics, a Render Target is a feature of modern graphics processing units (GPUs) that allows a 3D scene to be rendered to an intermediate memory buffer, or Render Target Texture (RTT), instead of the frame buffer or back buffer. This RTT can then be manipulated by pixel shaders in order to apply additional effects to the final image before displaying it.

Glossary of computer graphics - Wikipedia

In other words, you can use a render target to draw things to a texture, rather than directly to the “screen”. render.set_render_target_size() sets the dimensions of the render target texture.

1 Like

What do you mean exactly by this?

The default is for the render script to stretch the content from what you set as width and height in game.project to fit the actual screen size. We call this a stretch projection.

You can change this to instead show more of your game and keep graphics at 1:1 ratio. This is the fixed fit projection.

You can also let the render script keep the ratio at 1:1 and apply a zoom. This is the fixed projection.

Read about the different options here: The render pipeline in Defold

1 Like

Never mind, britzl. It was the result of a profound mistake. I was assuming a 2D canvas mode while defold is actually a full 3D stuff. :sweat_smile:

2 Likes

Ok, good that we cleared that up! Did you manage to get the result you were looking for?