Lost my physics debug draw, what am I missing?


#1

My render script is an amalgamation of following the grading tutorial and implementing rendercam. Plus some screen size handling.

In any case, I can’t see any debug physics drawn to screen. The render part of Defold is not my strong suit, so I wonder if anyone could take a look and see if there’s something obvious I’m missing that could be the culprit?

My render’s update:

function update(self)
  render.enable_render_target(self.target)
  -- Set view and projection with latest matrices calculated by the module
  render.set_view(rendercam.calculate_view())
  render.set_projection(rendercam.calculate_proj())
  -- 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.set_depth_mask(false)
  render.set_stencil_mask(0xff)
  render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color,
    [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

  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)

  render.draw(self.tile_pred)
  render.draw(self.tilemid_pred)
  render.draw(self.particle_pred)
  render.draw(self.tiletop_pred)
  render.draw(self.particletop_pred)

  render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
  render.enable_state(render.STATE_CULL_FACE)
  render.enable_state(render.STATE_DEPTH_TEST)
  render.set_depth_mask(true)
  render.draw(self.model_pred)
  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.disable_state(render.STATE_CULL_FACE)
  render.disable_state(render.STATE_DEPTH_TEST)
  render.enable_state(render.STATE_STENCIL_TEST)
  render.draw(self.gui_pred)
  render.draw(self.text_pred)
  render.disable_state(render.STATE_STENCIL_TEST)

  render.set_depth_mask(false)
  render.draw_debug2d()

  render.disable_render_target(self.target)

	render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color,
    [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

  render.set_view(vmath.matrix4())
  render.set_projection(vmath.matrix4())
  render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())

  render.enable_texture(0, self.target, render.BUFFER_COLOR_BIT)
  render.draw(self.grade_pred)
  render.draw_debug2d()
  render.disable_texture(0, self.target)
end

Yes I’m aware I have two debug2d calls there… :confused:


#2

Actually, render.draw_debug3d() is the one you want, as far as I can tell, draw_debug2d() doesn’t do anything. Try moving render.draw_debug3d() above render.enable_state(render.STATE_CULL_FACE) and render.enable_state(render.STATE_DEPTH_TEST), or add in lines disabling those states before doing the debug draw.


#3

You sir, are a scholar and a gentleman.
Right on the money! Just moved it above the culling and depth test.