Rendercam - Universal Camera Library

Hello @ross.grams. First of all Rendercam is great. Thank you, I love it.

I would like to use a shader with it. Nothing fancy. Lets say Grading (
Looks like it is possible. It “looks” (not sure if it works correct and efficient) fine until I resize the window. I don’t know much about the shaders but I guess setting view and projection cause a problem.

How can I handle the update correctly with Rendercam?

function update(self)
	-- Set view and projection with latest matrices calculated by the module

	-- Set viewport (x and y will be zero unless using a fixed aspect ratio)
	render.set_viewport(vp.x, vp.y, vp.width, vp.height)

	-- ** Render Target
	-- GUI Rendering

	-- ** Disable Render Target

	render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color}) 

	render.set_viewport(vp.x, vp.y, vp.width, vp.height)

	render.enable_texture(0,, render.BUFFER_COLOR_BIT) 


Thanks Selim! I’m glad this is making life easier for some people!

When you create your render target you give it color_params and depth_params tables, and both of these contain width and height values. Those need to be updated if the window changes size. I’m definitely not an expert on this and it’s been a while since I messed with render targets, but the way I did it last time was to delete and recreate the render target with the new width and height. However, there is a render.set_render_target_size function which sounds like it should do the trick without any rigmarole (but I haven’t tried it).

I will take a closer look at this tomorrow and make an example project for you, if you don’t figure it out first.


Thank you @ross.grams. Looks like “render.set_render_target_size” do the trick :slight_smile:
But if it’s not too much trouble, I love to see your example for better understanding.

Some results…

Terrible bloom:

Color grade:




Love the gfx!


Thank you @britzl
Still got lots of things to do :expressionless:


Nice! Looks cool.

Here’s my little demo project: (Also a “technical demo” for @sven, for my lighting and line-of-sight setup. A follow-up for that Simple 2D Lighting thread.)
-original link removed- (it crashed everywhere except on windows)
Updated working project link: (432.1 KB)


I’m getting the following error on OSX

WARNING:GRAPHICS: ERROR: 0:43: ‘’ does not operate on ‘vec4’ and 'int’
ERROR: 0:45: '
’ does not operate on ‘int’ and ‘vec4’

Changing from int to float (2->2.0 and 4->4.0) on line #43 and #45 in render_target.fp solves the above problems but results in a crash:

ERROR:GRAPHICS: gl error 1282: invalid operation


Ach, yeah sorry, I’m not as careful as I should be about keeping numbers floats instead of ints in shaders. On windows it doesn’t seem to care at all. But it still crashes for you after that’s fixed, eh? That’s a problem . . . A google search for that error didn’t turn up anything specific, though maybe some relation to reading multiple textures . . . It’s a pain that I don’t get these errors myself. Does Defold use different OpenGL versions based on the system?

1 Like

It does follow different shader rules that are inherent on different platforms.

You should begin to release versioned releases on Github for Rendercam as it becomes widely adopted.


Maybe @Sven can spot what’s wrong?

1 Like

@Pkeod Good to know. I don’t suppose there’s convenient documentation on the differences? Yeah, I’ve planned to switch to versioned releases but haven’t gotten to it yet. It turns out, releasing a library for public use comes with some maintenance headaches! (Of course, this little demo doesn’t actually have much to do with Rendercam.)

@britzl OK, thanks for helping debug this. I did try a web build, and that turned up some slightly more informative errors, though I haven’t been able to track down the causes yet:

Regarding the second and third errors, my render targets are set to render.WRAP_CLAMP_TO_EDGE.

I will keep looking into it in a little while.

1 Like

Well I’m stupid. My render targets were set up with the Clamp to Edge mode in the render script, but the samplers on the material were still set to Repeat. Fixing that solved the “active texture is ‘incomplete’” errors on web. Interestingly, if I only used one render target it was fine, but with two I got that error about each texture.

@britzl Can you try this version to see if it works on OSX? Thanks!
-link removed- (It didn’t. See below for a working version)

I’m still not sure what’s causing the “Error: WebGL warning: uniform4fv: Function used differs from uniform size: 16” on web, but I know it’s coming from one of my materials, and I can’t see that it breaks anything. I will look more tomorrow.


Crashed on macOS.
ERROR:GRAPHICS: gl error 1282: invalid operation
Assertion failed: (0), function SetConstantV4, file …/src/opengl/graphics_opengl.cpp, line 1346.


Thanks Dmitriy!

OK, hopefully the 3rd time’s the charm. I cleared up the other error I got on web, and it sounds like the same error as on MacOS (stupid again, I had extra stuff in my vertex shader). (432.1 KB)

1 Like

Works on macOS & iOS. Nice example, btw.

1 Like

Yess! Thanks again! Now I know to be much more careful with my shader code in the future (and test web builds for errors). If you didn’t figure it out already, you can move the “character” around with the arrow keys.


It worked :rofl:
This is so educational, thank you.


Hi Everyone,

@ross.grams, thanks for Rendercam, it works great!

Is anyone seeing the following issue when using the rendercam.pan() function with something like:
rendercam.pan(20, 0)

ERROR:SCRIPT: /rendercam/rendercam.lua:186: bad argument #1 to '__add' (vector3 expected, got nil)
stack traceback:
	[C]: in function '__add'
	/rendercam/rendercam.lua:186: in function 'pan'

All the other functions seem to work ok, eg:
rendercam.shake(2, 10)

all do what they’re supposed to when used at exactly the same code point. Apologies if I’m missing something.

1 Like

Hmm, that’s strange. Argument #1 is the stored local position of the camera, I’m not sure how that would be nil. But obviously there’s something I didn’t anticipate going on. Can you share your project?

Thanks for the reply.

Sure, do you need to PM me you email address for me to share?

I can replicate this in the Rendercam example you provided with the addon also. Adding this to the end of the init() function in main_example.script creates the same error. The zoom, shake and recoil all work:

rendercam.pan(10, 0) -- Doesn't work
-- rendercam.zoom(-40) --Works
-- rendercam.shake(10, 10) --Works
-- rendercam.recoil(vmath.vector3(40, 0, 0), 2) --Works	

Defold prints a load more errors in the example after the same error I get though so scroll up! :slight_smile:

Best regards

1 Like