Skip to content

Commit c7a9d3b

Browse files
committed
Update SDL examples
1 parent 92528db commit c7a9d3b

8 files changed

Lines changed: 39 additions & 40 deletions

File tree

_includes/samples/sdl_image/CMakeLists.txt renamed to _includes/samples/sdl-sprite/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
cmake_minimum_required(VERSION 3.11)
22

3-
project(sdl-image)
3+
project(sdl-sprite)
44

55
add_executable(${PROJECT_NAME} main.c)
66

77
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
8-
find_package(SDL3_image REQUIRED)
98

109
target_link_libraries(${PROJECT_NAME} PRIVATE
1110
SDL3::SDL3
12-
SDL3_image::SDL3_image
1311
)
1412

1513
if(PSP)
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include <SDL3/SDL.h>
22
#include <SDL3/SDL_main.h>
3-
#include <SDL3_image/SDL_image.h>
43

5-
int main(int argc, char *argv[])
6-
{
4+
int main(int argc, char *argv[]) {
5+
// This prevents compiler warnings
6+
// We don't actually need these variables, but they do need to be there so SDL_main works
7+
(void)argc;
8+
(void)argv;
9+
10+
// Initialize sdl
711
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
812
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
913
return 1;
@@ -18,7 +22,7 @@ int main(int argc, char *argv[])
1822
}
1923

2024
// Load the texture
21-
SDL_Surface * pixels = IMG_Load("grass.png"); // For png you can also use SDL_LoadPNG instead, which does not require SDL image
25+
SDL_Surface * pixels = SDL_LoadPNG("grass.png");
2226
if (!pixels) {
2327
SDL_Log("Couldn't load grass.png: %s", SDL_GetError());
2428
SDL_Quit();

_includes/samples/sdl/main.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include <SDL3/SDL.h>
22
#include <SDL3/SDL_main.h>
33

4-
int main(int argc, char *argv[])
5-
{
4+
int main(int argc, char *argv[]) {
5+
// This prevents compiler warnings
6+
// We don't actually need these variables, but they do need to be there so SDL_main works
7+
(void)argc;
8+
(void)argv;
9+
10+
// Initialize sdl
611
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
712
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
813
return 1;

_includes/samples/sdl_mixer/main.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
#define SCREEN_WIDTH 480
77
#define SCREEN_HEIGHT 272
88

9-
// audio file path
10-
#define MUSIC_PATH "ms0:/MUSIC/test.ogg" // ogg/mp3 file format
11-
129
int main(int argc, char **argv) {
10+
// This prevents compiler warnings
11+
// We don't actually need these variables, but they do need to be there so SDL_main works
1312
(void)argc;
1413
(void)argv;
1514

1615
// Initialize sdl
17-
SDL_Init(SDL_INIT_VIDEO |
18-
SDL_INIT_AUDIO |
19-
SDL_INIT_GAMEPAD
20-
);
16+
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD)) {
17+
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
18+
return 1;
19+
}
2120

2221
// Initialize sdl2_mixer
2322
Mix_OpenAudio(44100,
@@ -26,20 +25,13 @@ int main(int argc, char **argv) {
2625
2048
2726
);
2827

29-
// create window
30-
SDL_Window *win = SDL_CreateWindow(
31-
"psp_win",
32-
SDL_WINDOWPOS_UNDEFINED,
33-
SDL_WINDOWPOS_UNDEFINED,
34-
SCREEN_WIDTH,
35-
SCREEN_HEIGHT,
36-
0
37-
);
38-
39-
// Create Renderer
40-
SDL_Renderer *renderer = SDL_CreateRenderer(
41-
win, -1, 0
42-
);
28+
SDL_Window * window = NULL;
29+
SDL_Renderer * renderer = NULL;
30+
if (!SDL_CreateWindowAndRenderer("window", 480, 272, 0, &window, &renderer)) {
31+
SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
32+
SDL_Quit();
33+
return 2;
34+
}
4335

4436
// Load ogg file
4537
Mix_Music *ogg_file = NULL;

_includes/samples/sdl_ttf/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#define SCREEN_WIDTH 480
77
#define SCREEN_HEIGHT 272
88

9-
int main(int argc, char **argv)
10-
{
9+
int main(int argc, char **argv) {
1110
// This prevents compiler warnings
1211
// We don't actually need these variables, but they do need to be there so SDL_main works
1312
(void)argc;
1413
(void)argv;
1514

15+
// Initialize sdl
1616
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
1717
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
1818
return 1;

basic_programs.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ psp-cmake ..
117117
make
118118
```
119119

120-
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and add the grass image file, download it from <a href="/resources/grass.png">here</a>, to be able to run it on the PSP.
120+
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and add the grass image file, download it from <a href="/resources/grass.png">here</a>, to be able to run it on the PSP.
121121

122122
More libgu examples can be found <a href="https://github.com/pspdev/pspsdk/tree/master/src/samples/gu">here</a>.
123123

@@ -193,7 +193,7 @@ psp-cmake ..
193193
make
194194
```
195195

196-
<p>This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and the PSP can run it.</p>
196+
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and the PSP can run it.
197197

198198
More audiolib examples can be found <a href="https://github.com/pspdev/pspsdk/tree/master/src/samples/audio">here</a>.
199199

@@ -234,7 +234,7 @@ psp-cmake ..
234234
make
235235
```
236236

237-
<p>This will result in an EBOOT.PBP` file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and the PSP can run it.</p>
237+
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and the PSP can run it.
238238

239239
If you have sdl dev package and a compiler installed this code will also build on Linux for Linux by running:
240240

@@ -248,7 +248,7 @@ More documentation on SDL can be found <a href="http://wiki.libsdl.org/FrontPage
248248

249249
</details>
250250

251-
## Using SDL Image
251+
## Using SDL for Drawing Sprites
252252
{: .fs-6 .fw-700 }
253253

254254
![](images/sprite.png)
@@ -266,13 +266,13 @@ Click on view source below to see the code and how to build it.
266266
**main.c**
267267

268268
```c
269-
{% include samples/sdl_image/main.c %}
269+
{% include samples/sdl-sprite/main.c %}
270270
```
271271
272272
**CMakeLists.txt**
273273
274274
```cmake
275-
{% include samples/sdl_image/CMakeLists.txt %}
275+
{% include samples/sdl-sprite/CMakeLists.txt %}
276276
```
277277

278278
Building can be done with:
@@ -331,7 +331,7 @@ psp-cmake ..
331331
make
332332
```
333333

334-
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and you need an audio file to test the program, download it from <a href="/resources/test.ogg">here</a>. Put it in a directory in ms0:/MUSIC/ and then rename the audio file same as name on your *MUSIC_PATH* macro in your C code and the PSP can run it.
334+
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and add the test audio file, download it from <a href="/resources/test.ogg">here</a>, to be able to run it on the PSP.
335335

336336
Documentation for SDL_mixer can be found <a href="https://wiki.libsdl.org/SDL3_mixer/FrontPage">here</a>.
337337

@@ -340,7 +340,7 @@ Documentation for SDL_mixer can be found <a href="https://wiki.libsdl.org/SDL3_m
340340
## Using SDL ttf
341341
{: .fs-6 .fw-700 }
342342

343-
![](images/sdl_ttf.jpg)
343+
![](images/sdl_ttf.png)
344344

345345
This is a simple program to use the SDL_ttf library. It provides functionality for rendering TrueType fonts for your PSP.
346346

images/sdl_ttf.jpg

-9.04 KB
Binary file not shown.

images/sdl_ttf.png

2.56 KB
Loading

0 commit comments

Comments
 (0)