mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-21 22:42:20 +00:00
[NEW] FreeType support now available (first support)
This commit is contained in:
parent
81c3a5650f
commit
0d760f99d4
24 changed files with 573 additions and 28 deletions
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
|
||||
#define __GRRLIB_CORE__
|
||||
#include <grrlib.h>
|
||||
#include "grrlib/GRRLIB_ttf.h"
|
||||
|
||||
#define DEFAULT_FIFO_SIZE (256 * 1024) /**< GX fifo buffer size. */
|
||||
|
||||
|
@ -161,6 +162,9 @@ int GRRLIB_Init (void) {
|
|||
// Initialise the filing system
|
||||
if (!fatInitDefault()) error_code = -2;
|
||||
|
||||
// Initialise TTF
|
||||
if (GRRLIB_InitTTF()) error_code = -3;
|
||||
|
||||
VIDEO_SetBlack(false); // Enable video output
|
||||
return error_code;
|
||||
}
|
||||
|
@ -192,4 +196,7 @@ void GRRLIB_Exit (void) {
|
|||
if (xfb[0] != NULL) { free(MEM_K1_TO_K0(xfb[0])); xfb[0] = NULL; }
|
||||
if (xfb[1] != NULL) { free(MEM_K1_TO_K0(xfb[1])); xfb[1] = NULL; }
|
||||
if (gp_fifo != NULL) { free(gp_fifo); gp_fifo = NULL; }
|
||||
|
||||
// Done with TTF
|
||||
GRRLIB_ExitTTF();
|
||||
}
|
||||
|
|
238
GRRLIB/GRRLIB/GRRLIB_ttf.c
Normal file
238
GRRLIB/GRRLIB/GRRLIB_ttf.c
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
Copyright (c) 2009 The GRRLIB Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include <grrlib.h>
|
||||
#include "grrlib/GRRLIB_ttf.h"
|
||||
#include <wchar.h>
|
||||
|
||||
static FT_Library ftLibrary; /**< A handle to a FreeType library instance. */
|
||||
|
||||
// Static function prototypes
|
||||
static void DrawBitmap(FT_Bitmap *bitmap, int offset, int top, const u32 color) ;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize FreeType library.
|
||||
* @return int 0=OK; -1=Failed
|
||||
* @see GRRLIB_ExitFreetype
|
||||
*/
|
||||
int GRRLIB_InitTTF () {
|
||||
if (FT_Init_FreeType(&ftLibrary)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this when your done with FreeType.
|
||||
*/
|
||||
void GRRLIB_ExitTTF (void) {
|
||||
FT_Done_FreeType(ftLibrary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a TTF from a buffer.
|
||||
* @param file_base Buffer with TTF data.
|
||||
* @param file_size Size of the TTF buffer.
|
||||
* @return A handle to a given TTF font object.
|
||||
* @see GRRLIB_FreeTTF
|
||||
*/
|
||||
GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) {
|
||||
GRRLIB_ttfFont* myFont = (GRRLIB_ttfFont*)malloc(sizeof(GRRLIB_ttfFont));
|
||||
FT_New_Memory_Face(ftLibrary, file_base, file_size, 0, &myFont->face);
|
||||
myFont->kerning = FT_HAS_KERNING(myFont->face);
|
||||
/*
|
||||
if (FT_Set_Pixel_Sizes(myFont->face, 0, fontSize)) {
|
||||
FT_Set_Pixel_Sizes(myFont->face, 0, 12);
|
||||
}
|
||||
*/
|
||||
return myFont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory allocated by TTF fonts.
|
||||
* @param myFont A TTF.
|
||||
*/
|
||||
void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) {
|
||||
FT_Done_Face(myFont->face);
|
||||
free(myFont);
|
||||
myFont = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print function for TTF font.
|
||||
* @param x Specifies the x-coordinate of the upper-left corner of the text.
|
||||
* @param y Specifies the y-coordinate of the upper-left corner of the text.
|
||||
* @param myFont A TTF.
|
||||
* @param string Text to draw.
|
||||
* @param fontSize Size of the font.
|
||||
* @param color Text color in RGB format.
|
||||
*/
|
||||
void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize, const u32 color) {
|
||||
size_t length = strlen(string) + 1;
|
||||
wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
|
||||
utf32[length] = '\0';
|
||||
mbstowcs(utf32, string, length);
|
||||
|
||||
GRRLIB_PrintfTTFW(x, y, myFont, utf32, fontSize, color);
|
||||
|
||||
free(utf32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print function for TTF font.
|
||||
* @author wplaat and DrTwox
|
||||
* @param x Specifies the x-coordinate of the upper-left corner of the text.
|
||||
* @param y Specifies the y-coordinate of the upper-left corner of the text.
|
||||
* @param myFont A TTF.
|
||||
* @param utf32 Text to draw.
|
||||
* @param fontSize Size of the font.
|
||||
* @param color Text color in RGB format.
|
||||
*/
|
||||
void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *utf32, unsigned int fontSize, const u32 color) {
|
||||
unsigned int loop;
|
||||
int penX = 0;
|
||||
int penY = fontSize;
|
||||
FT_GlyphSlot slot = myFont->face->glyph;
|
||||
FT_UInt glyphIndex = 0;
|
||||
FT_UInt previousGlyph = 0;
|
||||
|
||||
if (FT_Set_Pixel_Sizes(myFont->face, 0, fontSize)) {
|
||||
FT_Set_Pixel_Sizes(myFont->face, 0, 12);
|
||||
}
|
||||
|
||||
size_t length = wcslen(utf32);
|
||||
|
||||
/* Loop over each character, until the
|
||||
* end of the string is reached, or until the pixel width is too wide */
|
||||
for (loop = 0; loop < length; ++loop) {
|
||||
glyphIndex = FT_Get_Char_Index(myFont->face, utf32[ loop ]);
|
||||
|
||||
/* To the best of my knowledge, none of the other freetype
|
||||
* implementations use kerning */
|
||||
if (myFont->kerning && previousGlyph && glyphIndex) {
|
||||
FT_Vector delta;
|
||||
FT_Get_Kerning(myFont->face, previousGlyph, glyphIndex, FT_KERNING_DEFAULT, &delta);
|
||||
penX += delta.x >> 6;
|
||||
}
|
||||
if (FT_Load_Glyph(myFont->face, glyphIndex, FT_LOAD_RENDER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DrawBitmap(&slot->bitmap,
|
||||
penX + slot->bitmap_left + x,
|
||||
penY - slot->bitmap_top + y,
|
||||
color);
|
||||
penX += slot->advance.x >> 6;
|
||||
previousGlyph = glyphIndex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a character on the screen.
|
||||
* @param bitmap Bitmap to draw.
|
||||
* @param offset x-coordinate offset.
|
||||
* @param top y-coordinate.
|
||||
* @param color character color in RGB format.
|
||||
*/
|
||||
static void DrawBitmap(FT_Bitmap *bitmap, int offset, int top, const u32 color) {
|
||||
FT_Int i, j, p, q;
|
||||
FT_Int x_max = offset + bitmap->width;
|
||||
FT_Int y_max = top + bitmap->rows;
|
||||
|
||||
for ( i = offset, p = 0; i < x_max; i++, p++ ) {
|
||||
for ( j = top, q = 0; j < y_max; j++, q++ ) {
|
||||
GRRLIB_Plot( i, j,
|
||||
RGBA((color >> 16) & 0xFF,
|
||||
(color >> 8) & 0xFF,
|
||||
color & 0xFF,
|
||||
bitmap->buffer[ q * bitmap->width + p ]) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a text in pixel.
|
||||
* @param myFont A TTF.
|
||||
* @param string The text to check.
|
||||
* @param fontSize The size of the font.
|
||||
* @return The width of a text in pixel.
|
||||
*/
|
||||
unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize) {
|
||||
if(string == NULL) {
|
||||
return 0;
|
||||
}
|
||||
unsigned int penX;
|
||||
size_t length = strlen(string) + 1;
|
||||
wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
|
||||
utf32[length] = '\0';
|
||||
length = mbstowcs(utf32, string, length);
|
||||
|
||||
penX = GRRLIB_WidthTTFW(myFont, utf32, fontSize);
|
||||
|
||||
free(utf32);
|
||||
|
||||
return penX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a text in pixel.
|
||||
* @param myFont A TTF.
|
||||
* @param utf32 The text to check.
|
||||
* @param fontSize The size of the font.
|
||||
* @return The width of a text in pixel.
|
||||
*/
|
||||
unsigned int GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *utf32, unsigned int fontSize) {
|
||||
unsigned int loop;
|
||||
unsigned int penX = 0;
|
||||
FT_UInt glyphIndex;
|
||||
FT_UInt previousGlyph = 0;
|
||||
size_t length;
|
||||
|
||||
if(utf32 == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(FT_Set_Pixel_Sizes(myFont->face, 0, fontSize)) {
|
||||
FT_Set_Pixel_Sizes(myFont->face, 0, 12);
|
||||
}
|
||||
|
||||
length = wcslen(utf32);
|
||||
|
||||
for(loop = 0; loop < length; ++loop) {
|
||||
glyphIndex = FT_Get_Char_Index(myFont->face, utf32[ loop ]);
|
||||
|
||||
if(myFont->kerning && previousGlyph && glyphIndex) {
|
||||
FT_Vector delta;
|
||||
FT_Get_Kerning(myFont->face, previousGlyph, glyphIndex, FT_KERNING_DEFAULT, &delta);
|
||||
penX += delta.x >> 6;
|
||||
}
|
||||
if(FT_Load_Glyph(myFont->face, glyphIndex, FT_LOAD_RENDER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
penX += myFont->face->glyph->advance.x >> 6;
|
||||
previousGlyph = glyphIndex;
|
||||
}
|
||||
|
||||
return penX;
|
||||
}
|
|
@ -37,6 +37,8 @@ THE SOFTWARE.
|
|||
// Includes
|
||||
//==============================================================================
|
||||
#include <gccore.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
//==============================================================================
|
||||
|
||||
//==============================================================================
|
||||
|
@ -137,15 +139,24 @@ typedef struct GRRLIB_bytemapChar {
|
|||
* Structure to hold the bytemap font information.
|
||||
*/
|
||||
typedef struct GRRLIB_bytemapFont {
|
||||
char *name; /**< Font name. */
|
||||
u32 *palette; /**< Font palette. */
|
||||
u16 nbChar; /**< Number of characters in font. */
|
||||
u8 version; /**< Version. */
|
||||
s8 tracking; /**< Tracking (Add-space after each char) (-128 to 127). */
|
||||
char *name; /**< Font name. */
|
||||
u32 *palette; /**< Font palette. */
|
||||
u16 nbChar; /**< Number of characters in font. */
|
||||
u8 version; /**< Version. */
|
||||
s8 tracking; /**< Tracking (Add-space after each char) (-128 to 127). */
|
||||
|
||||
GRRLIB_bytemapChar *charDef; /**< Array of bitmap characters. */
|
||||
GRRLIB_bytemapChar *charDef; /**< Array of bitmap characters. */
|
||||
} GRRLIB_bytemapFont;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
* Structure to hold the TTF information.
|
||||
*/
|
||||
typedef struct GRRLIB_Font {
|
||||
FT_Face face; /**< A TTF face object. */
|
||||
FT_Bool kerning; /**< true whenever a face object contains kerning data that can be accessed with FT_Get_Kerning. */
|
||||
} GRRLIB_ttfFont;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
* This structure contains information about the type, size, and layout of a file that containing a device-independent bitmap (DIB).
|
||||
|
|
|
@ -148,5 +148,13 @@ void GRRLIB_2dMode();
|
|||
void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz);
|
||||
void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// GRRLIB_Freetype.c - FreeType function for GRRLIB
|
||||
GRRLIB_ttfFont* GRRLIB_LoadTTF(const u8* file_base, s32 file_size);
|
||||
void GRRLIB_FreeTTF(GRRLIB_ttfFont *myFont);
|
||||
void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize, const u32 color);
|
||||
void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *string, unsigned int fontSize, const u32 color);
|
||||
unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *, unsigned int);
|
||||
unsigned int GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *, unsigned int);
|
||||
|
||||
#endif // __GRRLIB_FNLIB_H__
|
||||
|
|
24
GRRLIB/GRRLIB/grrlib/GRRLIB_ttf.h
Normal file
24
GRRLIB/GRRLIB/grrlib/GRRLIB_ttf.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
Copyright (c) 2009 The GRRLIB Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int GRRLIB_InitTTF();
|
||||
void GRRLIB_ExitTTF();
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -34,7 +34,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
|
|||
# any extra libraries we wish to link with the project
|
||||
# the order can-be/is critical
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat
|
||||
LIBS += -lwiiuse
|
||||
#LIBS += -lmodplay -lasnd
|
||||
LIBS += -lbte -logc -lm
|
||||
|
|
157
examples/ttf/Makefile
Normal file
157
examples/ttf/Makefile
Normal file
|
@ -0,0 +1,157 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
# Clear the implicit built in rules
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITPPC)),)
|
||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||
endif
|
||||
|
||||
include $(DEVKITPPC)/wii_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
|
||||
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
# the order can-be/is critical
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib
|
||||
LIBS += -lfreetype
|
||||
LIBS += -lpngu -lpng -ljpeg -lz -lfat
|
||||
LIBS += -lwiiuse
|
||||
#LIBS += -lmodplay -lasnd
|
||||
LIBS += -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# automatically build a list of object files for our project
|
||||
#---------------------------------------------------------------------------------
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
export LD := $(CC)
|
||||
else
|
||||
export LD := $(CXX)
|
||||
endif
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
$(sFILES:.s=.o) $(SFILES:.S=.o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of include paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD) \
|
||||
-I$(LIBOGC_INC)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of library paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
|
||||
-L$(LIBOGC_LIB)
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
.PHONY: $(BUILD) clean
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
run:
|
||||
wiiload $(TARGET).dol
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).dol: $(OUTPUT).elf
|
||||
$(OUTPUT).elf: $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .jpg extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.jpg.o : %.jpg
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .png extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.png.o : %.png
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .ttf extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.ttf.o : %.ttf
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
BIN
examples/ttf/data/FreeMonoBold.ttf
Normal file
BIN
examples/ttf/data/FreeMonoBold.ttf
Normal file
Binary file not shown.
57
examples/ttf/source/main.c
Normal file
57
examples/ttf/source/main.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*===========================================
|
||||
TrueType Font demo
|
||||
============================================*/
|
||||
#include <grrlib.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <wiiuse/wpad.h>
|
||||
|
||||
// Font
|
||||
#include "FreeMonoBold_ttf.h"
|
||||
|
||||
extern GXRModeObj *rmode;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Initialise the Graphics & Video subsystem
|
||||
GRRLIB_Init();
|
||||
GRRLIB_ttfFont *myFont = GRRLIB_LoadTTF(FreeMonoBold_ttf, FreeMonoBold_ttf_size);
|
||||
|
||||
GRRLIB_texImg *CopiedImg = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);
|
||||
|
||||
// Initialise the Wii Remotes
|
||||
WPAD_Init();
|
||||
|
||||
// Loop forever
|
||||
while(1) {
|
||||
GRRLIB_DrawImg(0, 0, CopiedImg, 0, 1, 1, 0xFFFFFFFF);
|
||||
char Letter[2] = {rand() % 93 + 32, '\0'};
|
||||
GRRLIB_PrintfTTF(rand() % rmode->fbWidth - 50,
|
||||
rand() % rmode->efbHeight - 50,
|
||||
myFont,
|
||||
Letter,
|
||||
rand() % 180 + 20,
|
||||
rand() % 0xFFFFFF);
|
||||
GRRLIB_Screen2Texture(0, 0, CopiedImg, false);
|
||||
|
||||
GRRLIB_Render(); // Render the frame buffer to the TV
|
||||
|
||||
WPAD_ScanPads(); // Scan the Wii Remotes
|
||||
|
||||
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
|
||||
break;
|
||||
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) {
|
||||
GRRLIB_Rectangle(0, 0, rmode->fbWidth, rmode->efbHeight, 0x000000FF, 1);
|
||||
GRRLIB_Screen2Texture(0, 0, CopiedImg, false);
|
||||
}
|
||||
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_1 && WPAD_ButtonsHeld(0) & WPAD_BUTTON_2) {
|
||||
WPAD_Rumble(0, true); // Rumble on
|
||||
GRRLIB_ScrShot("sd:/grrlib_ttf.png");
|
||||
WPAD_Rumble(0, false); // Rumble off
|
||||
}
|
||||
}
|
||||
|
||||
GRRLIB_FreeTTF(myFont);
|
||||
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
|
||||
|
||||
exit(0); // Use exit() to exit a program, do not use 'return' from main()
|
||||
}
|
|
@ -34,7 +34,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--section-start,.init=0x81
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -34,7 +34,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--section-start,.init=0x81
|
|||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
LIBS := -lgrrlib -lfreetype -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Doxyfile 1.6.1
|
||||
# Doxyfile 1.6.2
|
||||
|
||||
# This file describes the settings to be used by the documentation system
|
||||
# doxygen (www.doxygen.org) for a project
|
||||
|
@ -397,6 +397,12 @@ HIDE_SCOPE_NAMES = YES
|
|||
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
|
||||
# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
|
||||
# will list include files with double quotes in the documentation
|
||||
# rather than with sharp brackets.
|
||||
|
||||
FORCE_LOCAL_INCLUDES = NO
|
||||
|
||||
# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
|
||||
# is inserted in the documentation for inline members.
|
||||
|
||||
|
@ -811,6 +817,12 @@ HTML_FOOTER =
|
|||
|
||||
HTML_STYLESHEET =
|
||||
|
||||
# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
|
||||
# page will contain the date and time when the page was generated. Setting
|
||||
# this to NO can help when comparing the output of multiple runs.
|
||||
|
||||
HTML_TIMESTAMP = NO
|
||||
|
||||
# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
|
||||
# files or namespaces will be aligned in HTML using tables. If set to
|
||||
# NO a bullet list will be used.
|
||||
|
@ -912,7 +924,7 @@ QCH_FILE =
|
|||
# Qt Help Project output. For more information please see
|
||||
# http://doc.trolltech.com/qthelpproject.html#namespace
|
||||
|
||||
QHP_NAMESPACE =
|
||||
QHP_NAMESPACE = org.doxygen.Project
|
||||
|
||||
# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
|
||||
# Qt Help Project output. For more information please see
|
||||
|
@ -944,6 +956,23 @@ QHP_SECT_FILTER_ATTRS =
|
|||
|
||||
QHG_LOCATION =
|
||||
|
||||
# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
|
||||
# will be generated, which together with the HTML files, form an Eclipse help
|
||||
# plugin. To install this plugin and make it available under the help contents
|
||||
# menu in Eclipse, the contents of the directory containing the HTML and XML
|
||||
# files needs to be copied into the plugins directory of eclipse. The name of
|
||||
# the directory within the plugins directory should be the same as
|
||||
# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
|
||||
# the help appears.
|
||||
|
||||
GENERATE_ECLIPSEHELP = NO
|
||||
|
||||
# A unique identifier for the eclipse help plugin. When installing the plugin
|
||||
# the directory name containing the HTML and XML files should also have
|
||||
# this name.
|
||||
|
||||
ECLIPSE_DOC_ID = org.doxygen.Project
|
||||
|
||||
# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
|
||||
# top of each HTML page. The value NO (the default) enables the index and
|
||||
# the value YES disables it.
|
||||
|
@ -984,15 +1013,26 @@ TREEVIEW_WIDTH = 250
|
|||
|
||||
FORMULA_FONTSIZE = 10
|
||||
|
||||
# When the SEARCHENGINE tag is enable doxygen will generate a search box
|
||||
# When the SEARCHENGINE tag is enabled doxygen will generate a search box
|
||||
# for the HTML output. The underlying search engine uses javascript
|
||||
# and DHTML and should work on any modern browser. Note that when using
|
||||
# HTML help (GENERATE_HTMLHELP) or Qt help (GENERATE_QHP)
|
||||
# there is already a search function so this one should typically
|
||||
# be disabled.
|
||||
# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
|
||||
# (GENERATE_DOCSET) there is already a search function so this one should
|
||||
# typically be disabled. For large projects the javascript based search engine
|
||||
# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
|
||||
|
||||
SEARCHENGINE = YES
|
||||
|
||||
# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
|
||||
# implemented using a PHP enabled web server instead of at the web client
|
||||
# using Javascript. Doxygen will generate the search PHP script and index
|
||||
# file to put on the web server. The advantage of the server
|
||||
# based approach is that it scales better to large projects and allows
|
||||
# full text search. The disadvances is that it is more difficult to setup
|
||||
# and does not have live searching capabilities.
|
||||
|
||||
SERVER_BASED_SEARCH = NO
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
|
@ -1009,7 +1049,10 @@ GENERATE_LATEX = NO
|
|||
LATEX_OUTPUT = latex
|
||||
|
||||
# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
|
||||
# invoked. If left blank `latex' will be used as the default command name.
|
||||
# invoked. If left blank `latex' will be used as the default command name.
|
||||
# Note that when enabling USE_PDFLATEX this option is only used for
|
||||
# generating bitmaps for formulas in the HTML output, but not in the
|
||||
# Makefile that is written to the output directory.
|
||||
|
||||
LATEX_CMD_NAME = latex
|
||||
|
||||
|
|
Loading…
Reference in a new issue