Game Development Community

dev|Pro Game Development Curriculum

Watermark text for TGE

by Herru Cules D · 07/24/2008 (6:40 am) · 3 comments

This resource will give you 2d watermark text for TGE. This watermark will always on top of other gui child.

First open up engine/gui/core/guicanvas.cc on method void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) exactly after
if (cursorON && mouseCursor && mShowCursor)
      {
         Point2I pos((S32)cursorPt.x, (S32)cursorPt.y);
         Point2I spot = mouseCursor->getHotSpot();

         pos -= spot;
         mouseCursor->render(pos);
      }
Add this code
bool WT = true; // enable/disable watermark

      if(WT)
      {
         GuiControlProfile *mtProfile;
         mtProfile = NULL;

         // set the font to guidefaultprofile font
         if( !mtProfile ) {
            SimObject *obj = Sim::findObject( "GuiDefaultProfile" );

            if( obj )
               mtProfile = dynamic_cast<GuiControlProfile*>(obj);
            else
               return;
         }

         if(mtProfile)
         {
            const char* renderTip = "TGE Licenced to HD"; // any watermark text you like

            ColorF mForegroundColor;
            mForegroundColor.set( 1, 1, 1, 1 );
            ColorI mFillColor;

            //Vars used:
            //Screensize (for position check)
            //Offset to set position
            //textBounds for text extent.
            Point2I offset; 
            Point2I textBounds;
            S32 textWidth = mtProfile->mFont->getStrWidth(renderTip);

            //Create text bounds.
            textBounds.x = textWidth+8;
            textBounds.y = mtProfile->mFont->getHeight() + 4;
            
            //Offset from below right edge
            offset.y = size.y - textBounds.y - 10;
            offset.x = size.x - textBounds.x - 10;

            // Set rectangle for the box, and set the clip rectangle.
            RectI rect(offset, textBounds);
            dglSetClipRect(rect);
            
            mFillColor.set(0,0,0,255);
            dglDrawRectFill(rect, mFillColor);
            
            mFillColor.set(255,255,255,255);
            dglDrawRect( rect, mFillColor );

            // Draw the text centered in the rectangle
            dglSetBitmapModulation( mForegroundColor );
            Point2I start;
            start.set( ( textBounds.x - textWidth) / 2, ( textBounds.y - mtProfile->mFont->getHeight() ) / 2 );   
            dglDrawText( mtProfile->mFont, start + offset, renderTip, mtProfile->mFontColors );
            dglClearBitmapModulation();

         }
         
         mtProfile = NULL;
      }

compile and rebuild the engine, now you can see the watermark on the below right edge of your game.

problem: if only I can set the font from C++ without finding guidefaultprofile (need help for this).

Thats it for now, hope it'll be usefull.

cheers.
herrucules.blogspot.com

#1
07/24/2008 (4:11 pm)
why not do this with ordinary Gui Controls ?
eg, push a modeless Gui on top.
#2
07/24/2008 (7:19 pm)
@Orion
Thx for the comment before. I'm making this resource to prevent the engine executable reusability by others. if you only use ordinary gui control, it can be easily stripped out without engine modification.
#3
07/25/2008 (8:44 am)
ah! i see.