www.xbdev.net xbdev - software development
Monday December 10, 2018
home | about | contact | Donations

     
 

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.

 

DownloadCode
 

#define XFONT_TRUETYPE   // <-- DON'T FORGET THIS OR ELSE IT WON'T WORK!

#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;

 

      //InitialiseFonts

      g_pD3DDevice->GetBackBuffer(-1,D3DBACKBUFFER_TYPE_MONO,&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->SetTextColor(D3DCOLOR_XRGB(30,255,20));

 

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

 

      //Release our TextBuffers

      pFont->Release();

      pFrontBuffer->Release();

}// End DisplayText()

 

 

Simple code is the best code I always say :)

 

 

 

 
 Visitor: 9534626  { 209.237.238.175 } Copyright (c) 2002-2017 xbdev.net - All rights reserved.
Designated tutorial and software are the property of their respective owners.