#### Archived

This topic is now archived and is closed to further replies.

This topic is 5813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi!!!!11 I''m experimenting with Nehe tut13 SDL-version. Here''s the code to select font:

Display *dpy;          /* Our current X display */
XFontStruct *fontInfo; /* Our font info */

/* Sotrage for 96 characters */
base = glGenLists( 96 );

/* Get our current display long enough to get the fonts */
dpy = XOpenDisplay( NULL );

/* Get the font information */

/* If the above font didn''t exist try one that should */
if ( fontInfo == NULL )
{
fontInfo = XLoadQueryFont( dpy, "fixed" );
/* If that font doesn''t exist, something is wrong */
if ( fontInfo == NULL )
{
fprintf( stderr, "no X font available?\n" );
Quit( 1 );
}
}

/* generate the list */
glXUseXFont( fontInfo->fid, 32, 96, base );

/* Recover some memory */
XFreeFont( dpy, fontInfo );

/* close the display now that we''re done with it */
XCloseDisplay( dpy );


I think that this "-adobe-helvetica-medium-r-normal--18-*-*-*-p-*-iso8859-1" is font name. Duh! How do I actually select Font of certain size? I noticed that changing the value 18 changes font size. Is it correct to select font of certain size this way: sprintf(fontname,"-adobe-helvetica-medium-r-normal--%d-*-*-*-p-*-iso8859-1",size); Is there simplier method to select any common font of certain size?

##### Share on other sites
Firstly, this isn''t really a smart approach.
You are mixing X calls with SDL, SDL wraps on
top of X and then you are putting X on top
of an X wrapper. This will make it non-portable
and defeat the primary purpose of SDL.

Fonts under X are not gauranteed under Windows,
what I recommend is that you render your own
fonts as OpenGL bitmaps and use OpenGL calls

##### Share on other sites
quote:
Original post by LearFox
Fonts under X are not gauranteed under Windows,
what I recommend is that you render your own
fonts as OpenGL bitmaps and use OpenGL calls

This is actually what I''m doing! I just don''t read font from bitmap but get it instead from X Font.
It generates displaylist for each char (that uses glBitmap innerly).
After this procedure I never need X anymore.
And this is directly from NeHe/SDL tutorial.

But I understand your worry, it''s not good to mix SDL and X.
The above is not good because it''s not portable.

Ok, I also thought to make own fonts in gimp and then save them as image (or export default font as .cpp -code to make sure always is default font available).

Any ideas how to make variable length fonts from bitmap?
Maybe just scanning each char''s bitmap?

Thanks. I''ll take now another approach....

##### Share on other sites
A while ago, I wrote a short program to load a font in X and then convert it into a .h header file that defines a gl bitmap. Where the width always fits one character (usually 8 to 16 points wide) and the height contains all the alphabets (usually 8 to 16 points per character height). This way I could use glBitmap to draw the #included header file. To index the character I wanted to draw from the bitmap was easy, I just offsetted the starting height within the bitmap by the character''s ASCII value * the character height, the bitmap always contained 256 characters. Hope this helps you off to a good start, because it worked out quite well for me. The only draw back is that the fonts need to be fixed width and height, but this worked out quite well since most fonts in games are fixed size.

##### Share on other sites
Well, I discovered FreeType2 and it''s very good and easy with wariable length chars

##### Share on other sites
M''kay, but be careful with that, if you are using
FreeType2 to just render the fonts into gl bitmaps and
then include them as compile time header files that would
work. However FreeType2 is extremely unstable as of this
writing and often is not compilable on most systems
(including most UNIXes).

##### Share on other sites
You mean I''d better to do a little conversion program to save fonts in kinda bitmap (with extra data: letter width,height,pos,advance...) and use it?

Why not, but why?
It''s not big thing to do.

But why wouldn''t freetype work if I share the same font with my app always?