Skip to content

Commit 38790d0

Browse files
committed
Add sprite and sdl2_image examples to basic programs
1 parent d119d1e commit 38790d0

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

basic_programs.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,45 @@ More libgu examples can be found <a href="https://github.com/pspdev/pspsdk/tree/
8484

8585
</details>
8686

87+
## Drawing Sprites
88+
{: .fs-6 .fw-700 }
89+
90+
![](images/sprite.png)
91+
92+
This is a sprite drawn on the PSP. It uses the native libgu library to draw and the stb_image library to load the image. stb_image supports a lot of image formats. For the Playstation Portable it is important that the width of images used is a power of 2. In this case 16, but 32, 64, 128 and 256 will also work. This limitation does not exist for the example with SDL2 below.
93+
94+
Click on view source below to see the code and how to build it.
95+
96+
<details markdown="1">
97+
98+
<summary>View source</summary>
99+
100+
**main.c**
101+
102+
```c
103+
{% include samples/sprite/main.c %}
104+
```
105+
106+
**CMakeLists.txt**
107+
108+
```cmake
109+
{% include samples/sprite/CMakeLists.txt %}
110+
```
111+
112+
Building can be done with:
113+
114+
```shell
115+
mkdir build && cd build
116+
psp-cmake ..
117+
make
118+
```
119+
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.
121+
122+
More libgu examples can be found <a href="https://github.com/pspdev/pspsdk/tree/master/src/samples/gu">here</a>.
123+
124+
</details>
125+
87126
## Controller
88127
{: .fs-6 .fw-700 }
89128

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

210249
</details>
211250

251+
## Using SDL2 Image
252+
{: .fs-6 .fw-700 }
253+
254+
![](images/sprite.png)
255+
256+
SDL2 image is a library which adds support for multiple image formats to SDL2. This example results in the same image as the sprite example using libgu above. Here the limitation of the image width being a power 2 does not apply.
257+
258+
Despite this example adding an option to close by pressing the start button, the code is much shorter. It can even be build for Linux without any further modifications.
259+
260+
Click on view source below to see the code and how to build it.
261+
262+
<details markdown="1">
263+
264+
<summary>View source</summary>
265+
266+
**main.c**
267+
268+
```c
269+
{% include samples/sdl2_image/main.c %}
270+
```
271+
272+
**CMakeLists.txt**
273+
274+
```cmake
275+
{% include samples/sdl2_image/CMakeLists.txt %}
276+
```
277+
278+
Building can be done with:
279+
280+
```shell
281+
mkdir build && cd build
282+
psp-cmake ..
283+
make
284+
```
285+
286+
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.
287+
288+
If you have sdl2 sdl2-image dev packages and a compiler installed this code will also build on Linux for Linux by running:
289+
290+
```shell
291+
mkdir build && cd build
292+
cmake ..
293+
make
294+
```
295+
296+
Documentation for SDL2_image can be found <a href="https://wiki.libsdl.org/SDL2_image/FrontPage">here</a>.
297+
298+
</details>
299+
300+
212301
## Using SDL2 mixer
213302
{: .fs-6 .fw-700 }
214303

@@ -244,6 +333,8 @@ make
244333

245334
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.
246335

336+
Documentation for SDL2_mixer can be found <a href="https://wiki.libsdl.org/SDL2_mixer/FrontPage">here</a>.
337+
247338
</details>
248339

249340
## Using SDL2 ttf
@@ -281,6 +372,8 @@ make
281372

282373
This will result in an EBOOT.PBP file in the build directory. Put it in a directory in ms0:/PSP/GAME/ and you need a font file to test the program, download it from <a href="/resources/Pacifico.ttf">here</a>. Put it in a directory same as EBOOT.PBP and the PSP can run it.
283374

375+
Documentation for SDL2_ttf can be found <a href="https://wiki.libsdl.org/SDL2_ttf/FrontPage">here</a>.
376+
284377
</details>
285378

286379
## More Examples

0 commit comments

Comments
 (0)