iDevGames Forums
Drawing Text with OpenGL ES - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Drawing Text with OpenGL ES (/thread-2444.html)

Pages: 1 2


Drawing Text with OpenGL ES - bronxbomber92 - Aug 26, 2008 02:08 PM

How do you draw text with OpenGL ES? I need to display the count down of a timer.

Thanks


Drawing Text with OpenGL ES - AnotherJake - Aug 26, 2008 02:20 PM

Look at the sample code! It's right there, easy as could be.


Drawing Text with OpenGL ES - Najdorf - Aug 26, 2008 02:25 PM

If you want to do it with Cocoa, you have to do it in the usual way, i.e. look at a sample program that works and copy it, because there's no way you'll ever get it working otherwise.


Drawing Text with OpenGL ES - reubert - Aug 26, 2008 02:57 PM

Oh how I love that Texture2D class. It's pretty easy to port it to standard Cocoa too for a nice generic image/text class.


Drawing Text with OpenGL ES - bronxbomber92 - Aug 26, 2008 03:23 PM

Can that load custom ttf fonts?

Edit - I should say, I know it can't so what are my other alternatives?


Drawing Text with OpenGL ES - Skorche - Aug 26, 2008 04:52 PM

I still like texture fonts. They are a bit more of a hassle to create initially, but they are much more flexible style-wise. Instead of just an outline, you can edit the font as an image to texturize or stylize it.

I have a simple 100 line SDL_TTF program that will output a font image and a set of metrics for it. For iPhone ScribBall, I just ran the metrics file through a ruby script that output a VAR with geometry for all the characters packed into it.

http://code.google.com/p/aerosol/source/browse/trunk/makefont/makefont.c
http://code.google.com/p/aerosol/source/browse/trunk/Aerosol/base/font/font.rb


Drawing Text with OpenGL ES - bronxbomber92 - Aug 26, 2008 07:27 PM

Thanks! I tried running my font through makefont, but it keeps telling me the font couldn't be loaded. I even tried it with the test parameters you have commented in the file

./makefont /Library/Fonts/VeraMono.ttf 9 1 128 128

I thought maybe I had an old version of SDL_ttf, so I downloaded the latest and recompiled but I'm having the same problem.


Drawing Text with OpenGL ES - Skorche - Aug 26, 2008 11:38 PM

What's the error? I've actually made a font of vera before.


Drawing Text with OpenGL ES - bronxbomber92 - Aug 27, 2008 08:03 AM

There is no error. It just says "Could not load font."


Drawing Text with OpenGL ES - Skorche - Aug 27, 2008 11:23 AM

Code:
TTF_Font *font = TTF_OpenFont(FONT, SIZE);
        if ( font == NULL ) {
                fprintf(stderr, "Could not load font\n");

I guess you could try adding a bit more error checking there. I've yet to run into a TTF font that SDL_TTF couldn't read.


Drawing Text with OpenGL ES - bronxbomber92 - Aug 27, 2008 03:05 PM

Well, I found an old commandline version of Glyph Tool that did the trick for me. Thanks though :-)


Drawing Text with OpenGL ES - wonza - Oct 12, 2008 12:17 PM

Im trying to use the Texture2D class thats included with the crashlander app, but for some reason it just displays a large rectangle with no text:
Code:
statusTexture[0] =  [[Texture2D alloc] initWithString:@"Speed" dimensions:CGSizeMake(200, 20) alignment:UITextAlignmentLeft fontName:kFontName fontSize:11];
[statusTexture[0] drawInRect:[self bounds]];
any ideas?


Drawing Text with OpenGL ES - AnotherJake - Oct 12, 2008 07:02 PM

There are a few things that could be tripping it up. Assuming you have the texture correctly loaded and glBindTextured'ed:

glBindTexture(GL_TEXTURE_2D, [statusTexture[0] name])

Some ideas that come to mind:

Make sure you have these enabled:

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);

I don't know what blend function you'll need, probably either:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) or,
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)


Drawing Text with OpenGL ES - Frogblast - Oct 13, 2008 10:47 AM

Is the texture power-of-two size? It must be to work on the iPhone.


Drawing Text with OpenGL ES - wonza - Oct 16, 2008 03:14 AM

Just to let you know I managed to sort this.. it was an issue with scaling and clipping panes etc. Basically my text was being rendered way off screen and was far far too large Smile Thanks for your help!!