Hello, I implemented Oliver's method of drawing Client Side Text into my
mod, and it compiles without errors but does not draw the text. I discovered
by using Msg that the code seems to locate the correct x,y position on the
screen and attempts to draw the correct name to it, so the error is probably
in this section here, my guess being the font:

vgui::surface()->DrawSetTextFont(m_hFont);
vgui::surface()->DrawSetTextPos(x, y);
vgui::surface()->DrawSetTextColor(Color(255, 255, 255, alpha));
vgui::surface()->DrawPrintText(sIDString, wcslen(sIDString));

Anyways, I am trying to draw the text above an entity that is stored as
public in the player class, so that is what pJ is in the code, and yes pJ is
fine as the player camera follows it, but the text isnt appearing over it.

I call  CJDrawer::DrawJumbles(this);
in baseplayer_shared.cpp clientside, under calcview

Header file here: http://pastebin.ca/443839
CPP file here: http://pastebin.ca/443849

And you can see I use GetVectorInScreenSpaceJumble, this is because I have
the camera and text based on where the player's CJumble "pJ" is. Therefore:

bool GetVectorInScreenSpaceJumble( Vector pos, int& iX, int& iY, Vector
*vecOffset )
{
        Vector screen;

        // Apply the offset, if one was specified
        if ( vecOffset != NULL )
                pos += *vecOffset;

        // Transform to screen space
        int iFacing = ScreenTransform( pos, screen );
        iX =  0.5 * screen[0] * ScreenWidth();
        iY = -0.5 * screen[1] * ScreenHeight();
        iX += 0.5 * ScreenWidth();
        iY += 0.5 * ScreenHeight();

       //Cut out playing facing calculations since we calculate off the
CJumble


        return true;
}




From: Oliver <[EMAIL PROTECTED]>
Reply-To: [email protected]
To: [email protected]
Subject: Re: [hlcoders] Client Side Text
Date: Mon, 16 Apr 2007 16:28:11 -0400

--
[ Picked text/plain from multipart/alternative ]
1) Declare as a private variable for the class:
vgui::HFont m_hFont;

Be sure to set it to a font in the constructor, we set to trebuchet:
m_hFont = g_hFontTrebuchet24;

2) Declare as a private variable for the class:
wchar_t sIDString[256];

3) You're right, code could be cleaned by moving variable declaration out
of
Paint method.

Good luck!

On 4/16/07, Dest Romano <[EMAIL PROTECTED]> wrote:
>
> Hello, That looks like a really great method of drawing text so I coded
it
> in. I have three questions
>
> 1) Where is m_hFont declared and how could I access m_hFont
> 2) Where is sIDString declared and what type of variable is it (char*
> dosen't seem to work)
> 3) Why do you declare so many variables in a class that will run every
> frame, why not just storing them on the player under public?
>
> Thanks for the method Oliver!
> -Dest
>
>
> >From: Oliver <[EMAIL PROTECTED]>
> >Reply-To: [email protected]
> >To: [email protected]
> >Subject: Re: [hlcoders] Client Side Text
> >Date: Sun, 15 Apr 2007 23:11:22 -0400
> >
> >--
> >[ Picked text/plain from multipart/alternative ]
> >Here's how we did it:
> >
> >Create a client-side class that extends CHudElement and vgui::Panel
> >
> >The Paint method is used to draw the text (fade as distance increases).
> >The
> >InView method determines if the other player is in view of the local
> >player.
> >
> >I make no claims to the elegance of this code, but it does work.  :)
> >
> >void YourClassName::Paint()
> >{
> >     C_HL2MP_Player *pLocalPlayer =
> C_HL2MP_Player::GetLocalHL2MPPlayer();
> >
> >     if ( !pLocalPlayer )
> >         return;
> >
> >     Vector origin;
> >     int x, y, length, wide, tall, offsetZ, alpha;
> >     for ( int iEntIndex = 0; iEntIndex <
> >cl_entitylist->NumberOfEntities();
> >iEntIndex++ )
> >     {
> >         if ( IsPlayerIndex( iEntIndex ) )
> >         {
> >             C_BasePlayer *pPlayer =
> >static_cast<C_BasePlayer*>(cl_entitylist->GetEnt( iEntIndex ));
> >
> >             if( pPlayer && !pPlayer->IsLocalPlayer() )
> >             {
> >                 if(InView(pLocalPlayer, pPlayer))
> >                 {
> >                     sIDString[0] = 0;
> >
> >vgui::localize()->ConvertANSIToUnicode(pPlayer->GetPlayerName(),
> sIDString,
> >sizeof(sIDString));
> >
> >                     length = (pPlayer->GetAbsOrigin() -
> >pLocalPlayer->GetAbsOrigin()).Length();
> >                     offsetZ = 72;
> >                     offsetZ += (length - 80)/12.6;
> >                     if(length <= 400) alpha = 255;
> >                     else
> >                     {
> >                         alpha = 655 - length;
> >                         if(alpha < 0) alpha = 0;
> >                     }
> >
> >
> >                     vgui::surface()->GetTextSize( m_hFont, sIDString,
> >wide,
> >tall );
> >
> >                     Vector offset = Vector(0,0,offsetZ);
> >                     GetVectorInScreenSpace(pPlayer->GetAbsOrigin(), x,
> y,
> >&offset);
> >                     x -= wide/2;
> >
> >                     vgui::surface()->DrawSetTextFont(m_hFont);
> >                     vgui::surface()->DrawSetTextPos(x, y);
> >
> >vgui::surface()->DrawSetTextColor(Color(255,255,255,alpha));
> >                     vgui::surface()->DrawPrintText(sIDString,
> >wcslen(sIDString));
> >                 }
> >             }
> >         }
> >     }
> >}
> >
> >bool YourClassName::InView(C_BasePlayer *pLocalPlayer, C_BasePlayer
> >*pPlayer)
> >{
> >     // Clip text that is far away
> >     if((pLocalPlayer->GetAbsOrigin() -
> >pPlayer->GetAbsOrigin()).LengthSqr()
> > > 90000000) return false;
> >
> >     // Clip text that is behind the client
> >     Vector clientForward;
> >     pLocalPlayer->EyeVectors( &clientForward );
> >
> >     Vector toText    = pPlayer->GetAbsOrigin() -
> >pLocalPlayer->GetAbsOrigin();
> >      float  dotPr    = DotProduct(clientForward,toText);
> >
> >     if (dotPr < 0) return false;
> >
> >     //Clip text that is obscured
> >     trace_t tr;
> >     Vector forward = pPlayer->GetAbsOrigin() -
> >pLocalPlayer->GetAbsOrigin();
> >     int length = forward.Length();
> >     forward.NormalizeInPlace();
> >     UTIL_TraceLine(pLocalPlayer->Weapon_ShootPosition(), forward *
> >MAX_TRACE_LENGTH, (MASK_SHOT & ~CONTENTS_WINDOW), pLocalPlayer,
> >COLLISION_GROUP_NONE, &tr);
> >
> >     if((tr.endpos - pLocalPlayer->GetAbsOrigin()).Length() < length)
> >     {
> >         return false;
> >     }
> >     return true;
> >}
> >
> >On 4/15/07, Dest Romano <[EMAIL PROTECTED]> wrote:
> > >
> > > Hello everyone,
> > >
> > > I am attempting to draw text over other players' heads.
> > >
> > > Serverside, NDebugOverlay::Text works perfectly fine
> > > However, I don't want to draw text over myself, so I am going to
draw
> it
> > > client side.
> > >
> > > When I do NDebugOverlay::Text clientside, it gives me an unresolved
> > > external
> > > symbol.
> > >
> > > I do have debugoverlay_shared.h included, and it is in game_shared,
so
> I
> > > don't see what is wrong.
> > >
> > > baseplayer_shared.obj : error LNK2019: unresolved external symbol
> "void
> > > __cdecl NDebugOverlay::Text(class Vector const &,char const
> >*,bool,float)"
> > > ([EMAIL PROTECTED]@@YAXABVVector@@[EMAIL PROTECTED]) referenced in 
function
> > > "public: virtual void __thiscall
C_BasePlayer::DrawJumbleNames(void)"
> > > ([EMAIL PROTECTED]@@UAEXXZ)
> > > 1>Release HL2MP/client.dll : fatal error LNK1120: 1 unresolved
> externals
> > >
> > > If anyone has another more flexible method of drawing text over
> entities
> > > client side, or a solution to this error, I would love to hear it!
> > >
> > > Thanks,
> > > Dest
> > >
>
> _________________________________________________________________
> MSN is giving away a trip to Vegas to see Elton John. Enter to win
today.
> http://msnconcertcontest.com?icid-nceltontagline
>
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list archives,
> please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>
--

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders


_________________________________________________________________
Can’t afford to quit your job? – Earn your AS, BS, or MS degree online in 1
year.
http://www.classesusa.com/clickcount.cfm?id=866145&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866143


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to