Drawing Text with OpenGL ES
How do you draw text with OpenGL ES? I need to display the count down of a timer.
Thanks
Thanks
Look at the sample code! It's right there, easy as could be.
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
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
Can that load custom ttf fonts?
Edit - I should say, I know it can't so what are my other alternatives?
Edit - I should say, I know it can't so what are my other alternatives?
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
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.
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.
./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.
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.
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.
Well, I found an old commandline version of Glyph Tool that did the trick for me. Thanks though :-)
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:
any ideas?
Code:
statusTexture[0] = [[Texture2D alloc] initWithString:@"Speed" dimensions:CGSizeMake(200, 20) alignment:UITextAlignmentLeft fontName:kFontName fontSize:11];
[statusTexture[0] drawInRect:[self bounds]];
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)
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)
Is the texture power-of-two size? It must be to work on the iPhone.
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
Thanks for your help!!
Thanks for your help!!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL Cube drawing: VBOs, instanced geometry, octrees | Symbol$ | 5 | 6,194 |
Dec 23, 2011 01:43 PM Last Post: Skorche |
|
| Drawing menu versus drawing game | johncmurphy | 4 | 3,705 |
Jan 6, 2010 09:14 AM Last Post: AnotherJake |
|
| OpenGL ES : Drawing Text... | savage | 8 | 8,175 |
Jan 4, 2010 08:59 PM Last Post: alerus |
|
| openGL n00b looking for FBO drawing examples or direction | auptown | 5 | 5,719 |
Nov 4, 2009 02:16 AM Last Post: Eskema |
|
| Drawing shapes opengl es | jjslay | 2 | 3,409 |
Aug 14, 2009 11:07 AM Last Post: jjslay |
|

