Drawing Text with OpenGL ES

Member
Posts: 312
Joined: 2006.10
Post: #1
How do you draw text with OpenGL ES? I need to display the count down of a timer.

Thanks
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #2
Look at the sample code! It's right there, easy as could be.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #3
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.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #4
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.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #5
Can that load custom ttf fonts?

Edit - I should say, I know it can't so what are my other alternatives?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
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/...makefont.c
http://code.google.com/p/aerosol/source/...nt/font.rb

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #7
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
What's the error? I've actually made a font of vera before.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #9
There is no error. It just says "Could not load font."
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #10
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.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #11
Well, I found an old commandline version of Glyph Tool that did the trick for me. Thanks though :-)
Quote this message in a reply
Member
Posts: 94
Joined: 2008.08
Post: #12
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?
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #13
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)
Quote this message in a reply
Member
Posts: 87
Joined: 2006.08
Post: #14
Is the texture power-of-two size? It must be to work on the iPhone.
Quote this message in a reply
Member
Posts: 94
Joined: 2008.08
Post: #15
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!!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Cube drawing: VBOs, instanced geometry, octrees Symbol$ 5 8,630 Dec 23, 2011 01:43 PM
Last Post: Skorche
  Drawing menu versus drawing game johncmurphy 4 4,171 Jan 6, 2010 09:14 AM
Last Post: AnotherJake
  OpenGL ES : Drawing Text... savage 8 9,751 Jan 4, 2010 08:59 PM
Last Post: alerus
  openGL n00b looking for FBO drawing examples or direction auptown 5 6,958 Nov 4, 2009 02:16 AM
Last Post: Eskema
  Drawing shapes opengl es jjslay 2 3,973 Aug 14, 2009 11:07 AM
Last Post: jjslay