In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Difference between revisions of "FreeTypeGX"

From WiiBrew
Jump to navigation Jump to search
(Undo revision 38203 by ArminTamzarian (Talk))
(Update for version 0.2.2)
Line 6: Line 6:
 
| display = Any
 
| display = Any
 
| author = [[User:ArminTamzarian|Armin Tamzarian]]
 
| author = [[User:ArminTamzarian|Armin Tamzarian]]
| version = 0.2.1
+
| version = 0.2.2
 
| download = [http://code.google.com/p/freetypegx/ Here]
 
| download = [http://code.google.com/p/freetypegx/ Here]
 
}}
 
}}
Line 23: Line 23:
 
# Extract the FreeTypeGX archive.
 
# Extract the FreeTypeGX archive.
 
# Copy the contents of the src directory into your project's development path.
 
# Copy the contents of the src directory into your project's development path.
# Place a copy of the desired TrueType or OpenType font you wish to use in the FreeTypeGX/ttf directory.
 
# Modify the fontface.s file and change the value of the incbin variable to point to your font.
 
# Modify the fontface.s file and change the value of the fontsize variable to the byte-size of the font file.
 
 
# Include the FreeTypeGX header file in your code using syntax such as the following:  
 
# Include the FreeTypeGX header file in your code using syntax such as the following:  
 
  #include "FreeTypeGX.h"  
 
  #include "FreeTypeGX.h"  
Line 37: Line 34:
 
  #include "FreeTypeGX.h"  
 
  #include "FreeTypeGX.h"  
  
==Usage==
+
==FreTypeGX Prerequisites==
* Within the file you included the FreeTypeGX.h file create an instance object of the FreeTypeGX class passing in the desired font point size:
+
Before you begin using FreeTypeGX in your project you must ensure that the desired font in compiled into your project. For this example I will assume you are building your project with a Makefile using devKitPro evironment and are attempting to include a font whose filename is rursus_compact_mono.ttf.
  
  FreeTypeGX *freeTypeGX = new FreeTypeGX(32);
+
* Copy the font into a directory which will be processed by the project's Makefile. If you are unsure about where you should place your font just copy the it into your project's source directory.
 +
* Modify the Makefile to convert the font into an object file:
 +
  %.ttf.o : %.ttf
 +
    @echo $(notdir $<)
 +
    $(bin2o)
 +
* Include the font object's generated header file in your source code:
 +
#include "rursus_compact_mono_ttf.h"
  
:Alternately you can specify a texture format you would like to which you would like to render the font characters.
+
:This header file defines the two variables that you will need for use within your project:
  
  FreeTypeGX *freeTypeGX = new FreeTypeGX(32, GX_TF_RGB565);
+
  extern const u8 rursus_compact_mono_ttf[];     A pointer to the font buffer within the compiled project.
 +
extern const u32 rursus_compact_mono_ttf_size; The size of the font's buffer in bytes.
  
:Furthermore you can also specify a third flag which will load and cache all available font glyphs immidiately. Note that on large font sets enabling this feature could take a significant amount of time.
+
==FreeTypeGX Usage==
 +
* Within the file you included the FreeTypeGX.h file create an instance object of the FreeTypeGX class:
  
  FreeTypeGX *freeTypeGX = new FreeTypeGX(32, GX_TF_RGB565, true);
+
  FreeTypeGX *freeTypeGX = new FreeTypeGX();
 +
 
 +
:Alternately you can specify a texture format to which you would like to render the font characters. Note that the default value for this parameter is GX_TF_RGBA8.
 +
 
 +
FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565);
 +
 
 +
:Furthermore, you can also specify a positional format as defined in your graphics subsystem initialization. Note that the default value for this parameter is GX_POS_XYZ.
 +
 
 +
FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565, GX_POS_XY);
  
 
:Currently supported textures are:
 
:Currently supported textures are:
Line 58: Line 71:
 
:* GX_TF_RGB5A3
 
:* GX_TF_RGB5A3
 
:* GX_TF_RGBA8
 
:* GX_TF_RGBA8
 +
 +
:Currently supported position formats are:
 +
:* GX_POS_XY
 +
:* GX_POS_XYZ
 +
 +
* Using the allocated FreeTypeGX instance object call the loadFont function to load the font from the compiled buffer and specify the desired point size:
 +
 +
fontSystem->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64);
 +
 +
:Alternately you can specify a flag which will load and cache all available font glyphs immidiately. Note that on large font sets enabling this feature could take a significant amount of time.
 +
 +
fontSystem->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64, true);
  
 
* Using the allocated FreeTypeGX instance object call the drawText function to print a string at the specified screen X and Y coordinates to the current EFB:
 
* Using the allocated FreeTypeGX instance object call the drawText function to print a string at the specified screen X and Y coordinates to the current EFB:

Revision as of 23:23, 16 January 2009

FreeTypeGX
FreeTypeGX.png
General
Author(s)Armin Tamzarian
TypeDevelopment
Version0.2.2
Links
[[Here|Download]]

FreeTypeGX is a wrapper class for libFreeType which renders a compiled FreeType parsable font into a GX texture for Wii homebrew development. FreeTypeGX is written in C++ and makes use of a selectable pre-buffered or buffer-on-demand methodology to allow fast and efficient printing of text to the EFB.

Note: As of version 0.2.1 FreeTypeGX has forked into two disparate projects and now relies upon the Metaphrasis library.

This library was developed in-full by Armin Tamzarian with the support of developers in #wiibrew on EFnet, Chaosteil of libwiisprite, and DrTwox of GRRLIB.

Full Doxygen API documentation is included within the download archive for assistance with program integration.

Installation (Source Code)

  1. Ensure that you have the libFreeType Wii library installed in your development environment.
  2. Ensure that you have the Metaphrasis library installed in your development environment with the library added to your Makefile where appropriate.
  3. Extract the FreeTypeGX archive.
  4. Copy the contents of the src directory into your project's development path.
  5. Include the FreeTypeGX header file in your code using syntax such as the following:
#include "FreeTypeGX.h" 

Installation (Library)

  1. Ensure that you have the libFreeType Wii library installed in your development environment.
  2. Ensure that you have the Metaphrasis library installed in your development environment with the library added to your Makefile where appropriate.
  3. Extract the FreeTypeGX archive.
  4. Copy the contents of the lib directory into your devKitPro/libogc directory.
  5. Include the FreeTypeGX header file in your code using syntax such as the following:
#include "FreeTypeGX.h" 

FreTypeGX Prerequisites

Before you begin using FreeTypeGX in your project you must ensure that the desired font in compiled into your project. For this example I will assume you are building your project with a Makefile using devKitPro evironment and are attempting to include a font whose filename is rursus_compact_mono.ttf.

  • Copy the font into a directory which will be processed by the project's Makefile. If you are unsure about where you should place your font just copy the it into your project's source directory.
  • Modify the Makefile to convert the font into an object file:
%.ttf.o : %.ttf
    @echo $(notdir $<)
    $(bin2o)
  • Include the font object's generated header file in your source code:
#include "rursus_compact_mono_ttf.h"
This header file defines the two variables that you will need for use within your project:
extern const u8 rursus_compact_mono_ttf[];     A pointer to the font buffer within the compiled project.
extern const u32 rursus_compact_mono_ttf_size; The size of the font's buffer in bytes.

FreeTypeGX Usage

  • Within the file you included the FreeTypeGX.h file create an instance object of the FreeTypeGX class:
FreeTypeGX *freeTypeGX = new FreeTypeGX();
Alternately you can specify a texture format to which you would like to render the font characters. Note that the default value for this parameter is GX_TF_RGBA8.
FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565);
Furthermore, you can also specify a positional format as defined in your graphics subsystem initialization. Note that the default value for this parameter is GX_POS_XYZ.
FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565, GX_POS_XY);
Currently supported textures are:
  • GX_TF_I4
  • GX_TF_I8
  • GX_TF_IA4
  • GX_TF_IA8
  • GX_TF_RGB565
  • GX_TF_RGB5A3
  • GX_TF_RGBA8
Currently supported position formats are:
  • GX_POS_XY
  • GX_POS_XYZ
  • Using the allocated FreeTypeGX instance object call the loadFont function to load the font from the compiled buffer and specify the desired point size:
fontSystem->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64);
Alternately you can specify a flag which will load and cache all available font glyphs immidiately. Note that on large font sets enabling this feature could take a significant amount of time.
fontSystem->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64, true);
  • Using the allocated FreeTypeGX instance object call the drawText function to print a string at the specified screen X and Y coordinates to the current EFB:
freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"));
Alternately you can specify a GXColor object you would like to apply to the printed characters:
freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"), (GXColor){0xff, 0xee, 0xaa, 0xff});

License

FreeTypeGX is distributed under the GNU Lesser General Public License.