I’ve been working on a project in 16:9, but now I have a 1920 x 1200 computer, which is obviously not the same aspect ratio. I’ve been using rendercam for a long time for that project, and now that it’s no longer compatible with modern versions of Defold, I’ve replaced it with the builtin cameras.
However, while using defOS fullscreen, it adjusts the world to fit in the screen/stretches the view to fit in the screen. I’d prefer it to add black boxes, keeping everything in view within the same aspect ratio as windows (16:9). Is there a way for me to do this or do i have to use something like Orthographic camera? Thanks.
If you’re open to learning about editing a .render_script, then you have plenty of options; between that & DefOS, you can ensure the window works just the way you want it to.
Whether you’re interested in that or not, this manual is what you want.
Nevermind. I interpreted a minor “vocabulary” change in the render scripts as a complete overhaul of the basic render script function because of much abstraction there is in the new one, but I could get the old script running my making a couple of changes (bunch of things that were under render got moved to graphics, etc. If someone needs a suitable script for rendercam to fix any broken old projects, hopefully this will work for you.
local rendercam = require "rendercam.rendercam"
local vp = rendercam.viewport
local IDENTITY_MATRIX = vmath.matrix4()
local CLEAR_COLOR = hash("clear_color")
local WINDOW_RESIZED = hash("window_resized")
local UPDATE_WINDOW = hash("update window")
local function update_window(self)
rendercam.update_window(render.get_window_width(), render.get_window_height())
self.gui_proj = vmath.matrix4_orthographic(0, rendercam.window.x, 0, rendercam.window.y, -1, 1)
end
function init(self)
self.tile_pred = render.predicate({"tile"})
self.gui_pred = render.predicate({"gui"})
self.text_pred = render.predicate({"text"})
self.model_pred = render.predicate({"model"})
self.particle_pred = render.predicate({"particle"})
self.clear_color = vmath.vector4(0)
self.clear_color.x = sys.get_config_number("render.clear_color_red", 0)
self.clear_color.y = sys.get_config_number("render.clear_color_green", 0)
self.clear_color.z = sys.get_config_number("render.clear_color_blue", 0)
self.clear_color.w = sys.get_config_number("render.clear_color_alpha", 0)
rendercam.configWin.x = render.get_width(); rendercam.configWin.y = render.get_height()
rendercam.update_window_size(render.get_window_width(), render.get_window_height())
update_window(self)
end
function update(self)
render.set_depth_mask(true)
render.set_stencil_mask(0xff)
render.clear({[graphics.BUFFER_TYPE_COLOR0_BIT] = self.clear_color, [graphics.BUFFER_TYPE_DEPTH_BIT] = 1, [graphics.BUFFER_TYPE_STENCIL_BIT] = 0})
render.set_viewport(vp.x, vp.y, vp.width, vp.height)
render.set_view(rendercam.calculate_view())
render.set_projection(rendercam.calculate_proj())
-- Sprite and particle rendering
render.set_depth_mask(false)
render.disable_state(graphics.STATE_DEPTH_TEST)
render.disable_state(graphics.STATE_STENCIL_TEST)
render.enable_state(graphics.STATE_BLEND)
render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA)
render.disable_state(graphics.STATE_CULL_FACE)
render.draw(self.tile_pred)
render.draw(self.particle_pred)
-- Model rendering
render.enable_state(graphics.STATE_BLEND)
render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA)
render.enable_state(graphics.STATE_DEPTH_TEST)
render.enable_state(graphics.STATE_CULL_FACE)
render.set_depth_mask(true)
render.draw(self.model_pred)
-- Debug rendering - physics debug, draw_line
render.disable_state(graphics.STATE_DEPTH_TEST)
render.disable_state(graphics.STATE_CULL_FACE)
render.draw_debug3d()
-- GUI Rendering
render.set_viewport(0, 0, rendercam.window.x, rendercam.window.y)
render.set_view(IDENTITY_MATRIX)
render.set_projection(self.gui_proj) -- gui_proj only calculated on update_window
render.enable_state(graphics.STATE_STENCIL_TEST)
render.draw(self.gui_pred)
render.draw(self.text_pred) -- Includes debug text from "draw_text" messages.
render.disable_state(graphics.STATE_STENCIL_TEST)
end
function on_message(self, message_id, message)
if message_id == CLEAR_COLOR then
self.clear_color = message.color
elseif message_id == WINDOW_RESIZED then -- sent by engine
update_window(self)
elseif message_id == UPDATE_WINDOW then -- sent by rendercam when a camera is activated ("window_resized" engine message requires data)
update_window(self)
end
end
I had some personal modifications for a project and tried to remove them the best I could
Great! That’s basically what I suggested. Start editing the .render_script.
I feel obligated to add that the author of Rendercam has said in his own opinion that the code “should be rewritten from scratch”:
If all you want is the old Rendercam back, and nothing else from the render script, then changing only the bare minimum in Rendercam to get it to compile & work is still useful IMO. You might be the first person to post & share a fixed version, because I haven’t seen another.
What I would caution against is using it as a base to start learning how to modify or write your own .render_script. The current default render script is a better starting point for that kind of project.
I’ve been working with the render script and shaders for a bit, so I already got, I don’t understand everything obviously, I guess originally I was too lazy to figure out what was actually changed. The default render script was recently updated and looks a lot different, but the basis is basically the same. I only figured this out from playing around with Orthographic Camera and realizing its default render script is even more simple.
My biggest issue was that there wasn’t a way to maintain a 16:9 ratio when fullscreening with DefOS, but Rendercam automatically did it. But at this point, it was not really needed because Rendercam doesn’t obfuscate GUI elements that appear on the black boxes, so I had to take my own approach that would’ve worked with the normal camera anyways (creating a new gui material to layer on top of everything.) I may switch back to normal cameras if needed; I just needed this to revive an old project I hadn’t touched in months.