Sdl_ttf Oddities


acron^

Still Fresh
Joined
Oct 23, 2006
Messages
9
Anyone ever had any issues with this?

I recently added SDL_TTF to a project I'm working on and rather oddly the text string flashes from the colour I define to black but only when it's overlayed on a sprite. When I just render it to an SDL render screen it seems fine.

Code:
SDL_Color foregroundColor = { 255, 0, 0 };
SDL_Surface* textSurface =  TTF_RenderText_Blended(m_font, m_string, foregroundColor);
SDL_Rect textLocation = { pos.x, pos.y, 0, 0 };
SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
SDL_FreeSurface(textSurface);

What's going on? :/

EDIT: TTF_RenderText_Solid() produces the same results except it's obvious now it's not flading completely to black, it's just going to approximately half it's alpha. I also tested by overlapping the text half on and half off a sprite. As predicted, the half of the text on the sprite continue flashing.
 
the code looks ok so I dont think thats the problem. do you have a background (or are blanking the screen) on each update? if not add

Code:
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255,255,255));

at the top of your display code. i think this will fix it.
 
the code looks ok so I dont think thats the problem. do you have a background (or are blanking the screen) on each update? if not add

Code:
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255,255,255));

at the top of your display code. i think this will fix it.

Ok, that may have done the job but I don't have a back buffer set up and this pretty much kills my display.

What would be the best way to get up a back buffer?
Where & when do I need to SDL_Flip() ?
 
Last edited by a moderator:
In SDL_Init, add SDL_DOUBLEBUF on the video flags i.e.

Code:
screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

then at the end of your display code add SDL_Flip();, it will then flip the buffer and display anything added to it since the last SDL_Flip
 
In SDL_Init, add SDL_DOUBLEBUF on the video flags i.e.

Code:
screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

then at the end of your display code add SDL_Flip();, it will then flip the buffer and display anything added to it since the last SDL_Flip

Would you like your kisses mailed to you? ;)
 
Last edited by a moderator:
Back
Top