Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Help: Bitmap Fonts - TextExtent, measurment etc


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 SparkyNZ   Members   -  Reputation: 121

Like
0Likes
Like

Posted 16 January 2011 - 03:25 PM

Hi. How do you measure the size of a string (in pixels) when rendering bitmaps fonts to the screen in OpenGL? I'm doing what is done in Lesson 13 (ie. wglUseFontBitmaps() etc).

I would like to use bitmap fonts because I'm doing some OpenGL coding that is going to be 2D. At the same time, I would like to minimise my usage of Windows GDI functions if possible. If all the font characters are displayed using GL "lists" (sorry, I'm new to OpenGL), then is there a way to determine the width and height of a GL list before it is actually rendered to the screen? I'm thinking if I wanted to print the string "Hello", I could calculate the length in pixels of "Hello" by getting the total widths of H, e, l and o.

I noticed the tutorial on outline fonts indicates how to calculate string measurement but not the tutorial for bitmap fonts.

Sponsor:

#2 lc_overlord   Members   -  Reputation: 436

Like
0Likes
Like

Posted 17 January 2011 - 03:53 AM

well it's not an easy thing, first you need all the info about character widths and the offsets between them, then you need to know the current window projection and so on.
The window projection can be set to the actual pixels, so that solves that bit.
Secondly you need to know the character width, but if your doing bitmap fonts it should be texturesize/16,
then all you need to know is the spaces between them (there are two per character before and after, and they are usually negative) and that's something wglUseFontBitmaps() doesn't deliver, so you have to make your own, but it's not that hard

Then all you have to do is go ((texturesize/16)-(charofsset[text[0]]*2)) + ((texturesize/16)-(charofsset[text[1]]*2)) + ........ and so on

Hope this clear things up a bit.

#3 SparkyNZ   Members   -  Reputation: 121

Like
0Likes
Like

Posted 17 January 2011 - 11:43 AM

Thanks for that. Is another option to use outline fonts in 2D projection? I tried that yesterday but all I could see where dots - as if I were looking at my words edge on (like looking across a piece of paper rather than perpendicular to it (and that was using the same Lesson 13 projection that worked with bitmap fonts).

Do outline fonts only work with 3D projections?

What I really want to do is use OpenGL for some 2D graphics (for a bit of "crossplatform" development) but I'm not sure if 3D mode would be more processor intensive than 2D mode or not. I suppose for what I need it for it won't matter too much but...

#4 lc_overlord   Members   -  Reputation: 436

Like
0Likes
Like

Posted 17 January 2011 - 12:31 PM

yea outline fonts should work in 2d and 3d projections but it can take a bit of work sometimes to get the everything just right, though i prefer the bitmap fonts since then you can make your own bitmaps and get better looking fonts.

And i think you should know that there is no such thing as 3D when it comes to openGL, it's all just 2D but using clever tricks like 3d matrix projection, hidden surface removal and a z buffer to make it look like 3D.
So 3D and 2D should be equally fast. if you render the same thing.

#5 SparkyNZ   Members   -  Reputation: 121

Like
0Likes
Like

Posted 17 January 2011 - 01:47 PM

yea outline fonts should work in 2d and 3d projections but it can take a bit of work sometimes to get the everything just right, though i prefer the bitmap fonts since then you can make your own bitmaps and get better looking fonts.


Yeah, I keep wondering why I am bothering with Windows fonts at the moment given that I will be loading my own fonts anyway. I guess I am just wanting to know more about this and that. Ultimately I'm writing an iPhone app with OpenGL ES so I will indeed be extracting my own font glyphs from a file.. and they'll all be the same width too. :-) I guess its just good to experiment with things on Windows using the Windows fonts to fill in gaps for now.. Maybe I should just do my own fonts right away. :-)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS