- Joined
- Nov 7, 2014
- Messages
- 571
Warcraft III has only a few image drawing functions exposed to its scripting language Jass, but the performance of those functions is good enough for [re]drawing at least a few thousand images every second. Newer patches of the game also expose functions for detecting the player's mouse state (mouse move/click events). The combination of these two things allow one to create a draw loop that, for example, could draw a simple user interface (a small caveat is that the gameplay camera needs to be pointed down towards the terrain, because images cannot be rotated.
Although the game comes with ~1200 images (most images have a disabled version as well), they require a special preprocessing before they can be drawn normally by the exposed drawing functions
The left image above is
The preprocessed images need to be imported to the map before they can be used. This can significantly increase the size of the map, if for example, most images that come with game are preprocessed and imported.
Bad Draw is a small library of drawing functions (all drawing is done by creating images). The functions need to be called in a draw loop. A simple draw loop would be:
The above draw loop repeatedly draws a black rectangle (fully visible) with width
The
The demo map implements a simple UI by using the Bad Draw library (also a tiny widget library, see attatchments).
Although the game comes with ~1200 images (most images have a disabled version as well), they require a special preprocessing before they can be drawn normally by the exposed drawing functions
CreateImage
and SetImageRenderAlways
.The left image above is
ReplaceableTextures\\CommandButtons\\BTNMGExchange.blp
, with width and height set to 128.0. It has strange drawing artifacts around it (right and above). The right image above is the left image after preprocessing. It doesn't have any strange drawing artifacts except that it has "lost" 1 pixel from every side.The preprocessed images need to be imported to the map before they can be used. This can significantly increase the size of the map, if for example, most images that come with game are preprocessed and imported.
Bad Draw is a small library of drawing functions (all drawing is done by creating images). The functions need to be called in a draw loop. A simple draw loop would be:
JASS:
function simple_draw_loop takes nothing returns nothing
call bd_draw_begin(0)
call bd_rect(x, y, w, h, 2, 0x00, 0x00, 0x00, 0xFF)
call bd_draw_end()
endfunction
...
call TimerStart(CreateTimer(), 1.0/24.0, true, function simple_draw_loop)
...
The above draw loop repeatedly draws a black rectangle (fully visible) with width
w
and height h
at position x, y
. The rectangle is only visible to Player(0)
.The
bd_*
functions need to be called in a specific order. bd_draw_begin
must be called first, then other bd_*
draw functions can be called, but bd_draw_end
must be called last.The demo map implements a simple UI by using the Bad Draw library (also a tiny widget library, see attatchments).