Render.enable_render_target() seems to not work (and is not in the API)

I came across a confusing thing in the Color grading tutorial - neither:

render.enable_render_target(self.render_target) --nor:
render.disable_render_target(self.render_target)

are no longer in the API, although those functions are mentioned even in the code examples in the API. I must have missed that change, but I can’t find when and why it happened.

Nevertheless, I tried to use those functions, but it is not working, here’s a small repro:

Grade.zip (25.8 KB)

So how can we now properly enable a render target?

I believe that tutorial is outdated. I saw on Slack that someone was going to create a PR to fix it.

The function you are looking for is render.set_render_target(target, [options]) and render.set_render_target(render.RENDER_TARGET_DEFAULT).

1 Like

It was me :smile:
Thank you! I’ll check it and prepare a PR :wink:

The functions were deprecated in 1.2.139: Defold 1.2.139 has been released

(although I still believe they are exposed in the API but reference documentation has been removed)

1 Like

Changing enable/disable render target to set_render_target as you proposed still didn’t help in the project I uploaded - the screen is still black :confused:

function update(self)
   render.set_render_target(self.render_target)

     ... -- drawing everything like in default script

   render.set_render_target(render.RENDER_TARGET_DEFAULT)

-- up to this point everything is drawn to the render target only

    -- 1) clear the frame buffer
    render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color})
    -- 2) fill the window with a viewport (set viewport to match window)
    render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
    -- 3) set the view to the identity matrix
    render.set_view(vmath.matrix4())
    -- 4) set texture slot 0 to the color buffer of the render target
    render.enable_texture(0, self.render_target, render.BUFFER_COLOR_BIT)
    -- 5) draw graded predicate
    render.draw(self.grade_pred)
    -- 6) disable texture slot 0
    render.disable_texture(0)
end

And how do you create self.render_target?

-- create a render target
local color_params = { format = render.FORMAT_RGBA,
                        width = render.get_width(),
                       height = render.get_height() }
local target_params = { [render.BUFFER_COLOR_BIT] = color_params }
self.render_target = render.render_target("original", target_params)

in init

I was test this a few days ago for faking light :crazy_face:
Attached…grade.zip (636.9 KB)

2 Likes

Thanks! :smiley: I will try to figure out what is wrong in my project. I see that you use enable/disable render target anyway, so maybe that’s a way to go :confused:

1 Like

Actually I didn’t know it was deprecated :frowning: and it works :slight_smile: But no, we shouldn’t use it anyway.

Don’t use deprecated functions. They’re for backwards compatibility, and are thus unsupported. That’s why they’re not documented anymore.

4 Likes

As I’m now learning OpenGL more thoroughly and revising the documentation, especially the tutorials that are outdated, few things already came up. One is with render.enable_target() which was deprecated and actually the topic should have been followed up, thus I’m working on a PR to the tutorial and also the documentation - in some code examples there are still deprecated functions used :confused:

Second thing is that Grading tutorial stating in chapter “Drawing to an off-screen buffer”:

  1. All original drawing code in update() is left as is, apart from the viewport which is set to the render target’s resolution.

and the code responsible for this is:

 render.set_viewport(0, 0, render.get_width(), render.get_height()) -- <2>

And my problem is that according to the API render.get_width() and render.get_height() are returning a width and height (respectively) from the game.project:

Returns the logical window width that is set in the “game.project” settings.

Is it correct or is there something wrong and a function render.get_render_target_width() should be used?

It looks like the width and height of the render target are set to render.get_width() and render.get_height() so I guess in that case it doesn’t matter if render.get_width() or render.get_render_target_width() is used?

1 Like

In that case yes, but when window size is changed, is it that when I use an incorrect viewport, I could see some more/less of the world in a screen? It is somehow strange to understand when combined with projection :sweat_smile:

Also replacing render.enable_render_target() with render.set_render_target() is ok, but there is no replacement function for render.disable_render_target() (which is also not in the API) and it seems, like without disabling it, everything fails - is it ok guys?

And there is an example of this in the API docs (as of right now anyway).

3 Likes

Oh, right :smiley: Thank you for clarification!

2 Likes

This is my first PR to the engine, so let me know if everything is ok! :smiley: The change regards replacing enable_render_target and disable_render_target with set_render_target equivalents. It is only in comments used to generate API documentation for render :wink:

1 Like

Looks good. Thank you for the contribution!

1 Like