This is my first post here as I’m just beginning to learn SDL. I’ve got SDL and
SDL_ttf installed, and (thanks to some great tutorials) I’m able to set up SDL
Video and SDL_ttf as follows:
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
printf("Unable to init SDL: %s\n", SDL_GetError());
screen = SDL_SetVideoMode(1024, 768, 16, SDL_SWSURFACE);
if ( screen == NULL )
printf("Unable to set 1024x768 video: %s\n", SDL_GetError());
if(TTF_Init()==-1)
printf("TTF_Init: %s\n", TTF_GetError());
font=TTF_OpenFont("VeraSe.ttf", 16);
if(!font)
printf("TTF_OpenFont: %s\n", TTF_GetError());
All this (appears to) work ok, everything is initialised and a black window of
1024x768 appears. However, when it comes to writing text onto the screen, I use
this:
if(!(text_surface=TTF_RenderText_Solid(font,"Hello World!",clrWhite)))
{
//handle error here, perhaps print TTF_GetError at least
printf("SDL_ttf Error, %s\n", TTF_GetError());
}
clrWhite is defined as ‘SDL_Color clrWhite = {255,255,255,0};’
Is there something else I need to be doing before the text is displayed on
screen? At the moment the screen stays resolutely blank. Hope someone can help.
Is there something else I need to be doing before the text is
displayed on screen? At the moment the screen stays resolutely
blank. Hope someone can help.
Are you doing SDL_UpdateRect(), SDL_UpdateRects() or SDL_Flip()
somewhere in your loop?
From the code you posted, you haven’t yet blitted your newly-text-filled
"text_surface" to the screen yet. After blitting it to the screen, you’ll
need to call either SDL_Flip or SDL_UpdateRect(s). Hope that helps.
-Dave> ----- Original Message -----
From: wilkinson.m@btopenworld.com (Mark)
To:
Sent: Monday, January 03, 2005 9:12 AM
Subject: [SDL] SDL_ttf - a newbies question
Hi,
This is my first post here as I’m just beginning to learn SDL. I’ve got
SDL and
SDL_ttf installed, and (thanks to some great tutorials) I’m able to set up
SDL
Video and SDL_ttf as follows:
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
printf(“Unable to init SDL: %s\n”, SDL_GetError());
All this (appears to) work ok, everything is initialised and a black
window of
1024x768 appears. However, when it comes to writing text onto the screen,
I use
this:
//handle error here, perhaps print TTF_GetError at least
printf(“SDL_ttf Error, %s\n”, TTF_GetError());
}
clrWhite is defined as ‘SDL_Color clrWhite = {255,255,255,0};’
Is there something else I need to be doing before the text is displayed on
screen? At the moment the screen stays resolutely blank. Hope someone
can help.
From the code you posted, you haven’t yet blitted your newly-text-filled
"text_surface" to the screen yet. After blitting it to the screen, you’ll
need to call either SDL_Flip or SDL_UpdateRect(s). Hope that helps.
-Dave
Dave,
As you’ll have seen from my response to Gabriel, that was the precise problem.
The only good thing about embarrassing yourself on your first post, is that it
gets it out the way early.
As you’ll have seen from my response to Gabriel, that was the precise problem.
The only good thing about embarrassing yourself on your first post, is that it
gets it out the way early.
Hey, no need to feel embarrased! We are all newbies in some thing or
another