• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Bad Draw

Status
Not open for further replies.
Level 13
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 CreateImage and SetImageRenderAlways.

gold-coin-bad-png.313495
gold-coin-ok-png.313496


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).

baddraw-demo-img-1-png.313497
 

Attachments

  • gold-coin-bad.png
    gold-coin-bad.png
    12.6 KB · Views: 160
  • gold-coin-ok.png
    gold-coin-ok.png
    80.9 KB · Views: 182
  • baddraw-demo-img-1.png
    baddraw-demo-img-1.png
    55.2 KB · Views: 183
  • baddraw-src-and-doc.zip
    127 KB · Views: 45
  • baddraw-demo.w3x
    12.9 MB · Views: 79
Status
Not open for further replies.
Top