Sdl_test Library (1)--sdl draw text without TTF library

Source: Internet
Author: User

There are many extensions to the SDL library, which is convenient. But each expansion library is bloated, typically dragging an additional two or three open source libraries, and, even more, the size of the extension library is much larger than the SDL library itself. But there is a self-bringing, very useful library that is easily overlooked by everyone. It is the Sdl_test library that this article is going to talk about. This library can draw strings on a window when the TTF library is not loaded.

The function is called sdltest_drawstring, and the following is an introduction to the function of E and how to use it:

Draw a string in the currently set font.

* param renderer The renderer to draw on.
* param x The x coordinate of the upper left corner of the string.
* param y The y coordinate of the upper left corner of the string.
* param s The string to draw.

* Returns returns 0 on success,-1 on failure.

In short, a renderer, coordinate, and C-style string are passed in to draw. Very simple, no more introduction, here directly to the sample source code:

1#include <SDL2/SDL.h>2#include <SDL2/SDL_test.h>3 4Sdl_renderer *windowren=NULL;5Sdl_window *windows=NULL;6 7 intMainintargcChar*argv[]) {8 Sdl_init (sdl_init_audio);9Windows=sdl_createwindow ("teststring", -, -,650,650, Sdl_window_shown);TenWindowren=sdl_createrenderer (windows,-1,0); OneSdl_setrenderdrawcolor (Windowren,255,0,0,255);//Set The color of the string ASdltest_drawstring (Windowren, -, -,"helloworld!");//Draw A string on (100,100) - sdl_renderpresent (windowren); -      while(1){ the sdl_pumpevents (); - sdl_renderpresent (windowren); -     } -     return 0; +}

It is also important to note that when connecting, the Sdl2_test library is placed behind the SDL2 library because the former relies on the function that the latter leads to.

Sdl_test Library (1)--sdl draw text without TTF library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.