xbdev - software development
Sunday June 16, 2024
Home | Contact | Support | XBOX Programming.. More than just a toy...

XBOX Programming..

More than just a toy...


Text Out using TTF Fonts

Author: Ben_3D@xbdev.net



Using TTF Font's (True Type Fonts)....which you can find of on your PC....there's usually loads of them...we can output various information on the screen...in loads of cool styles.


Why don't we usually use TTF (True Type Fonts)?...hmm?...well in the xdk docs it says that TTF Fonts affect performance....but well...on occasion it can't harm....not if we want some simple feedback...or where doing some simple app for the xbox.


The code that you need is simple!...its really simple....the one thing not to forget though is this line:  "#define XFONT_TRUETYPE" it may look simple...but its not....make sure you put it just before you put the "#include <xfont.h>".  Then you'll find it all as simple as pie :)


This is all the code that does the Text Output....well don't forget I did it in a single function like this...so you could see it easily!...what it needs to create a file...and what you need to release when you've finished with your fonts.  Please download the full main.cpp to take a looksy at the whole code and play around with it.




#include <xfont.h> //used for directX textout




// Now don't forget to put the "times.ttf" file or whatever ttf file your

// going to use for your font, with your xbox executable (xbe).


void DisplayText()


      //Create some DirectX text buffers

      XFONT*                        pFont; 

      LPDIRECT3DSURFACE8      pFrontBuffer;




      DWORD dwFontCacheSize = 16 * 1024;


      XFONT_OpenTrueTypeFont(L"D:\\times.ttf", dwFontCacheSize, &pFont );


      // pFont->SetTextHeight(48);

      // pFont->SetTextColor(D3DCOLOR_XRGB(30,255,20));


      WCHAR szbuff[200] = {0};

      swprintf(szbuff, L"Hello World");

      //Top left corner of where we want to draw our text.

      float xpos = 100.0f;

      float ypos = 100.0f;


      //Display our text.



      pFont->TextOut( pFrontBuffer, szbuff, -1, (long)xpos, (long)ypos );


      //Release our TextBuffers



}// End DisplayText()



Simple code is the best code I always say :)




Advert (Support Website)

Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.