GML Functions: Going to 3D Mode

If you want to use 3D mode you first need to set Game Maker in 3D mode. You can later switch back to 2D mode if you want. The following two functions exist for this.


 * d3d_start Start using 3D mode. Returns whether successful.
 * d3d_end Stop using 3D mode. Returns whether successful.

Note that all functions related to 3D mode start with d3d_.

Starting 3D mode will result in the following changes. First of all hidden surface removal is switched on (using a 16-bit z-buffer). This means that for each pixel on the screen only the drawing with the smallest z-value (= depth value) is drawn. If instances have the same depth it is unclear what will happen and you can get ugly effects. Make sure instances that might overlap do not have the same depth value!

Secondly, the normal orthographic projection is replaced by a perspective one. This means the following. Normally the size of instances on the screen is independent on its depth. With a perspective projection instances that have a greater depth will appear smaller. When the depth is 0 it is equal to the old size (unless you change the projection; see below). The viewpoint for the camera is placed at a distance above the room. (This distance is equal to the width of the room; that gives a reasonable default projection.) Only instances in front of the camera are drawn. So don't use instances with a depth smaller than 0 (or at least not smaller than -w where w is the width of the room or the view).

Thirdly, the vertical y-coordinate is reversed. While normally the (0,0) position is at the top-left of the view, in 3D modo the (0,0) position is at the bottom-left position, as is normal for 3-dimensional views.

You can actually switch hidden surface remove and perspective projection on or off using the following functions.


 * d3d_set_hidden(enable) Enables hidden surface removal (true) or disables it (false).
 * d3d_set_perspective(enable) Enables the use of a perspective projection (true) or disables it (false).