Page 1 of 1

Posted: Fri Aug 14, 2009 9:25 am
by parcival
As some of you might know there is an issue that doesn't allow GaugeImage calls to work as they used to in R5.
Example:

Code: Select all

parciEnergyGauge =
    GaugeImage(
        JustifyBottom,
        ImportImageFromFile("mods/CortUI/media/cortui_parci_energy.png", true),
        GetPercentEnergy(Me, OnEveryFrame)
    );
Although the above used to work with R4, now that R5 is on the way there is a problem with the above call. Specifically, when the value of the specific gauge is reduced, it's image is truncated from the bottom instead from the top (of course I am talking about using it with JustifyBottom, as demonstrated on the example above).

From left to right, Energy Full, Energy low R4 way (correctly displayed truncated from top), Energy low R5 way (wrongly displayed truncated from bottom):


Also, some of you might use the following to do the same job since it does not suffer from the truncated from bottom issue:

Code: Select all

parciEnergyGauge =
    GaugeImageRect(
        JustifyBottom,
        ImportImageFromFile("mods/CortUI/media/cortui_parci_energy.png", true),
        Rect(0, 0, 19, 82), // which part of the image to use
        true, // this set 3D mode
        GetPercentEnergy(Me, OnEveryFrame)
    );
This has a side effect in R5. The gauge will appear semitransparent.

Imago tried to locate the source of these issues in R5 but due to the complexity of the code and Imago's limited available time for this, a fix was not found and another pointed out the correct method to call the gauge, that doesn't suffer from any of the above issues.
ALL you need to do is wrap your calls into BlendImage calls.

For the 1st case you can do this:

Code: Select all

parciEnergyGauge = 
    BlendImage( 
        GaugeImage(
            JustifyBottom,
            ImportImageFromFile("mods/CortUI/media/cortui_parci_energy.png", true),
            GetPercentEnergy(Me, OnEveryFrame)
        ),
    BlendModeAdd
    );


For the 2nd case you can do this (although this crushes R4, so you have to wait for R5):

Code: Select all

parciEnergyGauge =
    BlendImage(  
        GaugeImageRect(
            JustifyBottom,
            ImportImageFromFile("mods/CortUI/media/cortui_parci_energy.png", true),
            Rect(0, 0, 19, 82), // which part of the image to use
            true, // this set 3D mode
            GetPercentEnergy(Me, OnEveryFrame)
        ),
    BlendModeAdd //hudBlendMode    
    );

Posted: Fri Aug 14, 2009 10:22 am
by Imago
"Imago tried to locate the source of these issues in R5 but due to the complexity of the code and Imago's limited available time for this"

This isn't true, wrapping it in a blend image is the CORRECT way to do it. The way you have been doing it is _WRONG_. There is no CODE CHANGE to be made! The msoriginal gauges use blend image, using the default blend mode being BlendModeAdd (hudBlendMode) which i proved here: http://alleg.pastebin.com/m7fa262f0 I thought I made this perfectly clear per our conversation in IRC. :o

ANYWAYS

QUOTE <parcival> Hi!
<parcival> Are you around?
<parcival> I am making a post in the Artworks about the BlendImage thing but I lost the different modes... :doh
<parcival> 1 is BlendModeAdd
<parcival> 2 is BlendModeSource
<parcival> but I forgot the rest
<parcival> And since I was stupid enough to delete our chat logs I can't find them
<parcival> Could you please list them again so I could add them in my post?
<parcival> I gtg
<parcival> So if you have the time post the blend modes here:
<parcival> http://www.freeallegiance.org/forums/index...showtopic=51881[/quote]

HERE

Code: Select all

        switch (blendMode) {
 
            case BlendModeSource:
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHABLENDENABLE, false));
                break;

            case BlendModeAdd:
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE));
                break;

            case BlendModeSourceAlpha:
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
                break;

            case BlendModeSourceAlphaTest:
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHAREF, (DWORD)8));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE)); 
                break;

            case BlendModeAlphaStampThrough:
                CD3DDevice9::Get()->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
                CD3DDevice9::Get()->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA));
                D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
                break;

            default:
                ZError("Invalid BlendMode");
        }

Posted: Fri Aug 14, 2009 7:42 pm
by parcival
Imago is correct! Error edited and fixed in my 1st post.
`yt! You rock!