Welcome! Log In Create A New Profile

Advanced

FreeTypeGX runtime bug

Posted by g_man 
FreeTypeGX runtime bug
January 06, 2010 01:48AM
I'm trying to get text to work with FreeTypeGX, but nothing is happening, and the documentation is of much help. When I run my program with the draw text command, the screen just stays black. I thought this error might have been caused from incompatable libs, but even when i use FreeTypeGX from source, it still fails. I have successfully used the wrapper that Arikado keeps telling people to use, but i cannot use it, becuase i need to get the width of the text, and FreeTypeGX has a method for that.
Here is my Code:
#include stdio.h>
#include stdlib.h>
#include string.h>
#include malloc.h>
#include gccore.h>
#include string.h>
#include wiiuse/wpad.h>
#include fat.h>
#include ogc/gx.h>
#include wiisprite.h>
#include FreeTypeGX.h"
#include ftImage.h"
#include font_ttf.h"
#include hbmenuhead.h>

#include gfx/header/buttonWhite.h"
#include gfx/header/buttonRed.h"
#include gfx/header/buttonBlue.h"
#include gfx/header/buttonCyan.h"
#include gfx/header/buttonGreen.h"

// libwiisprite uses wsp as it's namespace
using namespace wsp;

enum BUTTON_COLOR{WHITE,RED,BLUE,CYAN,GREEN};

class buttonObj{
	public:
	
	void setMessage(char* m){
		strcpy(msg,m);
	}
	char* getMessage(){
		return msg;
	}

	void setLocation(int X,int Y){
		x=X;
		y=Y;
	}

	int getX(){
		return x;
	}

	int getY(){
		return y;
	}	
	
	void setDim(int w,int h){
		width = w;
		height = h;
	}

	int getWidth(){
		return width;
	}

	int getHeight(){
		return height;
	}	
	
	void setColor(BUTTON_COLOR c){
		color = c;
	}

	BUTTON_COLOR getColor(){
		return color;
	}

	void genButton(LayerManager *manager){
		switch (color)
		{
			case WHITE:
				buttonImg.LoadImage(buttonWhite);
				break;
			case RED:
				buttonImg.LoadImage(buttonRed);
				break;
			case BLUE:
				buttonImg.LoadImage(buttonBlue);
				break;
			case CYAN:
				buttonImg.LoadImage(buttonCyan);
				break;
			case GREEN:
				buttonImg.LoadImage(buttonGreen);
				break;
	
		}
		buttonSpr.SetImage(&buttonImg);
		buttonSpr.SetStretchWidth(width/80);
		buttonSpr.SetStretchHeight(height/20);
		buttonSpr.SetPosition(x,y);
	
		manager->Append(&buttonSpr);
	}
	
	void buttonDraw(LayerManager *manager){
		manager->Draw(0,0);
	}	
	
	private:
	int x,y;
	int width;
	int height;
	char* msg;
	BUTTON_COLOR color;
	Image buttonImg;
	Sprite buttonSpr;
};


int main(int argc, char **argv)
{
	// Create the game window and initalise the VIDEO subsystem
	GameWindow *gwd = new GameWindow;
	gwd->InitVideo();
	
	gwd->SetBackground((GXColor){ 255, 255, 255, 255 });
	
	LayerManager manager(1);
	
	buttonObj buttonTest;
	
	buttonTest.setLocation(5,5);
	//buttonTest.setMessage("This button worked!!!");
	buttonTest.setDim(200,50);
	buttonTest.setColor(RED);
	
	buttonTest.genButton(&manager);
	
	
	/*Image 	buttonImg;
	Sprite	buttonSpr;
	
	buttonImg.LoadImage(buttonBlue);
	buttonSpr.SetImage(&buttonImg);
	buttonSpr.SetStretchWidth(200/80);
	buttonSpr.SetStretchHeight(50/20);
	buttonSpr.SetPosition(10,10);
	
	manager.Append(&buttonSpr);*/
	
	//TEXT
	ftImage print(640,480);
	Sprite Text;
	print.setFont(font_ttf, font_ttf_size);
	print.setSize(32);
	print.setColor(Color::Color(0xff,0,0));
	Text.SetPosition(200,100);
	Text.SetImage(&print);
	// Initialise Wiimote

	FreeTypeGX	*textGX = new FreeTypeGX();

	textGX->loadFont(font_ttf,font_ttf_size,64);
	

	WPAD_Init();

	for(;;)
	{
		WPAD_ScanPads();
		if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME)
			homemenu(gwd);
		textGX->drawText(300,330,_TEXT("FreeTypeGX\0"),(GXColor){0x0, 0xff, 0x0, 0xff},0);
		buttonTest.buttonDraw(&manager);
		//print.printf("Press HOME To Quit");
		//print.flush();
		//Text.Draw();
		//print.clear();
		//print.reset();
		
		gwd->Flush();
	}
	return 0;
}
My Libs:
LIBS	:=	-lhbmenu -lftimage -lwiisprite -lmetaphrasis -lfreetype -lpngu -lpng -lz -lwiiuse -lbte -lfat -logc -lm
Re: FreeTypeGX runtime bug
January 06, 2010 02:31AM
Change:
textGX->drawText(300,330,_TEXT("FreeTypeGX\0"),(GXColor){0x0, 0xff, 0x0, 0xff},0);

to:

print.printf("FreeTypeGX");



Edited 1 time(s). Last edit at 01/06/2010 02:31AM by Arikado.
Sorry, only registered users may post in this forum.

Click here to login