libtcod
Loading...
Searching...
No Matches
renderer_sdl2.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef LIBTCOD_RENDERER_SDL2_H_
36#define LIBTCOD_RENDERER_SDL2_H_
37#ifndef NO_SDL
38
39#include <SDL3/SDL_properties.h>
40#include <stdbool.h>
41
42#include "config.h"
43#include "console.h"
44#include "context.h"
45#include "error.h"
46#include "mouse.h"
47#include "tileset.h"
48
49struct SDL_Window;
50struct SDL_Renderer;
51struct SDL_Texture;
60typedef struct TCOD_TilesetAtlasSDL2 {
62 struct SDL_Renderer* renderer;
64 struct SDL_Texture* texture;
77 struct SDL_Window* window; // Owning power to an SDL window.
78 struct SDL_Renderer* renderer; // Owning pointer to an SDL renderer.
79 struct TCOD_TilesetAtlasSDL2* __restrict atlas; // Owning atlas pointer.
80 struct TCOD_Console* __restrict cache_console; // Tracks the data from the last console presented.
81 struct SDL_Texture* __restrict cache_texture; // Cached console rendering output.
82 uint32_t sdl_subsystems; // Which subsystems where initialzed by this context.
83 // Mouse cursor transform values of the last viewport used.
84 TCOD_MouseTransform cursor_transform;
85};
86#ifdef __cplusplus
87extern "C" {
88#endif // __cplusplus
89
104TCOD_PUBLIC TCOD_NODISCARD struct TCOD_Context* TCOD_renderer_init_sdl2(
105 int x, int y, int width, int height, const char* title, int window_flags, int vsync, struct TCOD_Tileset* tileset);
106
114TCOD_PUBLIC TCOD_NODISCARD TCOD_Context* TCOD_renderer_init_sdl3(
115 SDL_PropertiesID window_props, SDL_PropertiesID renderer_props, struct TCOD_Tileset* tileset);
123TCOD_PUBLIC TCOD_NODISCARD struct TCOD_TilesetAtlasSDL2* TCOD_sdl2_atlas_new(
124 struct SDL_Renderer* renderer, struct TCOD_Tileset* tileset);
128TCOD_PUBLIC void TCOD_sdl2_atlas_delete(struct TCOD_TilesetAtlasSDL2* atlas);
158 const struct TCOD_TilesetAtlasSDL2* __restrict atlas,
159 const struct TCOD_Console* __restrict console,
160 struct TCOD_Console* __restrict* cache,
161 struct SDL_Texture* __restrict* target);
195 const struct TCOD_TilesetAtlasSDL2* __restrict atlas,
196 const struct TCOD_Console* __restrict console,
197 struct TCOD_Console* __restrict cache,
198 struct SDL_Texture* __restrict target);
199#ifdef __cplusplus
200} // extern "C"
201#endif // __cplusplus
202#endif // NO_SDL
203#endif // LIBTCOD_RENDERER_SDL2_H_
Libtcod config header.
Various console functions.
Libtcod display management context.
Error handling module.
TCOD_Error
An enum of libtcod error codes.
Definition error.h:48
Deprecated mouse functions.
struct TCOD_Context * TCOD_renderer_init_sdl2(int x, int y, int width, int height, const char *title, int window_flags, int vsync, struct TCOD_Tileset *tileset)
Return a libtcod rendering context using an SDL renderer.
TCOD_Error TCOD_sdl2_render_texture(const struct TCOD_TilesetAtlasSDL2 *atlas, const struct TCOD_Console *console, struct TCOD_Console *cache, struct SDL_Texture *target)
Render a console onto a managed target texture.
void TCOD_sdl2_atlas_delete(struct TCOD_TilesetAtlasSDL2 *atlas)
Delete an SDL tileset atlas.
TCOD_Error TCOD_sdl2_render_texture_setup(const struct TCOD_TilesetAtlasSDL2 *atlas, const struct TCOD_Console *console, struct TCOD_Console **cache, struct SDL_Texture **target)
Setup a cache and target texture for rendering.
struct TCOD_TilesetAtlasSDL2 * TCOD_sdl2_atlas_new(struct SDL_Renderer *renderer, struct TCOD_Tileset *tileset)
Return a new SDL atlas created from a tileset for an SDL3 renderer.
TCOD_Context * TCOD_renderer_init_sdl3(SDL_PropertiesID window_props, SDL_PropertiesID renderer_props, struct TCOD_Tileset *tileset)
Return a libtcod rendering context using SDL3.
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:125
A rendering context for libtcod.
Definition context.h:340
Info needed to convert between mouse pixel and tile coordinates.
Definition mouse_types.h:117
The renderer data for an SDL rendering context.
Definition renderer_sdl2.h:76
An SDL tileset atlas.
Definition renderer_sdl2.h:60
int texture_columns
Internal use only.
Definition renderer_sdl2.h:70
struct TCOD_Tileset * tileset
The tileset used to create this atlas.
Definition renderer_sdl2.h:66
struct SDL_Renderer * renderer
The renderer used to create this atlas.
Definition renderer_sdl2.h:62
struct TCOD_TilesetObserver * observer
Internal use only.
Definition renderer_sdl2.h:68
struct SDL_Texture * texture
The atlas texture.
Definition renderer_sdl2.h:64
A container for libtcod tileset graphics.
Definition tileset.h:62
Definition tileset.h:48
Tileset module.