Skip to content

cf_render_state_3d_defaults

Category: graphics
GitHub: cute_graphics.h


Returns a CF_RenderState set up for rendering 3d geometry.

CF_RenderState cf_render_state_3d_defaults(void);

Return Value

cf_render_state_defaults plus depth writes on, a CF_COMPARE_FUNCTION_LESS_THAN depth test, and back-face culling.

Remarks

The 2d defaults deliberately leave depth testing off, which for 3d shows up as the far side of a model drawing over the near side. This turns it on in one call.

The canvas must have a depth buffer or none of this does anything. cf_canvas_defaults leaves depth_stencil_enable false, so opt in explicitly:

CF_CanvasParams params = cf_canvas_defaults(w, h);
params.depth_stencil_enable = true;
CF_Canvas canvas = cf_make_canvas(params);
cf_material_set_render_state(material, cf_render_state_3d_defaults());

The CF_COMPARE_FUNCTION_LESS_THAN test assumes the depth buffer clears to 1.0 (the default) and that your projection maps the near plane to 0 and the far plane to 1 -- which is what cf_perspective and cf_ortho produce. Back-face culling assumes counter-clockwise front faces.

CF_RenderState
cf_render_state_defaults
cf_material_set_render_state
CF_CanvasParams
cf_perspective