Announcement

Collapse
No announcement yet.

Can't get DrawText to render to the screen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can't get DrawText to render to the screen

    What am I missing guys... I have managed to get the DrawHUD to run repeatedly:


    Code:
    AMainHUD::AMainHUD(const class FPostConstructInitializeProperties& PCIP)
    	:	Super(PCIP)
    {
    	Points = PCIP.CreateDefaultSubobject<UHUDElementComponent>(this, TEXT("HUDElementComponent"));
    	ConstructorHelpers::FObjectFinder<UFont> FontObject(TEXT("Font'/Game/Fonts/PointsFont.PointsFont"));
    	if (FontObject.Object)
    	{
    		Points ->Font = FontObject.Object;
    	}
    
    }
    
    void AMainHUD::DrawHUD()
    {
    	DrawText(TEXT("Hi"), FColor(100, 100, 100, 0), 200.0f, 200.0f, NULL, 1.0f, false);
    }
    but the DrawText is not drawing to the screen... What might I be doing wrong?

    My GameMode has AMainHUD defined as its class and I guess that's working because it is correctly running the DrawHUD event
    Last edited by jimmyt1988; 09-09-2014, 08:26 AM.

    #2
    Code:
    Draw2DLine(0, 100, 100, 200, FColor(100, 100, 100, 0));
    is working but still no cigar on the DrawText?

    I've also tried:

    Code:
    void AMainHUD::DrawHUD()
    {
    	FString string = "HI THERE";
    	DrawText(string, FVector2D(10.0f, 10.0f), Points->Font, FVector2D(1.0f, 1.0f), FColor(100, 100, 100, 0));
    }
    I've also tried:


    Code:
    DrawText(string, FVector2D(100.0f, 100.0f), Points->Font, FVector2D(1.0f, 1.0f), FColor(1.0f, 1.0f, 1.0f, 0.0f));
    and

    Code:
    DrawText(string, FVector2D(100.0f, 100.0f), Points->Font, FVector2D(1.0f, 1.0f), FColor(1.0f, 1.0f, 1.0f, 1.0f));
    Last edited by jimmyt1988; 09-09-2014, 04:49 AM.

    Comment


      #3
      For a number of your examples, it looks like your FColor is completely transparent (alpha = 0). Try FColor(255, 255, 255, 255) and see if that makes your text visible.

      If you would like to follow along with an example, there is this Coding a Canvas HUD video. The DrawText line from it is:

      DrawText(TEXT("GAME OVER"), FColor::White, (ScreenDimensions.X - GameOverSize.X) / 2.f, (ScreenDimensions.Y - GameOverSize.Y) / 2.f, HUDFont);

      Basically, the parameters used there are:

      void DrawText
      (
      const FString & Text,
      FLinearColor TextColor,
      float ScreenX,
      float ScreenY,
      class UFont * Font,
      float Scale,
      bool bScalePosition
      )

      Does that example help at all?

      Comment


        #4
        You know what's funny... The Draw2DLine actually gets drawn when alpha is at 0.0f... so I thought i'd try it both ways for the DrawText... it originally started off as a typo... However, no it doesn't make a difference.

        I'm at work at the moment, but when I get home:

        - I'll try the 255... I thought it would be a range from 0 - 1 for alpha
        - I'll try to pick the different overload you have stated

        Thanks in advance!
        Last edited by jimmyt1988; 09-09-2014, 11:50 AM.

        Comment


          #5
          Are you sure that your font object is getting properly? Try to toss a breakpoint on this line in your code:

          Points ->Font = FontObject.Object;

          If the breakpoint doesn't get triggered when you play the game, you should know what the problem is. That's the only thing I can really think of; your DrawText calls look OK otherwise to me.

          Comment


            #6
            Thanks,

            I must have been a complete noob yesterday...

            Code:
            DrawText(TEXT("HI THERE"), FColor(255.0f,255.0f,255.0f), 10.0f, 10.0f, Points->Font, 1.0f, false);
            All working now ta.

            Comment


              #7
              By the way if you want to use 0 - 1 range, it is FLinearColor

              Comment

              Working...
              X