draw text to viewport like measure&const.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 01/11/2008 at 07:35, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   9.1 
    Platform:      
    Language(s) :     C++  ;

    ---------
    Hi,

    i need to draw some text to the editor window.

    Using the serach it seems that with R9 you have to implement your own way of doing this with bitmap fonts for example.

    like here:
    http://www.plugincafe.com/forum/display_topic_threads.asp?ForumID=4&TopicID;=2565

    I have two questions now:

    How was the text display done in the R9 function Measure&Construction; ?

    And secondly, has this changed in later sdk's ?

    thanks,
    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 01:31, xxxxxxxx wrote:

    Use the GeClipMap class' text functions.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 02:53, xxxxxxxx wrote:

    Thanks for the hint.

    Im having some difficulties though to understand what this class actually does and I cant find any examples.

    To draw text with it i have to init it with a bitmap that contains all letters ?
    Probably not bc i cant see how cinema would know where in the bitmap the individual letters are located...

    So GeClipMap is just needed to get the color at a given position of a loaded bitmap ?
    Would i have to init it with a bitmap at all if i want to draw text only ?

    the following code inside Draw() doesnt produce any results:

    > \> AutoAlloc<GeClipMap> cm; \> cm->Init(250,250); \> cm->BeginDraw();      \> cm->SetColor(0,0,0); \> cm->TextAt(mouseX-10,mouseY-10,"test"); \> cm->EndDraw(); \>

    greetings,
    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 04:09, xxxxxxxx wrote:

    Without having ever used this class, I would say you have to pass your 'drawing' cm to the BaseDraw bd somehow. But I don't know how, either.

    Cheers,
    Jack



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 04:32, xxxxxxxx wrote:

    Hi Jack.

    I saw in the sdk that with a CTrack plugin you pass the clipMap to the Draw Function, but im doing a ToolData plugin, which has no clipMap param in its draw function.
    So im not sure if thats neccessary..



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 04:43, xxxxxxxx wrote:

    You can obtain the internal bitmap of the GeClipMap with GetBitmap() member function.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 04:49, xxxxxxxx wrote:

    ok, so my code above creates a bitmap with the given text, which then i can draw to the viewport with the baseDraws DrawTexture(..) ?

    gonna try that out now.

    Kind of a cumbersome way though just to draw some text to the screen ;-)

    EDIT: is this the way that the text in the measure & construction tool was drawn ?

    thanks,
    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 05:19, xxxxxxxx wrote:

    alright im starting to get some results, doing it the way described above, text doesnt look very good though, more like some washed out texture font.

    Im wondering now how text in the hud in R9 and above is done.
    Is that done with bitmaps as well or with some internal functions that we dont have access to ?

    I cant seem to find much info on the hud neither in sdk nor with the forum search.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 07:15, xxxxxxxx wrote:

    Yes it is done with a GeClipMap. Actually it is not that hard, here I wrote a function for oyu to display text in a Draw() function. Just pass the BaseDraw and the position and of course the text.

    > \> static Bool DrawText(String text, LONG xpos, LONG ypos, BaseDraw \*bd) \> { \>      AutoAlloc<GeClipMap> cm; \>      if(!cm) return FALSE; \> \>      if(!cm->Init(0, 0, 32)) return FALSE; \>      cm->BeginDraw(); \>      LONG width = cm->TextWidth(text); \>      LONG height = cm->TextHeight(); \>      cm->EndDraw(); \>      cm->Destroy(); \> \>      if(!cm->Init(width, height, 32)) return FALSE; \>      cm->BeginDraw(); \>      cm->SetColor(255, 255, 255, 255); \>      cm->TextAt(0,0,text); \>      cm->EndDraw(); \> \>      bd->SetMatrix_Screen(); \>      bd->SetLightList(BDRAW_SETLIGHTLIST_NOLIGHTS); \> \>      Vector \*padr = bNew Vector[4]; \>      Vector \*cadr = bNew Vector[4]; \>      Vector \*vnadr = bNew Vector[4]; \>      Vector \*uvadr = bNew Vector[4]; \> \>      padr[0] = Vector(xpos,ypos,0); \>      padr[1] = Vector(xpos+width,ypos,0); \>      padr[2] = Vector(xpos+width,ypos+height,0); \>      padr[3] = Vector(xpos,ypos+height,0); \> \>      cadr[0] = Vector(1,1,1); \>      cadr[1] = Vector(1,1,1); \>      cadr[2] = Vector(1,1,1); \>      cadr[3] = Vector(1,1,1); \> \>      vnadr[0] = Vector(0,0,1); \>      vnadr[1] = Vector(0,0,1); \>      vnadr[2] = Vector(0,0,1); \>      vnadr[3] = Vector(0,0,1); \> \>      uvadr[0] = Vector(0,0,0); \>      uvadr[1] = Vector(1,0,0); \>      uvadr[2] = Vector(1,1,0); \>      uvadr[3] = Vector(0,1,0); \> \>      BaseBitmap \*cmbmp = NULL; \>      cmbmp = cm->GetBitmap(); \>      if(!cmbmp) return FALSE; \> \>      BaseBitmap \*bmp = NULL; \>      bmp = cmbmp->GetClone(); \>      if(!bmp) return FALSE; \> \>      AlphaBitmap \*alpha = NULL; \>      alpha = bmp->GetInternalChannel(); \>      if(!alpha) alpha = bmp->AddChannel(TRUE, FALSE); \>      if(!alpha) \>      { \>           BaseBitmap::Free(bmp); \>           return FALSE; \>      } \> \>      LONG x,y; \>      for(y=0; y<height; y++) \>      { \>           for(x=0; x<width; x++) \>           { \>                UWORD r; \>                bmp->GetPixel(x,y,&r;,&r;,&r;); \>                bmp->SetAlphaPixel(alpha, x, y, r); //r is the opacity \>           } \>      } \> \>      bd->DrawTexture(bmp, padr, cadr, vnadr, uvadr, 4, FALSE, DRAW_ALPHA_NORMAL); \> \>      BaseBitmap::Free(bmp); \> \>      bDelete(padr); \>      bDelete(cadr); \>      bDelete(vnadr); \>      bDelete(uvadr); \> \>      return TRUE; \> } \> \> Bool LookAtCamera::Draw(PluginTag \*tag, BaseObject \*op, BaseDraw \*bd, BaseDrawHelp \*bh) \> { \>      return DrawText("hello world", 256, 256, bd); \> } \>

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 07:26, xxxxxxxx wrote:

    This how the above code displays text:

    By changing the alpha channel of the bitmap you can display a border around the text. Just look at the code.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 09:29, xxxxxxxx wrote:

    hey thats cool, will save me quite some time figuring it out myself ;-)

    Im sure it will be very helpful for other people in the future as well.

    thanks alot,
    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/11/2008 at 13:55, xxxxxxxx wrote:

    Hi,

    somehow the part with the alphaBitmap / setAlphaPixel did not work, so i always had white text on a black non-transparent rectangle.

    First i thought it was bc i changed sth for R9, namely replaced the AlphaMap with a LONG, but i think that part was alright.

    Now i just stripped away the whole alphamap part, changed the alpha-color, and inverted the alpha mode, so that you will always get white font on transparent background, as in the picture.

    > \> static Bool DrawText(String text, LONG xpos, LONG ypos, BaseDraw \*bd){ \> \>           AutoAlloc<GeClipMap> cm; \>           if(!cm) return FALSE; \> \>           if(!cm->Init(0, 0, 32)) return FALSE; \>           cm->BeginDraw(); \>           LONG width = cm->TextWidth(text); \>           LONG height = cm->TextHeight(); \>           cm->EndDraw(); \>           cm->Destroy(); \> \>           if(!cm->Init(width, height, 32)) return FALSE; \>           cm->BeginDraw(); \>                // changed the alpha color \>           cm->SetColor(255, 255, 255, 0); \>           cm->TextAt(0,0,text); \>           cm->EndDraw(); \> \>           bd->SetMatrix_Screen(); \>           bd->SetLightList(BDRAW_SETLIGHTLIST_NOLIGHTS); \> \>           Vector \*padr = bNew Vector[4]; \>           Vector \*cadr = bNew Vector[4]; \>           Vector \*vnadr = bNew Vector[4]; \>           Vector \*uvadr = bNew Vector[4]; \> \>           padr[0] = Vector(xpos,ypos,0); \>           padr[1] = Vector(xpos+width,ypos,0); \>           padr[2] = Vector(xpos+width,ypos+height,0); \>           padr[3] = Vector(xpos,ypos+height,0); \> \>           cadr[0] = Vector(1,1,1); \>           cadr[1] = Vector(1,1,1); \>           cadr[2] = Vector(1,1,1); \>           cadr[3] = Vector(1,1,1); \> \>           vnadr[0] = Vector(0,0,1); \>           vnadr[1] = Vector(0,0,1); \>           vnadr[2] = Vector(0,0,1); \>           vnadr[3] = Vector(0,0,1); \> \>           uvadr[0] = Vector(0,0,0); \>           uvadr[1] = Vector(1,0,0); \>           uvadr[2] = Vector(1,1,0); \>           uvadr[3] = Vector(0,1,0); \> \>           BaseBitmap \*cmbmp = NULL; \>           cmbmp = cm->GetBitmap(); \>           if(!cmbmp) return FALSE; \> \>           BaseBitmap \*bmp = NULL; \>           bmp = cmbmp->GetClone(); \>           if(!bmp) return FALSE; \>                \>                // inverted alpha mode \>           bd->DrawTexture(bmp, padr, cadr, vnadr, uvadr, 4, FALSE, DRAW_ALPHA_INVERTED);           \> \>           BaseBitmap::Free(bmp);      \>           bDelete(padr); \>           bDelete(cadr); \>           bDelete(vnadr); \>           bDelete(uvadr); \>       \>           return TRUE; \> } \>


Log in to reply