mirror of
https://github.com/nicbarker/clay.git
synced 2025-09-18 12:36:17 +00:00
[Examples/SDL3] Load sample image as a texture
This commit is contained in:
parent
47eeb78acd
commit
518cbdf519
|
@ -23,7 +23,7 @@ typedef struct app_state {
|
||||||
ClayVideoDemo_Data demoData;
|
ClayVideoDemo_Data demoData;
|
||||||
} AppState;
|
} AppState;
|
||||||
|
|
||||||
SDL_Surface *sample_image;
|
SDL_Texture *sample_image;
|
||||||
|
|
||||||
static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData)
|
static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,11 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||||
|
|
||||||
state->rendererData.fonts[FONT_ID] = font;
|
state->rendererData.fonts[FONT_ID] = font;
|
||||||
|
|
||||||
sample_image = IMG_Load("resources/sample.png");
|
sample_image = IMG_LoadTexture(state->rendererData.renderer, "resources/sample.png");
|
||||||
|
if (!sample_image) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to load image: %s", SDL_GetError());
|
||||||
|
return SDL_APP_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize Clay */
|
/* Initialize Clay */
|
||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
|
@ -158,6 +162,10 @@ void SDL_AppQuit(void *appstate, SDL_AppResult result)
|
||||||
|
|
||||||
AppState *state = appstate;
|
AppState *state = appstate;
|
||||||
|
|
||||||
|
if (sample_image) {
|
||||||
|
SDL_DestroyTexture(sample_image);
|
||||||
|
}
|
||||||
|
|
||||||
if (state) {
|
if (state) {
|
||||||
if (state->rendererData.renderer)
|
if (state->rendererData.renderer)
|
||||||
SDL_DestroyRenderer(state->rendererData.renderer);
|
SDL_DestroyRenderer(state->rendererData.renderer);
|
||||||
|
|
Loading…
Reference in a new issue