Skip to content

Commit f691429

Browse files
committed
Initial work using SDL3 for ttf example
1 parent db49e28 commit f691429

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

_includes/samples/sdl2_ttf/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ project(sdl2_ttf)
55
add_executable(${PROJECT_NAME} main.c)
66

77
include(FindPkgConfig)
8-
pkg_search_module(SDL2 REQUIRED sdl2)
9-
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
8+
pkg_search_module(SDL3 REQUIRED sdl3)
9+
pkg_search_module(SDL3_TTF REQUIRED sdl3-ttf)
1010

1111
target_include_directories(${PROJECT_NAME} PRIVATE
12-
${SDL2_INCLUDE_DIRS}
13-
${SDL2_TTF_INCLUDE_DIRS}
12+
${SDL3_INCLUDE_DIRS}
13+
${SDL3_TTF_INCLUDE_DIRS}
1414
)
1515

1616
target_link_libraries(${PROJECT_NAME} PRIVATE
17-
${SDL2_LIBRARIES}
18-
${SDL2_TTF_LIBRARIES}
17+
${SDL3_LIBRARIES}
18+
${SDL3_TTF_LIBRARIES}
1919
)
2020

2121
if(PSP)
@@ -27,4 +27,4 @@ if(PSP)
2727
TITLE ${PROJECT_NAME}
2828
VERSION 01.00
2929
)
30-
endif()
30+
endif()

_includes/samples/sdl2_ttf/main.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <stdio.h>
22

3-
#include <SDL2/SDL.h>
4-
#include <SDL2/SDL_ttf.h>
3+
#include <SDL3/SDL.h>
4+
#include <SDL3/SDL_main.h>
5+
#include <SDL3_ttf/SDL_ttf.h>
56

67
// Define screen dimensions
78
#define SCREEN_WIDTH 480
@@ -32,8 +33,6 @@ int main(int argc, char **argv)
3233

3334
SDL_Window *win = SDL_CreateWindow(
3435
"window",
35-
SDL_WINDOWPOS_UNDEFINED,
36-
SDL_WINDOWPOS_UNDEFINED,
3736
SCREEN_WIDTH,
3837
SCREEN_HEIGHT,
3938
0);
@@ -45,22 +44,22 @@ int main(int argc, char **argv)
4544
SDL_GetError());
4645
}
4746

48-
SDL_Renderer *renderer = SDL_CreateRenderer(win, -1, 0);
47+
SDL_Renderer *renderer = SDL_CreateRenderer(win, NULL);
4948
TTF_Font *font = TTF_OpenFont("Pacifico.ttf", 40);
5049

5150
// Set the text and background color
5251
SDL_Color text_color = {0xff, 0xff, 0xff, 0xff};
5352
SDL_Color bg_color = {0x00, 0x00, 0x00, 0xff};
5453

55-
SDL_Rect text_rect;
56-
SDL_Surface *surface = TTF_RenderText(font, "Hello World!", text_color, bg_color);
54+
SDL_FRect text_rect;
55+
SDL_Surface *surface = TTF_RenderText_Shaded(font, "Hello World!", 0, text_color, bg_color);
5756
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
5857

5958
// Get text dimensions
6059
text_rect.w = surface->w;
6160
text_rect.h = surface->h;
6261

63-
SDL_FreeSurface(surface);
62+
SDL_DestroySurface(surface);
6463

6564
text_rect.x = (SCREEN_WIDTH - text_rect.w) / 2;
6665
text_rect.y = text_rect.h + 30;
@@ -73,14 +72,14 @@ int main(int argc, char **argv)
7372
{
7473
switch (e.type)
7574
{
76-
case SDL_QUIT:
75+
case SDL_EVENT_QUIT:
7776
running = 0;
7877
break;
79-
case SDL_CONTROLLERDEVICEADDED:
80-
SDL_GameControllerOpen(e.cdevice.which);
78+
case SDL_EVENT_GAMEPAD_ADDED:
79+
SDL_OpenGamepad(e.cdevice.which);
8180
break;
82-
case SDL_CONTROLLERBUTTONDOWN:
83-
if (e.cbutton.button == SDL_CONTROLLER_BUTTON_START)
81+
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
82+
if (e.button.button == SDL_GAMEPAD_BUTTON_START)
8483
{
8584
running = 0;
8685
}
@@ -91,7 +90,7 @@ int main(int argc, char **argv)
9190
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
9291
SDL_RenderClear(renderer);
9392
SDL_SetRenderDrawColor(renderer, 0xff, 0x00, 0x00, 0xff);
94-
SDL_RenderCopy(renderer, texture, NULL, &text_rect);
93+
SDL_RenderTexture(renderer, texture, NULL, &text_rect);
9594
SDL_RenderPresent(renderer);
9695
}
9796

@@ -101,4 +100,4 @@ int main(int argc, char **argv)
101100
SDL_Quit();
102101

103102
return 0;
104-
}
103+
}

0 commit comments

Comments
 (0)