GML Functions: Drawing Surfaces

This functionality is only available in the Pro Edition of Game Maker.

In certain situations you might want to paint not directly on the screen but on a canvas that can then later be used to paint things on the screen. Such a canvas is called a surface. For example, you want to let the user draw on the screen. The paint should not be drawn on the screen (because it will be removed each next step), but instead you want to draw it on a separate surface that is copied onto the screen in each step. Or you want to use a texture that changes over time.

Surfaces make this all possible. They are actually rather simple to use. You first create a surface. Next you indicate that further drawing should happen on this surface. From that moment on all drawing functions operate on the surface. Once you are done you reset the drawing target and further drawing happens on the screen again. You can draw the surface on the screen in many different ways or use it as a texture. There are though a few things you must be aware of. See the remarks at the end.

The following functions exist to deal with surfaces


 *  Creates a surface of the indicated width and height. Returns the id of the surface, which must be used in all further calls. Note that the surface will not be cleared. This is the responsibility of the user. (Set it as a target and call the appropriate clear function.)
 *  Frees the memory used by the surface.
 *  Returns whether the surface with the indicated id exists.


 *  Returns the width of the surface.
 *  Returns the height of the surface.
 *  Returns the texture corresponding to the surface. This can be used to draw textured objects with the image of the surface.


 *  Sets the indicated surface as the drawing target. All subsequent drawing happens on this surface. It resets the projection to simply cover the surface.
 * surface_reset_target Resets the drawing target to the normal screen.


 *  Returns the color of the pixel corresponding to position (x,y) in the surface. This is not very fast, so use with care.
 *  Saves a bmp image of the surface in the given filename. Useful for making screenshots.
 *  Saves part of the surface in the given filename.


 *  Draws the surface at position (x,y). (Without color blending and no alpha transparency.)
 *  Draws the surface stretched to the indicated region.
 *  Draws the surface tiled so that it fills the entire room.
 *  Draws the indicated part of the surface with its origin at position (x,y).
 * ''' Draws the surface scaled and rotated with blending color (use c_white for no blending) and transparency alpha (0-1).
 *  Draws the surface stretched to the indicated region. color is the blending color and alpha indicates the transparency setting.
 *  Draws the surface tiled so that it fills the entire room but now with scale factors and a color and transparency setting.
 *  Draws the indicated part of the surface with its origin at position (x,y) but now with scale factors and a color and transparency setting.
 *  The most general drawing function. It draws the indicated part of the surface with its origin at position (x,y) but now with scale factors, a rotation angle, a color for each of the four vertices (top-left, top-right, bottom-right, and bottom-left), and an alpha transparency value.


 *  Copies the source surface at position (x,y) in the destination surface. (Without any form of blending.)
 *  Copies the indicated part of the source surface at position (x,y) in the destination surface. (Without any form of blending.)

Note that there are no functions to copy part of the screen to a surface. (This is impossible due to possible format differences between the screen and the surfaces.) If this is required you must set a surface as render target and next draw the room. You can then use the surface copying routines to get parts of it.

Note that you can also create sprites and backgrounds from surfaces. See the section on changing resources for more information.

Some care must be taken when using these functions. In particular please notice the following:


 * You should never change the drawing target while you are actually drawing on the screen, that is, never use it in drawing events. This will cause serious problems with the projection and viewport.
 * Surfaces do not work correctly with 3D mode. You can use them while not in 3D mode (by calling before using them, but once you start 3D mode again the surfaces will be destroyed.
 * For reasons of speed, the surface is maintained in videomemory only. As a result, you might lose the surface when e.g. the screen resolution changes or the screensaver pops up.
 * Surfaces will not be saved when saving a game.