render: Add SDL_RenderDebugText().

Fixes #11201.
This commit is contained in:
Ryan C. Gordon
2024-10-13 21:48:11 -04:00
parent 44bc19b592
commit c20918b0fb
11 changed files with 2594 additions and 3354 deletions

View File

@@ -2464,6 +2464,57 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync);
/**
* The size, in pixels, of a single SDL_RenderDebugText() character.
*
* The font is monospaced and square, so this applies to all characters.
*
* \since This macro is available since SDL 3.1.5.
*
* \sa SDL_RenderDebugText
*/
#define SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE 8
/**
* Draw debug text to an SDL_Renderer.
*
* This function will render a string of text to an SDL_Renderer. Note that
* this is a convenience function for debugging, with severe limitations, and
* not intended to be used for production apps and games.
*
* Among these limitations:
*
* - It accepts UTF-8 strings, but will only renders ASCII characters.
* - It has a single, tiny size (8x8 pixels). One can use logical
* presentation or scaling to adjust it, but it will be blurry.
* - It uses a simple, hardcoded bitmap font. It does not allow different
* font selections and it does not support truetype, for proper scaling.
* - It does no word-wrapping and does not treat newline characters as a line
* break. If the text goes out of the window, it's gone.
*
* For serious text rendering, there are several good options, such as
* SDL_ttf, stb_truetype, or other external libraries.
*
* On first use, this will create an internal texture for rendering glyphs.
* This texture will live until the renderer is destroyed.
*
* The text is drawn in the color specified by SDL_SetRenderDrawColor().
*
* \param renderer the renderer which should draw a line of text.
* \param x the x coordinate where the top-left corner of the text will draw.
* \param y the y coordinate where the top-left corner of the text will draw.
* \param str the string to render.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety You may only call this function from the main thread.
*
* \since This function is available since SDL 3.1.5.
*
* \sa SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderDebugText(SDL_Renderer *renderer, float x, float y, const char *str);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}