Drawing 2D objects

Since Game Maker can not draw into the view of Ultimate 3D, you have to use Ultimate 3D itself if you want to draw some 2D stuff in there. To do this, Ultimate 3D offers two functions to draw textures and four functions to draw text.

Drawing textures

Let's begin with those that are used to draw textures in 2D to the screen:

DrawTex(
TextureIndex,
X,
Y,
Scaling,
Rotation,
Alpha
)

TextureIndex
This parameter gives the index of the texture that is to be drawn. The texture index is the value you entered as second parameter when loading the texture using
LoadTexture(...).

X, Y
The position where the texture is to be drawn in window space (relative to the left top of the first view).

Scaling
The scale that is to be used. 1 means no change, 0.5 means half size and 2 means double size.

Rotation
This parameter can be used to rotate the texture counter-clockwise in degrees. If it's 0 the texture does not get rotated at all.

Alpha
This parameter has to lie in the range from 0 to 255 where 0 means no opacity (fully transparent) and 255 means fully opaque.


If this function does not offer all the functionality you need, there's a second function to draw textures that are more complex. Basically it does the same thing, but there are more possibilities to modify the result.

DrawTexEx(
TextureIndex,
Left, Top,
Width, Height,
X, Y,
ScalingX, ScalingY,
Rotation,
R, G, B, A
)

Left, Top, Width, Height
These parameters identify the part of the texture that is to be used. The parameters should lie in the range from 0 to 1. They are texture coordinates. At the top left the texture coordinates given by left and top will be used, and at the bottom right the texture coordinates left+width and top+height will be used.

ScalingX, ScalingY
The scale that is to be used. 1 means no change, 0.5 means half size and 2 means double size.

R, G, B, A
These parameters give the color that is to be used as the "material" for drawing the texture. The values have to lie in the range from 0 to 255. A gives the opacity, where 0 means no opacity (fully transparent) and 255 means fully opaque.


That's all you need to know to draw textures.

Drawing text

Drawing text is also quite easy. First you set up a font, then you use it to draw a text. To set up the font you have to use the following function:

SetFont(
FontName,
FontIndex,
TextSize,
TextAttributes,
R,G,B,A
)

FontName
This is the name of the file in the fonts directory of Windows that contains the font you want to use. An example for this would be "Times New Roman" or "Arial".

FontIndex
This is the index you want to associate the font with. It works in the same way as the indices of textures. The highest valid index is 99.

TextSize
The size of the text as you know it from office programs.

TextAttributes
The text attributes. 0 means the normal font, 1 means bold, 2 means italic and 3 means bold and italic.

R, G, B, A
The text color. All values have to lie in the range from 0 to 255. A defines the opacity of the text where 0 means no opacity (fully transparent) and 255 means fully opaque.


A call to this function always requires some computing time. For this reason I recommend creating all fonts in the create event of the control object. If you want to change their color that's no problem. You can simply use the following function:

SetFontColor(
FontIndex,
R,G,B,A
)

FontIndex
The index of the font you want to change.

R, G, B, A
The new color of the font.


When you are done with creating the font you can use it to draw text. There are two different ways to draw text. You can either draw standard 2D text, or you can draw a text in the 3D scene. Let's start with the easier thing: drawing text in 2D.

DrawText(
FontIndex,
X, Y,
Text
)

FontIndex
The index of the font that is to be used for drawing the text.

X, Y
The position of the text relative to the top left corner of the first view.

Text
A string that contains the text you want to draw.


Drawing 3D text is a bit more complicated. Basically, you enter a complete transformation (as for primitives) instead of entering only an X and a Y.

Draw3DText(
Text,
FontIndex,
X, Y, Z,
RotX, RotY, RotZ,
ScalX, ScalY, ScalZ
)

Text
A string that contains the text you want to draw.

FontIndex
The index of the font that is to be used for drawing the text.

X, Y, Z, RotX, RotY, RotZ, ScalX, ScalY, ScalZ
The transformation of the 3D text. To get information about the meaning of the single variables have a look at the
second sub chapter of the tutorial about primitive objects.

Note that 3D text will always draw over everything else in the scene, including 2D textures and text.



© Christoph Peters. Some rights reserved.

Creative Commons License XHTML 1.0 Transitional