In the previous chapter I briefly introduced our first SDL applet to implement a small palette function, focusing on how to draw your own patterns on sdl_surface,
In this chapter I focus on the sdl_surface of the text on the display of the analysis. Let our screen also have its own text tag ... Of course.. You can also make your own notepad ....
Of course.. Want to write, one of the necessary is to have a font, you can download nfs-share.tar.gz the online package. Then put the Simfang.ttf in the working directory, the roughly used function has
Ttf_openfont (const char *file, int ptsize);
To set the font, here is the Simfang.ttf in the nfs-share.tar.gz below, and the second argument is the font size you want to set,
Ttf_renderutf8_solid (Ttf_font *font,
const Char *text, Sdl_color FG);
The first parameter is the Ttf_font object returned by the Ttf_openfont function, the second parameter is the content of the text file to be displayed, and the third argument is a
The structure object of the font color.
Sdl_upperblit (Sdl_surface *src, Sdl_rect *srcrect,
Sdl_surface *dst, Sdl_rect *dstrect);
The macro definition of this function is sdl_blitsurface, so the general use of the Sdl_blitsurface function, the following is a simple example to illustrate the problem ....
int main (int argc,char *argv[])
{
if (Sdl_init (Sdl_init_video) < 0 | | Ttf_init () < 0)
{
printf ("Init error\n");
return-1;
}
Sdl_surface *screen = Sdl_setvideomode (640,480,32,sdl_swsurface);
if (!screen)
{
printf ("Init video mode error\n");
return-1;
}
Ttf_font * Font = Ttf_openfont ("Simfang.ttf");
Sdl_color Color = {175,100,220};
Sdl_surface *text = ttf_renderutf8_solid (font, "Hello, hi", color);
Sdl_blitsurface (text,0,screen,0);
Sdl_updaterects (screen,1,&screen->clip_rect);
Ttf_closefont (font);
Sdl_delay ();
Ttf_quit ();
Sdl_quit ();
return 0;
}
Don't forget to release it after everything is done .... To develop a good habit is the beginning of success.
The next chapter I will be a picture of the loading of an analysis ....
This article is from the "Late Evening" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/833296