• 🏆 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!

[Solved] Image drawn below other images

Status
Not open for further replies.
Level 3
Joined
May 9, 2011
Messages
37
Hey guys I've been playing around with Maker's CustomWindow to make a full screen hero selection system. The problem is that when I create an image to be mapped to a window, the image is always drawn below the image of the window.

Here is the code:
JASS:
scope WindowManager initializer Init
    globals
        private constant string TRACKABLE_MODEL = "Doodads\\Terrain\\InvisiblePlatform\\InvisiblePlatform.mdx"
        private constant integer NUMBER_OF_HEROES = 2
        private constant integer BACKGROUND_ID = 'B000'
        
        private constant integer WINDOW_SIZE = 100
        private constant integer WINDOW_SIZE_BONUS = 15
        private constant integer WINDOW_X_OFFSET = 100
        private constant integer WINDOW_START_X = -700
        private constant integer WINDOW_START_Y = 100
        
        private constant real WINDOW_SCALE = 0.3
        
        private constant integer WINDOW_HERO_LENGTH_COUNT = 3
        private constant integer WINDOW_HERO_WIDTH_COUNT = 8
    
        private Table table
        
        private string array title
        private string array text
        private string array icons
        private integer array units
        private trackable array trackables
        private image array images
        private CustomWindow array window
        
        private destructable bg
    endglobals
    
    private function InitHeroes takes nothing returns nothing
        // initialize stuff here
        // I commented this stuff out as it is doesn't affect the height of the image
    endfunction
    
    private function InitializeHeroScreen takes nothing returns nothing
        local integer row = 0
        local integer col = 0
        local image im
        local real x = WINDOW_START_X
        local real y = WINDOW_START_Y
        local integer id
        local integer i = 1
        local CustomWindow CW
        
        // probably has something to do with this (I've set the image type to 3 which should be drawn below the icon but its not)
        set CW = CustomWindow.create(1.0, ((WINDOW_SIZE+WINDOW_SIZE_BONUS) + WINDOW_X_OFFSET)*WINDOW_HERO_LENGTH_COUNT, (WINDOW_SIZE + WINDOW_SIZE_BONUS)*WINDOW_HERO_WIDTH_COUNT, x, y, 3)
        // I set the height just in case
        call CW.setHeight(100)
        call CW.show(true)
        
        set window[i] = CW
        
        loop
            exitwhen i > NUMBER_OF_HEROES
            set trackables[i] = CreateTrackable(TRACKABLE_MODEL, x, y, 0)
            // image type is set to 1 and height to 200 just in case
            set images[i] = CreateImage(icons[i], WINDOW_SIZE, WINDOW_SIZE, 0, x - WINDOW_SIZE/2, y - WINDOW_SIZE/2, 200, 0, 0, 200, 1)
            call SetImageRenderAlways(images[i], true)
            call ShowImage(images[i], true)
        
            set id = GetHandleId(trackables[i])
            set table[id].real[0] = x
            set table[id].real[1] = y
            set table[id].real[2] = count
            set table[id].integer[3] = units[i]
            set x = x + WINDOW_X_OFFSET
            set i = i + 1
            
            call TriggerRegisterTrackableTrackEvent(track, trackables[i])
            call TriggerRegisterTrackableHitEvent(hit, trackables[i])
        endloop
        
    endfunction
    
    function Init takes nothing returns nothing
        local unit dum = CreateUnit(NEUTRAL_PASSIVE, DUMMY_ID, 0, 0, 270)
        local integer i = 0
        
        local CustomWindow CW
        local CustomTextWindow CTW
        
        call TriggerAddAction(track, function Track)
        call TriggerAddAction(hit, function Hit)
        
        set table = Table.create()
        set ct = NewTimer()
        set bg = CreateDestructableZ(BACKGROUND_ID, 0, 0, 0, 270, 1000, 1)
        
        if(GetPlayerSlotState(GetLocalPlayer()) == PLAYER_SLOT_STATE_PLAYING) then
            call CameraSetupApplyForceDuration(gg_cam_Start_Camera, true, 0.00)
            call LockCameraToUnit(GetLocalPlayer(), dum)
            call InitHeroes()
            call InitializeHeroScreen()
        endif
        
        set dum = null
    endfunction
endscope

Here is a picture of what happens:

attachment.php


That was the result. If you adjust the camera angle via the scroll wheel, you can see whats below:

attachment.php



I suspect it has to do with either set CW = CustomWindow.create(1.0, ((WINDOW_SIZE+WINDOW_SIZE_BONUS) + WINDOW_X_OFFSET)*WINDOW_HERO_LENGTH_COUNT, (WINDOW_SIZE + WINDOW_SIZE_BONUS)*WINDOW_HERO_WIDTH_COUNT, x, y, 3) or set images[i] = CreateImage(icons[i], WINDOW_SIZE, WINDOW_SIZE, 0, x - WINDOW_SIZE/2, y - WINDOW_SIZE/2, 200, 0, 0, 200, 1), which is weird as I set the image type of CW to 3 and images to 1, which means images is drawn above CW and adjusted the height just in case (to no effect).

All other leaks n shit that are not destroyed here are destroyed within another function which is unimportant to the problem.

Thanks in advance,
Tauren_009

edit:
I managed to get the icon be shown above the window but its being rendered weirdly

attachment.php

 

Attachments

  • result.png
    result.png
    70.9 KB · Views: 190
  • asd.png
    asd.png
    31.1 KB · Views: 169
  • new.png
    new.png
    24.7 KB · Views: 157
Last edited:
What was the solution to getting the icon displayed above the window? Just curious.

As for the black space--it is because Warcraft 3 images resize the image to fit a fixed image plane. Well, it doesn't quite "resize it", it actually takes the edge pixels and fills in the rest of the image with it. The solution is to add a 1 px transparent border and reimport the icon. That way, the stretched part will be transparent. BLP Lab can do this for you.

But an even better way (IMO) is to use destructables with a replaceable texture ID. That way, you don't even need to bother importing tons of icons. You can just create a destructable object for your icon, and then create it in game without any extra setup. It is a lot more convenient to work with than images IMO, except that images have some extra functions.

Look at the destructables in this system:
http://www.hiveworkshop.com/forums/spells-569/vjass-system-custominventory-159130/
You can take the imported square model and use it yourself (just be sure to give credit).
 
Level 3
Joined
May 9, 2011
Messages
37
I changed the black background originally from destructable to an image and changed the image type (or something like that).

I'll try and check that system for using destructables. Can the texture of a destructable be changed via code?

Thanks for the reply,
Tauren_009
 
I changed the black background originally from destructable to an image and changed the image type (or something like that).

I'll try and check that system for using destructables. Can the texture of a destructable be changed via code?

Thanks for the reply,
Tauren_009

The easiest way to "change" the destructable texture is to remove the old destructable and create a new one in its place with the desired texture. You'll need to make a separate destructable for each icon that you want to use. But it is easy to do (pretty much just copy and paste). It is better (IMO) than importing a bunch of icon textures for every icon you want to use.
 
Level 3
Joined
May 9, 2011
Messages
37
I managed to do what you said. Only 2 more problems:

1. The image seems to be tinted black. Pic:

attachment.php



2. My trackables code is fucked, not being placed in the location of the image. Btw, I used your Track library for this.

Here's my current code for initializing the hero screen:
JASS:
private function InitializeHeroScreen takes nothing returns nothing
        local real x = WINDOW_START_X
        local real y = WINDOW_START_Y
        local integer id
        local CustomWindow CW
        
        set c = c + 1
        
        set CW = CustomWindow.create(1.0, ((WINDOW_SIZE+WINDOW_SIZE_BONUS) + WINDOW_X_OFFSET)*WINDOW_HERO_LENGTH_COUNT, /* 
            */ (WINDOW_SIZE+WINDOW_SIZE_BONUS)*WINDOW_HERO_WIDTH_COUNT, x, y, 3)
        call CW.setHeight(100)
        call CW.show(true)
        
        set window[c] = CW
        
        set x = -470
        set y = 230
        
        loop
            set t = t + 1
            exitwhen t > NUMBER_OF_HEROES
            set d = CreateDestructableZ(icons[t], x, y, 1000, 270, 0.7, 0)
            set track[t] = CreateTrack(TRACKABLE_MODEL, x, y, 100, 270)
            call EnableTrackInstance(track[t], true)
        
            set id = track[t]
            set table[id].integer[0] = track[t]
            set table[id].integer[1] = t
            set table[id].destructable[2] = d
            set table[id].integer[3] = units[t]
            set x = x + WINDOW_X_OFFSET/1.55
            
            call RegisterHoverEvent(track[t], function Hover)
            call RegisterClickEvent(track[t], function Hit)
        endloop
endfunction

Hover and Hit just print out "Hover" and "Hit" respectively.

TRACKABLE_MODEL is the square model from the system you linked.
 

Attachments

  • 2.png
    2.png
    78.1 KB · Views: 131
Level 3
Joined
May 9, 2011
Messages
37
Oh I see. Fixed. Thanks

edit:

I managed to fix both problems. The system is now fully functional. Thanks everyone! Mods can lock this or something
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
What was the solution to getting the icon displayed above the window? Just curious.
It should be setting the Z (WC3 height) height above the other surfaces so one is physically in front of the other. Z (view depth) tests are used in real time graphics to determine if a piece of geometry is in front of another piece of geometry. If two pieces of geometry are the same Z distance then some arbitrary ordering occurs (Z fight artefacts, the result of internal ordering, floating point rounding error or even just the way the GPU driver built the shaders) which is why you should never overlap geometry which is plain wise parallel (intersections are ok because the area of Z fight is so small no one notices).

Although it really is dependant on the depth from the camera, as little as 1 WC3 unit offset might suffice (enough so that the icon display geometry can be considered in front of the background or terrain). Setting it too large might cause perspective problems.
 
Status
Not open for further replies.
Top