Minimap tips, should I make a special camera? [SOLVED]

You need to have a custom render script. If you don’t already then copy the default.render_script and default.render from builtins and modify default.render so that it points to your copy of default.render_script instead of the one in builtins. Next change in game.project so that your copy is used. Add a print(“hello”) in the update() function to make sure it is running.

Next step is to modify the render script so that you do what @Ivan_Liljeqvist did. The part of the default render script that we are interested in looks like this (from the update function):

render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
render.set_view(self.view)

render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)

-- default is stretch projection. copy from builtins and change for different projection
--
render.set_projection(stretch_projection(-1, 1))

render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

This portion of code starts by setting the viewport to cover the entire screen, then sets a view and projection plus some state setup and at the end it draws the graphics.

What you want to do is to do this twice, but with different viewports. Like this:

 render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
render.set_view(self.view)

render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)

-- default is stretch projection. copy from builtins and change for different projection
--
render.set_projection(stretch_projection(-1, 1))

-- draw full screen first
render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

-- draw smaller version (15% of full size) at 10,10 
render.set_viewport(10, 10, render.get_window_width() * 0.15, render.get_window_height() * 0.15)
render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

For a very simple game this would be enough, but if you do a lot of complex rendering with expensive shaders it might be better to render to a render target once and then draw it twice (full screen and minimap). Although now that I think of it you probably want to draw the minimap with a simple shader if you use something more advanced when drawing fullscreen.

7 Likes