Jump to content
  • Advertisement
Sign in to follow this  
deathwearer

Trouble to show text with SDL_ttf(solved)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I'v followed this tutorial here : http://www.aaroncox.net/tutorials/2dtutorials/sdltext.html And i tried to take his code and insert it in my Game ( using class ) to understand how to use it proprely. Everything compile and seems alright but the fact that the text isn't being show in the game. I don't know what's wrong since I'v followed everything on tutorial and i did read it many time :( I first off initialize ttf with TTF_Init(); in the main. After i declare everything in the header of my class like that.
	SDL_Surface *screen;
	TTF_Font* font;
	SDL_Color foregroundColor;
	SDL_Color backgroundColor;
	SDL_Surface* textSurface;
	SDL_Rect textLocation;


then in the constructor of one of my class, i define everything like that
	font = TTF_OpenFont("ARIAL.TTF", 12);
	(foregroundColor.b, 0);
	(foregroundColor.g, 0);
	(foregroundColor.r, 0);

	(backgroundColor.r, 0);
	(backgroundColor.g, 0);
	(backgroundColor.b, 0);

	textSurface = TTF_RenderText_Shaded(font, "This is my text.", 
      foregroundColor, backgroundColor);
	
	(textLocation.x,100);
	(textLocation.y,100);
	(textLocation.h,0);
	(textLocation.w,0);
	
	const char* WINDOW_TITLE = "SDL Start";
	SDL_WM_SetCaption( WINDOW_TITLE, 0 );


Then later in my main i call Draw_Scenes that call my function inside my class. And here is the function inside my class :
void CInterface::Draw_TTF()
{
      SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 15, 15, 15));

      SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
}


In the tutorial the guy call SDL_Flip(); But when i put it in my function ( Draw_TTF() the screen is buzzing, show one frame black one frame the game etc.. Was that important to call that? and if yes and it is the Problem, how do i fix the black/game screen bugging? [Edited by - deathwearer on August 20, 2005 7:49:10 PM]

Share this post


Link to post
Share on other sites
Advertisement
Um. What do you think these lines are doing?

(foregroundColor.b, 0);
(foregroundColor.g, 0);
(foregroundColor.r, 0);

I think you're trying to assign to the member variables in which case it would look like:

foregroundColor.b = 0;
foregroundColor.g = 0;
foregroundColor.r = 0;


And if you have the foreground color and the background color both be black, then it doesn't seem like you'd be able to see anything, black on black being not very visible.

Share this post


Link to post
Share on other sites
Ah jeez yes, was doing it like i had strcpy with string.h

And yes i know that about black on black but it would at least show a black square on my blue BG :)

I'v made the change but that still doens't show anything :(

Share this post


Link to post
Share on other sites
1) Are you sure you have a decent color scheme? Because it looks to me like you clear the screen to very dark grey (15,15,15) not blue...

2) Are you sure you have "arial.ttf" in the same directory as your project?

3) Do you ever call SDL_Flip( screen )?

If you have done all these, you may need to post more code.

Hope this helps

Share this post


Link to post
Share on other sites
1) i clear the whole screen? not sure i understand

I have a background image and want to print some text on it.

2) Yes it is.

3) No this is what i said at the very end of my post i don't.

When i call it, when i execute the game it's bugging a bit, one frame will be the game, the other one will be a black screen.

Share this post


Link to post
Share on other sites
Okay, Now I'v solve the problem of the screen bugging myself.

Now the screen is all red ( changed color to make sure I'ts working ).

When i call

SDL_BlitSurface(textSurface, NULL, screen, &textLocation);

textSurface is where i will draw, and on the tutorial it say if it's null it will color the whole screen. Now simple question how do i set textSurface to now draw everywhere.

Edit : It is now working, i love the docs :)

[Edited by - deathwearer on August 20, 2005 7:23:51 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!