Project: Low Poly 3D Text / OpenGL

Arwin

Now Officially a Top 10 Poster
Moderator
Legend
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 which I want to be able to use on my PSP using PSPGL.

iloveopengl.gif


I'm baking my own font here, using the minimum amount of triangles possible (max five so far). Looks a bit Asian as a result. ;)

Although I don't fully understand how everything works just yet (in terms of setting up the renderer and such), I got the basics working thanks to Nehe's Lesson 6, and what I set out to do is already up and running.

Firstly, 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 (right now I only have capital letters, no numbers yet).

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:
	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:
int i=0;
	while(myText[i] != '\0')
	{

		myGLChar.unicodechar = myText[i];
		myGLChar.x = i*(0.6f);
		i++;
		DrawGLChar(&myGLChar);
	}

Here's an .elf sample (load with FileAssistant++). 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 (they don't just yet on the PSP version of GL) 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.

Especially in this forum, I would really appreciate hearing on some nice effects ideas. Initially I'm looking at really basic stuff, as I'm still learning (this is my second C project after p-sprint, also on the PSP). At the very least I'd like to get this as a basis for some text-based games.

Also, I would like to learn more about best practices, as I'm sure many people here have tips on that.
 
Last edited by a moderator:
epicstruggle said:
Sounds interesting. How easy is it to go from OGL to PSPGL?

epic

Well, understand that PSPGL is basically the name of the library that brings OpenGL to the PSP. So on principle, real easy as there is no difference. :)

Not everything is completely up to spec though. For more details and a great start, check out this thread:

http://forums.ps2dev.org/viewtopic.php?t=5835
 
Arwin, have you considered doing a full-fledged font lofter? i.e. a 2d typeface rasterizer with the ability to extrude, or loft, the typefaces in depth, following certain parameters/paths?
 
darkblu said:
Arwin, have you considered doing a full-fledged font lofter? i.e. a 2d typeface rasterizer with the ability to extrude, or loft, the typefaces in depth, following certain parameters/paths?

That exists already though, doesn't it? At least on the PC, it is part of OpenGL even? Nehe's example has something like that. It may still be interesting to do though eventually, perhaps thinking up clever algorithms to allow you to limit the amount of polygons used.

I wanted to try something different now because of two reasons: I wanted to know how many characters I could show at any one time if I made a minimum poly count, and I wanted to do something with a limited scope to get something going on the PSP and become familiar with 3d stuff.

Right now for instance, in the demo I linked to above, I put up the sentence you see in the image 80 times across the z axis and have that rotate (it's really simple but I find it strangely mesmerizing to watch :D). That currently is about the limit that the PSP can push using OpenGL (which by the way is still 2500 polys per frame, though the framerate isn't all that - you should be able to push millions per second though). However, I know that in terms of what the PSP can actually do, that is still very slow (although it would kill my laptop to even try). Part of it must be because PSPGL is a lot slower than using the native Sony features directly, and part of it may very well be very bad coding.

So in and with this project I want to learn a few things. First of all, I want to become familiar with OpenGL and have a basis with which I can test different animation techniques, morphing, and eventually lighting and some texturing.

Second, I want to try to do something useful with the limits of the stuff I am learning. For instance, I would like to make one or two games involving text and moving/morphing characters just using the very basic OpenGL of drawing Polys, transposing them, and maybe moving the camera around.

And finally, I want to learn to do it right and do it fast. See what kind of optimisations I can do etc.

Those are my initial goals. Having something that is based on the very basics of OpenGL will allow me to use it as something I can keep returning to for different aspects. For instance, I could try to do self shadowing letters, apply bump-maps to them, and who knows what else. (probably I will first limit myself to what the PSP can do at least initially, and hopefully by the time the PS3 comes out it will indeed come with Linux and OpenGL ES so I can build on that from there)

And because it involves text, I could use it (and allow others to use it) for text related stuff also. There is tonnes of stuff you can do with text, but they could be a lot more fun / attractive / original if you put them into 3D.
 
Last edited by a moderator:
When I first saw the title, I thought someone was making an OpenGL rasterizer using ASCII as the framebuffer, which would have been a really cool ASCII Art generator! Kinda like ASCII Doom and HasciiCam.
 
DemoCoder said:
When I first saw the title, I thought someone was making an OpenGL rasterizer using ASCII as the framebuffer, which would have been a really cool ASCII Art generator! Kinda like ASCII Doom and HasciiCam.

Ha ha, that's a funny idea :D Well I suppose you could use it for that anyway :D - with some optimisations and adding a few ascii characters obviously.

Right now I just wanted to toy around with fully scaleable yet fast text, so i can put a lot of characters on screen at once and scale each of them quickly and individually in different ways. If you can try the 3d demo you'll see it actually does work fairly well already.

I just don't have enough time. Or maybe I'm not efficient enough. I think I have to go to bed. :) Work is taking away a lot of my coding energy, since that's also my work, coding.
 
I've been working a little more on this project now. I have added some code to allow variable width, to begin with. The character object now has a drawnWidth property which is filled by the drawChar function with the actual width of the character that was drawn.

One of the reaons why this was necessary is because not only did I add quotes and exclamation marks, but also numbers. For this, I also realised that I have to line up the characters left on the x-axis, rather than center them as I've been doing- you only know the space for the current character after you've drawn it, so it needs to be aligned left.

All this is pretty obvious stuff, but it's still fun to reinvent the wheel sometimes. ;)

I've played around a little with animating some text again to test all this out, which was fun. Maybe I'll release another little demo soon. Maybe also a PC version, as on this site there are certainly more of those around. ;)

Again, the whole point of this exercise is to create font(s) which combine good looks with minimal poly-counts.

One thing I'd like to work on is a technique that would keep font readability a little better at lower resolutions. If there are any ideas on this, or on stuff like anti-aliasing, I'd be very happy to hear.

I'll release source code soon, so you can all laugh at my pathetically inefficient beginner code. :)
 
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:

gltextlight.gif
 
Last edited by a moderator:
Back
Top