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

#1

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?

0 Likes

#2

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

#3

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

0 Likes

#4

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

#5

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
0 Likes

#6

And how do you create self.render_target?

0 Likes

#7
-- 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

0 Likes

#8

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

2 Likes

#9

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:

0 Likes

#10

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

0 Likes

#11

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

3 Likes