Project: 3D Text / PSPGL

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Project: 3D Text / PSPGL

Post by Arwin »

Hi guys,

Because I want to learn how to do 3D programming, I thought I would start with something that could be useful for other stuff later on, and is fun to do - build a low-poly text renderer.

Right now, I've just designed my own font that consists of no more than five triangles for each (capital) letter - using the form of the triangle to make an Asian style font that looks kinda fun.

Each of these can be scaled both width and height, and the width of the end of the triangle can also be specified to adjust the weight of the font. Currently, it works like this:

Code: Select all

	gltext_Param myGLChar;

	myGLChar.x = 0.0f;
	myGLChar.y = 0.0f;
	myGLChar.z = 0.0f;
	myGLChar.height = 1.0f;
	myGLChar.width = 0.5f;
	myGLChar.Red = 0.0f;
	myGLChar.Green = 0.0f;
	myGLChar.Blue = 0.0f;
	myGLChar.endwidth = 0.1f;
	myGLChar.unicodechar = 65;

                DrawGLChar(&myGLChar);
And you can write text for it using this:

Code: Select all

int i=0;
	while(myText[i] != '\0')
	{

		myGLChar.unicodechar = myText[i];
		myGLChar.x = i*(0.6f*zoom);
		i++;
		DrawGLChar(&myGLChar);
	}
Here's an .elf sample. I'll post source as soon as I made it a proper library and add 0-9 and dots 'n stuff.

Once Display Lists are working (and I've learnt how to use them), I could imagine making a function that returns the display list merge data rather than draw the stuff right away as it does now.

If anyone is interested in having this do certain things so that they could make use of it somehow, or has other kinds of input, let me know.
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

By the way, I would like to make this into something using the sceGu directly. If someone has an example of how to draw just one triangle, no textures, that would be great.

I edited the textured cube example, and just by removing everyting that refers to texture, I either get a completely garbled cube, or a fog that blocks everything, and really don't understand how. : blush :
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

sorry to refer to my own work.
you can model your text in MAYA and export it (with my homebrewn export script)

then translate it to my psp format (.3db)

then load it to psp using my object loader (pspLoader)

betatesting is currently running! (although i only have ONE betatester)

IFF you want you can be my second beta tester!
what does this mean?
you get the full source code before official release (which should be soon...)
you need to test my stuff and report me bugs/problems
you need maya to export models!

greets
lumo

PS: defining models in source code might work too, but... it would kill me ;)
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

I am interested, I will send you my email! I will also try to post my initial source tomorrow ...
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

I have played with this some more, and have added numbers, a few marks.

I have also added support for variable width type setting. For this, I added an extra property that reports the actual width that the character has been drawn at.

I also came across this: http://homepages.paradise.net.nz/henryj/code/#FTGL

This looks like an interesting project to try to port. Don't know if there are any takers ... if not, I may have a go at it after I've finished playing around with the current project.

The upside of my project is that it uses a minimum of polys and it will be the only include necessary and no extra libraries, font files, and so on. That's what I am aiming for - if only, it will be something that will ease debugging and such. But it's also fun to play around with some animation and effects stuff.

I'll try to post the first source code soon so others can play around with it.
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Ok, here's the rough code, a sample PSPGL targeting main.c (heavily borrowing from the ported NeHe sample lesson 6, I didn't even remove the texture yet) that implements gltextlight through header file, all included.

Here's the link: http://www.niwra.nl/psp/gltextlight/gltextlight.rar

And here's a little screenshot, to give an impression:

Image
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

really cool buddy
10011011 00101010 11010111 10001001 10111010
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

dot_blank wrote:really cool buddy
Thanks. :)

Now hopefully we can make some fun things with this.

Also, optimisation ideas are very welcome. Though I suspect to have optimisations under PSPGL an important factor is probably going to be to have display lists of some sort.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Nice Idea there with the poly-glyphs :)

Though I'd probably use a structure array to hold the vertice data for each character and in the drawing function just would render it from there. That would make it much more cleaner, rather than having 100's of switch cases. Sizing could be done by a scale matrix call.
But that's just how I would aproach something like that.

For optimisations I would suggest you try with direct sceGu function calls first, though I'm not sure about how much that would gain (haven't had a look at how efficiently pspgl wraps those calls). The most effective speed improvement would probably be a glyph cache though. Render your string into an offscreen texture and then just do a single texture quad on the screen (This way, you could also get some antialiasing effect done, by doing a downsample of the offscreen texture before rendering.

Well, keep up :)
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Raphael wrote:Nice Idea there with the poly-glyphs :)

Though I'd probably use a structure array to hold the vertice data for each character and in the drawing function just would render it from there. That would make it much more cleaner, rather than having 100's of switch cases. Sizing could be done by a scale matrix call.
But that's just how I would aproach something like that.
Yeah, that sounds much better. So far it has been easy developing the glyphs like this, but it shouldn't be much harder to do it from an array. I'm just not yet well versed enough in this language to be comfortable doing so yet. For example, when I thought about it initially, I couldn't immediately figure out how to deal with different amounts of triangles for the glyphs. I suppose I need an array of character structures, which in turn has a property with an index value of where in the coordinates array this character starts, and then have something in that array which marks the end of this glyph's coordinate?
For optimisations I would suggest you try with direct sceGu function calls first, though I'm not sure about how much that would gain (haven't had a look at how efficiently pspgl wraps those calls).
I will probably stick with PSPGL as long as I can, because it's a great luxury to be able to so easily develop on PC and then port that code.
The most effective speed improvement would probably be a glyph cache though. Render your string into an offscreen texture and then just do a single texture quad on the screen (This way, you could also get some antialiasing effect done, by doing a downsample of the offscreen texture before rendering.
Yes, but I'm taking that as something on a different abstraction level. I would write a different library which works like that ... but for now I am more interested in creating stuff that is (part of) a 3D environment.
Well, keep up :)
Thanks! I just created a kind of text vortex, which is a lot of fun. That's the kind of thing I was looking for doing. I originally wanted to create some word games which use 3D text.

I discovered a little bug in the drawing of the U character, btw, I'll have a fixed upload soon in case anyone noticed.
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Small fixed version updated, now with a spiral like textflow ... I also draw the letters double real close with the second one a light color as a test for seeing if this can achieve rudimentary AA. It looks like it might (at least, from the right angle of course). Will have to test with letters viewed from the front to see how that works out.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Arwin wrote: Yeah, that sounds much better. So far it has been easy developing the glyphs like this, but it shouldn't be much harder to do it from an array. I'm just not yet well versed enough in this language to be comfortable doing so yet. For example, when I thought about it initially, I couldn't immediately figure out how to deal with different amounts of triangles for the glyphs. I suppose I need an array of character structures, which in turn has a property with an index value of where in the coordinates array this character starts, and then have something in that array which marks the end of this glyph's coordinate?
Well, in your case that really isn't that trivial to achieve, since you have an array of variable length arrays. Easiest way would be to declare a structure with a fixed number of triangles and in the
definition, just fill unneeded tris with 0's.

abstracted simplified approach:

Code: Select all

struct nlist {
int n_items;
int item[4];
};

struct nlist mylist[] = { { 3, { 1, 2, 3, 0 } }, // list entry 1 consisting of 3 items
{ 2, { 2, 6, 0, 0 } }, // list entry 2 consisting of 2 items
... };
In your case, nlist would be the structure for one glyph, n_items would be the number of triangles and each item[] would be a triangle, made up of three vertices (or just vertice indices) instead of a single int.
You could possibly also skip the n_items, if you define one case of a triangle structure as the 'NULL' triangle (in the above case it could be simply 0, for your case probably a triangle made of three 0-indices) and decide by that when there aren't any more triangles.

Code: Select all

#define MAX_TRIS 4
struct tri {
int verts[3];
};

struct glyph {
struct tri tris[MAX_TRIS];
};

struct glyph glyphs[] = { {{ {1,2,3}, {3,4,5},{6,7,8},{{0}} }}, // glyph 1, 3 tris
{{ {3,5,8}, {9,12,11}, {{0}}, {{0}} }}, // glyph 2, 2 tris
 { {0} } // null-glyph };
Would be better readable if I did proper indenting with tabs.
Looking at all that, maybe your approach wasn't that bad at all ;P
Yes, but I'm taking that as something on a different abstraction level. I would write a different library which works like that ... but for now I am more interested in creating stuff that is (part of) a 3D environment.
That's up to your decision how far your abstraction level goes :) But since you only provide the raw code for drawing single chars it's pretty low-level, so its ok to stay away from complicating caching algorithms :)
[/u]
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

i guess for the moment I will stay with the current setup then. ;)

But if I would do it, I would create one index array linked to characters, i.e.:

e[charcode]=index_to_location_in_vertices_array

drawFromList(list_index) as drawnWidth

It could quickly get complicated though. I would have to define / figure out what part of the vertices array is what - i.e., which part should be scaled in what way for width, endwidth, height, and so on.

I'll keep muddling like I have now for a slight bit more I think. ;)

I notice that it is much, much harder to create something that is readable when drawn small. I think for now that will actually be too hard, though I can improve readability here and there by making lines rectangular rather than triangular. I think I will experiment with that a bit in a second draw function, but perhaps I should try to make do with what i have now and play with some larger letters instead. ;)
Post Reply