Skip to main content
gamedev.net
🔒 Locked

Question about SDL

Started by eektor May 24, 2006 at 4:10 PM 5 replies 1.3k views
Original Post
eektor
eektor
I was wondering if there was a function that I can use to get the values of the width and height of the screen. I checked the SDL documentary and could not find anything and was hoping someone here might know. Another question, I've been using TTF_FontLineSkip and it seems to cut off the letters that go below the line (g,q,p, etc.) To be more accurate should I use TTF_FontHeight and TTF_FontDescent or maybe TTF_FontAscent and TTF_FontDescent?
andrew_480
andrew_480
Quote:

I was wondering if there was a function that I can use to get the values of the width and height of the screen.


Uint16 w = screen->w;
Uint16 h = screen->h;
Mushu
Mushu
Do you want the info for the screen before or after calling SDL_SetVideoMode? If you want it after, you can use the above solution and query the video surface directly. If you want to check the display mode before setting up the main display surface, you'll first need to be using SDL 1.2.10 (the new release), then grab the SDL_VideoInfo with SDL_GetVideoInfo(), and check the values of current_w and current_h. Check the SDL documentation (1.2.10) for more details.

[Edited by - Mushu on May 24, 2006 6:30:46 PM]
eektor
eektor
It was after I set it. I was trying to avoid doing the above solution. Thanks for the help.

Any help on the TTF functions?
Mushu
Mushu
Ugh, fonts are icky. I was reading the SDL_TTF docs, and it seems like TTF_FontLineSkip is the one you want, being defined as at least as large as TTF_FontHeight, but the FreeType 2 Tutorial causes me to lose faith -
Quote:
text_height - This field is simply used to compute a default line spacing (i.e., the baseline-to-baseline distance) when writing text with this font. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance.

My suggestion would be to try a different font and see if it does the same thing. I hate fonts, I normally end up hard-coding the line spacing... Hopefully someone will post a better solution, for the both of us [sad]
DeadXorAlive
DeadXorAlive
Quote:
Original post by Mushu
Ugh, fonts are icky. I was reading the SDL_TTF docs, and it seems like TTF_FontLineSkip is the one you want, being defined as at least as large as TTF_FontHeight, but the FreeType 2 Tutorial causes me to lose faith -
Quote:
text_height - This field is simply used to compute a default line spacing (i.e., the baseline-to-baseline distance) when writing text with this font. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance.

My suggestion would be to try a different font and see if it does the same thing. I hate fonts, I normally end up hard-coding the line spacing... Hopefully someone will post a better solution, for the both of us [sad]


That's weird, I wonder what the reason would be for that. This line in the quote: "Note that it usually is larger than the sum of the ascender and descender taken as absolute values." seem to suggest that it is possible for TTF_FontLineSkip to be smaller than TTF_FontHeight, assuming TTF_FontHeight = TTF_FontAscent + TTF_FontDescent.
That would be easy enough to assert though. I didn't have any trouble with using TTF_FontHeight for lineskipping, but maybe it was because of the fonts I used.
Another option is to use a bitmap font. Angelcode has an easy to use tool to convert ttf to textures and outputs a neat xml-file. But this is maybe not what you want.
eektor
eektor
I'm going to try the TTF_FontHeight. If not I might just add a TTF_FontDescent to it, that would hopefully not add too much space between.

Thanks for the help.

Edit: I was just using the basic Arial font for now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.