Skip to content

Commit

Permalink
0.1.2 - Fixed Font ChromaKey
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Jun 27, 2012
1 parent 231bddc commit 47eeb7c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Changelog:
Added PS3 Font PATHS
- 0.1.1e -
Font Size..
- 0.1.2 -
Fixed Font ChromaKey. now fonts are better displayed

Homebrews built with this lib:
------------------------------
Expand Down
23 changes: 15 additions & 8 deletions include/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include FT_SYNTHESIS_H
#include FT_STROKER_H

#define CHROMAKEY 0x000000ff
#define CHROMAKEY 0x00000000
#define DEFAULT_FONT_SIZE 40

#define LATIN2 0
Expand All @@ -52,16 +52,14 @@ class Font{
Font(const char *Font_Path, Minimum *min);
Font(const int ID, Minimum *min);
~Font();
u32 FontColor;
u32 FontSize;
s32 width;
s32 height;

void ChangeFontColor(u32 color);
void ChangeFontSize(u32 size);


void Printf(u32 x, u32 y,const char *a, ...);
void Printf(u32 x, u32 y, u32 Color,const char *a, ...);
void Printf(u32 x, u32 y, u32 Color, u32 Size,const char *a, ...);
u32 color_depth;
u32 color_pitch;
u32 color_offset;
void Disable_Fonts();

void PrintfToBitmap(u32 x, u32 y, NoRSX_Bitmap* bmap,const char *a, ...);
Expand All @@ -79,6 +77,15 @@ class Font{
FT_Face face;
FT_Bitmap *bitmap;
FT_Vector vec;

u32 FontColor;
u32 FontSize;
s32 width;
s32 height;

u32 color_depth;
u32 color_pitch;
u32 color_offset;

int font;
Minimum *m;
Expand Down
33 changes: 19 additions & 14 deletions source/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ Font::~Font(){
Disable_Fonts();
}

void Font::ChangeFontColor(u32 color){
FontColor = color;
}

void Font::ChangeFontSize(u32 size){
FontSize = size;
FT_Set_Pixel_Sizes(face,0,FontSize);
}

void Font::Disable_Fonts(){
FT_Done_Glyph(glyph);
FT_Stroker_Done(stroker);
Expand Down Expand Up @@ -214,17 +223,16 @@ void Font::Printf(u32 x, u32 y, u32 Color, u32 Size,const char *a, ...){
vsnprintf(text, sizeof text, a, va);
size_t len = strlen(a);
if(len>0){
u32 C_TMP = FontColor, S_TMP = FontSize;
u32 C_TMP = FontColor;
FontColor = Color;
FontSize = Size;
len=strlen(text);
FT_Set_Pixel_Sizes(face,0,Size);
vec.x = 0;
vec.y = FontSize;
vec.y = Size;
FT_GlyphSlot slot = face->glyph;
FT_UInt glyph_index = 0;
FT_UInt previous_glyph = 0;
Kerning = FT_HAS_KERNING(face);
FT_Set_Pixel_Sizes(face,0,FontSize);

for(unsigned int i=0;i<len;i++){
glyph_index = FT_Get_Char_Index(face, text[i]);
Expand All @@ -236,13 +244,12 @@ void Font::Printf(u32 x, u32 y, u32 Color, u32 Size,const char *a, ...){
FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
FT_Get_Glyph(face->glyph, &glyph);
FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
FontDrawBitmap(&slot->bitmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
FontDrawBitmap(&slot->bitmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -Size));
previous_glyph = glyph_index;
vec.x += slot->advance.x >> 6;
vec.y += slot->advance.y >> 6;
}
FontColor = C_TMP;
FontSize = S_TMP;
FT_Set_Pixel_Sizes(face,0,FontSize);

}
Expand All @@ -260,7 +267,7 @@ void Font::FontDrawBitmap(FT_Bitmap *bitmap, s32 offset, s32 top){
for(y = top, j = 0; y < y_max; y++, j++){
if(y >= (s32)M_height) break;
color = bitmap->buffer[bitmap->width * j + i];
if(CHROMAKEY==color)
if(CHROMAKEY!=color)
*(m->buffers[m->currentBuffer].ptr + m->width * y + x) = FontColor;
}
}
Expand Down Expand Up @@ -342,13 +349,12 @@ void Font::PrintfToBitmap(u32 x, u32 y, NoRSX_Bitmap* bmap, u32 Color, u32 Size,
vsnprintf(text, sizeof text, a, va);
size_t len = strlen(a);
if(len>0){
u32 C_TMP = FontColor, S_TMP = FontSize;
u32 C_TMP = FontColor;
FontColor = Color;
FontSize = Size;
len=strlen(text);
FT_Set_Pixel_Sizes(face,0,Size);
vec.x = 0;
vec.y = FontSize;
FT_Set_Pixel_Sizes(face,0,FontSize);
vec.y = Size;
FT_GlyphSlot slot = face->glyph;
FT_UInt glyph_index = 0;
FT_UInt previous_glyph = 0;
Expand All @@ -364,13 +370,12 @@ void Font::PrintfToBitmap(u32 x, u32 y, NoRSX_Bitmap* bmap, u32 Color, u32 Size,
FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
FT_Get_Glyph(face->glyph, &glyph);
FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
FontDrawBitmapToBitmap(&slot->bitmap,bmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
FontDrawBitmapToBitmap(&slot->bitmap,bmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -Size));
previous_glyph = glyph_index;
vec.x += slot->advance.x >> 6;
vec.y += slot->advance.y >> 6;
}
FontColor = C_TMP;
FontSize = S_TMP;
FT_Set_Pixel_Sizes(face,0,FontSize);
}
}
Expand All @@ -389,7 +394,7 @@ void Font::FontDrawBitmapToBitmap(FT_Bitmap *bitmap, NoRSX_Bitmap* bmap, s32 off
for(y = top, j = 0;y < y_max;y++, j++ ){
if(y >= (s32) M_height) break;
color = bitmap->buffer[bitmap->width * j + i];
if(CHROMAKEY==color)
if(CHROMAKEY!=color)
*(bmap->bitmap + m->width * y + x) = FontColor;
}
}
Expand Down
13 changes: 3 additions & 10 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ s32 main(s32 argc, const char* argv[])

Font F1(Sans_ttf,Sans_ttf_size ,GFX); //Loaded from Memory
Font F2("/dev_flash/data/font/SCE-PS3-VR-R-LATIN2.TTF" ,GFX); //Loaded from File!
Font F3(JPN ,GFX); //I'm Using PS3 Original Fonts! These are the available on the ps3: LATIN2 | JPN | KOR | CGB | KANA


IMG.LoadPNG_Buf(NoRSX_Image_png,NoRSX_Image_png_size, &png);
Expand All @@ -77,7 +78,8 @@ s32 main(s32 argc, const char* argv[])

F1.PrintfToBitmap(150,200,&Precalculated_Layer,COLOR_RED,"Screen %d x %d",GFX->width,GFX->height);
F1.PrintfToBitmap(150,250,&Precalculated_Layer,COLOR_BLUE, 35,"Press X to exit!");
F2.PrintfToBitmap(150,300,&Precalculated_Layer,COLOR_GREEN,20,"FreeType2 with TTF support :)");
F2.PrintfToBitmap(150,300,&Precalculated_Layer,COLOR_GREEN,60,"FreeType2 with TTF support :)");
F3.PrintfToBitmap(150,500,&Precalculated_Layer,"Written by deroad");

exitapp = 1;
int frame=0;
Expand All @@ -96,15 +98,6 @@ s32 main(s32 argc, const char* argv[])


BMap.DrawBitmap(&Precalculated_Layer);
/* BG.Mono(0xb4e83a); //a green hex color (you can use hex colors insted of COLOR_XXXXXXX)
IMG.DrawIMG(imgX,imgY,&png);
OBJ.Circle(500,500,50,COLOR_YELLOW);
F1.Printf(150,200,COLOR_RED,"Screen %d x %d",GFX->width,GFX->height);
F1.Printf(150,250,COLOR_BLUE, 35,"Press X to exit!");
F1.Printf(150,100,"FPS %f", fps);
F2.Printf(150,300,COLOR_GREEN,20,"FreeType2 with TTF support :)");
*/
F1.Printf(150,100,"FPS %f", fps);

GFX->Flip();
Expand Down

0 comments on commit 47eeb7c

Please sign in to comment.