Game Development Community

SetBitmapModulation not working in TSE

by Stephane Conde · in Torque Game Engine Advanced · 08/24/2006 (8:19 pm) · 3 replies

In TGE, doing the following:

dglSetBitmapModulation(ColorF(1.0f, 1.0f, 1.0f, someAlphaValue));

just before using one of the draw functions (dglDrawBitmapStretch, for example) would allow you to fade out your texture.

In TSE, for some reason, that functionality does not work. You can use the RGB values to modulate red, green and blue, but modifying the alpha value does not seem to do anything in TSE.

It looks like the mBitmapModulation value in TSE is being used in the drawBitmapStretchSR function. drawBitmapStretchSR uses mBitmapModulation to set the four vertex colors before they are sent off to be rendered... but it seems like the alpha value is being ignored.

Does anyone have any ideas about why this may be happening? Any insight you might be able to provide would be greatly appreciated.

Thanks,

Stephane

Posted this again since it was not in the correct forum (previous thread can be deleted)

#1
08/25/2006 (5:05 pm)
I'm not entirely sure how and where you are using the bitmap modulation color, but for me it works (including alpha).

Make sure you have alpha blending on, first. If not, it'll act just like you describe.


Every time I've set the value I've used GFX->setBitmapModulation and GFX->clearBitmapModulation also.
#2
08/25/2006 (6:56 pm)
Hey Max,

Thanks for the reply! I'm glad to hear that someone has it working... I guess that somehow means I'm doing something wrong...

Perhaps someone can help me to figure our what I am doing wrong.

Here is an example of what I am doing that isn't working...

I tried changing the onRender in guiBitmapCtrl.cpp from this:
void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
  {
     if (mTextureObject)
     {
        GFX->clearBitmapModulation();
        if(mWrap)
        {
           GFXTextureObject* texture = mTextureObject;
           RectI srcRegion;
           RectI dstRegion;
           float xdone = ((float)mBounds.extent.x/(float)texture->mBitmapSize.x)+1;
           float ydone = ((float)mBounds.extent.y/(float)texture->mBitmapSize.y)+1;
           int xshift = startPoint.x%texture->mBitmapSize.x;
           int yshift = startPoint.y%texture->mBitmapSize.y;
           for(int y = 0; y < ydone; ++y)
              for(int x = 0; x < xdone; ++x)
              {
                 srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y);
                 dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift,
                                         ((texture->mBitmapSize.y*y)+offset.y)-yshift,
                                         texture->mBitmapSize.x,
                                         texture->mBitmapSize.y);
                 GFX->drawBitmapStretchSR(texture,dstRegion, srcRegion);
              }
        }
        else
        {
           RectI rect(offset, mBounds.extent);
           GFX->drawBitmapStretch(mTextureObject, rect);
        }
     }

     if (mProfile->mBorder || !mTextureObject)
     {
        RectI rect(offset.x, offset.y, mBounds.extent.x, mBounds.extent.y);
        GFX->drawRect(rect, mProfile->mBorderColor);
     }

     renderChildControls(offset, updateRect);
  }

To this:

void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
  {
     if (mTextureObject)
     {
        [b]//GFX->clearBitmapModulation();[/b]
        [b]GFX->setBitmapModulation(ColorF(1.0f, 1.0f, 1.0f, 0.5f));[/b]
        if(mWrap)
        {
           GFXTextureObject* texture = mTextureObject;
           RectI srcRegion;
           RectI dstRegion;
           float xdone = ((float)mBounds.extent.x/(float)texture->mBitmapSize.x)+1;
           float ydone = ((float)mBounds.extent.y/(float)texture->mBitmapSize.y)+1;
           int xshift = startPoint.x%texture->mBitmapSize.x;
           int yshift = startPoint.y%texture->mBitmapSize.y;
           for(int y = 0; y < ydone; ++y)
              for(int x = 0; x < xdone; ++x)
              {
                 srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y);
                 dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift,
                                         ((texture->mBitmapSize.y*y)+offset.y)-yshift,
                                         texture->mBitmapSize.x,
                                         texture->mBitmapSize.y);
                 GFX->drawBitmapStretchSR(texture,dstRegion, srcRegion);
              }
        }
        else
        {
           RectI rect(offset, mBounds.extent);
           GFX->drawBitmapStretch(mTextureObject, rect);
        }
     }

     if (mProfile->mBorder || !mTextureObject)
     {
        RectI rect(offset.x, offset.y, mBounds.extent.x, mBounds.extent.y);
        GFX->drawRect(rect, mProfile->mBorderColor);
     }

     renderChildControls(offset, updateRect);
  }

I would expect that any guiBitmapCtrls would then be rendered at 50% opacity... when in fact nothing changes at all. Does anyone know what I might be doing incorrectly?

Thanks!

Stephane

P.S. This change was made in a fresh download of TSE (downloaded last Thursday) without any effect
#3
08/26/2006 (12:13 pm)
Alright... I just figured this one out...

To fix this bug, simply add the following two lines to any drawing function that you want to have alpha:
setTextureStageAlphaOp(0, GFXTOPModulate);
   setTextureStageAlphaOp(1, GFXTOPDisable);

I'm still having issues with the other bug I posted about here though. Does anyone have any insight into this one?