Welcome! Log In Create A New Profile

Advanced

Libwiisprite: writing text

Posted by g_man 
Libwiisprite: writing text
July 20, 2009 08:41PM
How do you write text to the screen with libwiisprite, and if you can't then is there another c++ library that can draw sprites and let me write text to the screen.
Re: Libwiisprite: writing text
July 20, 2009 09:05PM
Have you taken a look at GRRLIB yet?
Re: Libwiisprite: writing text
July 20, 2009 09:09PM
you could have a look at libwiigui, it is very useful for creating guis for wii apps and it does print text to screen in a font. It should intergrate well with libwiisprite but i have only used libwiigui
Re: Libwiisprite: writing text
July 20, 2009 10:31PM
I'll try libwiigui, I havent ever used libwiisprite, I just had heard about it
Re: Libwiisprite: writing text
July 21, 2009 02:04AM
Quote
RazorChrist
Have you taken a look at GRRLIB yet?
GRRLIB is in C and not Object Oriented at all. I'm not knocking the library, but I am saying it's not an appropriate alternative for g_man.

Regarding libwiigui, I have to recommend against it. It's a very powerful library with lots of fully modifiable classes, however, I prefer libwiisprite for it's simplicity which (in my case at least) lends it's self to more control. Also, libwiisprite is geared more toward programming with it whereas libwiigui is geared towards adding a really nice menu to your program that doesn't need/use any extra programming libraries.

Anyways, back on topic....

To print text (from fonts I assume) with libwiisprite, I've had success by combining a few libraries. With the usage of FreeTypeGX by Armin Tamazarian and a wrapper my friend Ave made (which I have for download here [www.wiibrew.org] under the name libftimage ) I've successfully output text from fonts with libwiisprite with a simple initialization function call and then libftimage's text class's printf function. You can see the source code of any of my programs for an example.



Edited 1 time(s). Last edit at 07/21/2009 08:22PM by Arikado.
Re: Libwiisprite: writing text
July 21, 2009 02:15AM
I'll have a look at that. Libwiigui looks very powerful, but it was very hard for me to figure out what the program did, and how it worked by the docs, and example program. It has potenetial, but it needs more examples.
Re: Libwiisprite: writing text
July 21, 2009 04:37AM
You could look at the libwiigui tutorial. It's not completely finished, but it is already very helpful.
Re: Libwiisprite: writing text
July 21, 2009 12:31PM
Quote
g_man
I'll have a look at that. Libwiigui looks very powerful, but it was very hard for me to figure out what the program did, and how it worked by the docs, and example program. It has potenetial, but it needs more examples.

Being able to decipher how libwiigui works without external resources such as the tut for it really does help to improve your level of understanding of advanced techniques in programming, before libwiigui i had known very little about threading but now after reading libwiigui (i literally read the code) i now understand the vast potential that threading provides you with.

I understand that try to interpret how libwiigui without any hints can be difficult but once you get it you will feel overjoyed. But if you are looking for simplicity, libwiisprite is probably better since working with libwiigui requires you to remove all the elements of the demo
Re: Libwiisprite: writing text
July 21, 2009 08:19PM
I just finished taking my best shot at documenting a tutorial how to do this here on my blog.



Edited 1 time(s). Last edit at 07/21/2009 08:20PM by Arikado.
Re: Libwiisprite: writing text
July 24, 2009 07:04PM
Thanks Arikado, but now i have another problem, not realated to writing text, but to libwiisprite.
when i leave this code out, my program works fine
for(i=3;i<=dircounter;i++){
	if(opendir(applist.getDir())){ // Good practice
		dp = opendir(applist.getDir());
		while((ep = readdir(dp))){ //While there is a directory to read
			if (strcmp(strlower(ep->d_name), "icon.png")){
				strcpy(path,applist.getDir());
				strcat(path,"/icon.png");
				applist.setPngDir(path);
			}
		}
	}
}	

int x;
int y;
i = 3;
for(y=30;y<480;y+=(48+30)){
	for(x=28;x<640;x+=(128+25)){
		applist.appimg.LoadImage(applist.getPngDir());
		applist.appspr.SetImage(&applist.appimg);
		applist.appspr.SetPosition(x,y);
		manager.Append(&applist.appspr);
		i++;
	}
}
Code in my while loop
manager.Draw(0,0);
Background.SetPosition(0,0);

i = 3;
for(y=30;y<480;y+=(48+30)){
	for(x=28;x<640;x+=(128+25)){		
		applist.appspr.SetPosition(x,y);
		i++;
	}
}


here is my code that stores the appdir
DIR *dp;
struct dirent *ep;
if(opendir("SD:/apps")){ //If the apps folder exists
	dp = opendir("SD:/apps");
	while((ep = readdir(dp))){
		dircounter++;
		strcpy(path,"SD:/apps/");
		strcat(path,(ep->d_name));
		applist[dircounter].setDir(path);
	}	
	closedir(dp);
} else { //If apps doesn't exist
	opendir("SD:/");
	mkdir("apps",0777);
	exit(0);
}

and finally here is my object appobj
class appobj {
	public:
	
	//Accessor methods appname
	
	string getName() {return appname;}
	void setName(string name) { appname = name;}
	//hasdol
	bool getDol() {return hasdol;}
	void setDol(bool dol) { hasdol = dol;}
	//appdir
	string getDir() {return appdir;}
	void setDir(string dir) { appdir = dir;}
	//pngdir
	string getPngDir() {return pngdir;}
	void setPngDir(string pdir) { pngdir = pdir;}
	//coder
	string getCoder() {return coder;}
	void setCoder(string cod) { coder = cod;}
	//v_info
	string getVInfo() {return v_info;}
	void setVInfo(string vin) { v_info = vin;}
	//date
	string getDate() {return date;}
	void setDate(string dat) { date = dat;}
	//s_desc
	string getShortD() {return s_desc;}
	void setShortD(string sdes) { s_desc = sdes;}
	//appdir
	string getLongD() {return l_desc;}
	void setLongD(string ldes) { l_desc = ldes;}

	
	Image appimg;
	Sprite appspr;
	
	private:
	string appname;
	bool hasdol;
	string appdir;
	string pngdir;
	string coder;
	string v_info;
	string date;
	string s_desc;//Short description
	string l_desc;//Long description

};
I'm trying to print to the screen the icon.png of all the folders that have a boot.dol ,but all that happens is that the background color is there, and my wiimotes won't connect
Re: Libwiisprite: writing text
July 24, 2009 07:52PM
couldnt this line
for(y=30;y<480;y+=(48+30))

be this line

for(y=30;y<480;y+=78)

dont be lazy ;)

the cpu needs everything it can get, lol

try running the code bracket by bracket e.g the for loop but empty inside, then add the ifs and then the inside of the ifs etc.
Re: Libwiisprite: writing text
July 24, 2009 08:28PM
Ok, I'll try that. The reason for 48+30 is that it makes more sense. I'm adding the width of the image(48) + 30, it is easier to understand
Re: Libwiisprite: writing text
July 24, 2009 10:50PM
The compiler is smart enough to do the math for you at compile time, write what is logical and trust the compiler to have some brains.
Re: Libwiisprite: writing text
July 26, 2009 02:11PM
Quote
g_man
Ok, I'll try that. The reason for 48+30 is that it makes more sense. I'm adding the width of the image(48) + 30, it is easier to understand

the y-axis goes up and down right? then would you not use the height unless you need to use the width. Not sure if you meant height

also, in this for loop the inner loop will run 3 times for every run of the outer loop which might cause something unexpected
for(y=30;y<480;y+=(48+30)){
	for(x=28;x<640;x+=(128+25)){
		applist.appimg.LoadImage(applist.getPngDir());
		applist.appspr.SetImage(&applist.appimg);
		applist.appspr.SetPosition(x,y);
		manager.Append(&applist.appspr);
		i++;
	}
}
Re: Libwiisprite: writing text
July 26, 2009 03:10PM
Quote
henke37
The compiler is smart enough to do the math for you at compile time, write what is logical and trust the compiler to have some brains.

Second that
Re: Libwiisprite: writing text
July 26, 2009 06:48PM
Quote
SteelSLasher

also, in this for loop the inner loop will run 3 times for every run of the outer loop which might cause something unexpected
for(y=30;y<480;y+=(48+30)){
	for(x=28;x<640;x+=(128+25)){
		applist.appimg.LoadImage(applist.getPngDir());
		applist.appspr.SetImage(&applist.appimg);
		applist.appspr.SetPosition(x,y);
		manager.Append(&applist.appspr);
		i++;
	}
}
That is what i'm trying to do, I want to place 6 object in a row for each coloum, like a table in html.

EDIT: I maved this line:
//Ready Image
IMGBackground.LoadImage(background);
Background.SetImage(&IMGBackground);
Background.SetPosition(0,0);
To before here:
for(i=3;i<=dircounter;i++){
	if(opendir(applist.getDir())){ // Good practice
		dp = opendir(applist.getDir());
		while((ep = readdir(dp))){ //While there is a directory to read
			if (strcmp(strlower(ep->d_name), "icon.png")){
				strcpy(path,applist.getDir());
				strcat(path,"/icon.png");
				applist.setPngDir(path);
			}
		}
	}
}	
And my wiimotes magically sync, but the images still don't show :(



Edited 1 time(s). Last edit at 07/26/2009 07:20PM by g_man.
Sorry, only registered users may post in this forum.

Click here to login