Development Environment: MacOS
Reference Material: Teacher Chen Yun's SDL2 Tutorial
Note: This is a note
EP-2
Environment Configuration#
In SDL2, we have two methods for rendering images.
- One is to use BMP format images, which have the advantage of lossless images and can be directly rendered using the SDL2 library.
- The other is to use the
SDL2_image
library to render common formats such as PNG and JPG.
We will discuss both of these methods, starting with BMP format rendering.
Configure CMake#
First, configure CMake. As mentioned in the previous article, we can simply copy and paste the configuration for SDL_image
.
It is worth noting that when using the CMakeTools extension in VScode on MacOS, starting directly may fail due to the executable file not being able to find the image. Therefore, we need to add a line of code to move the executable file to the working directory.
Now, we can start the actual process.
Render BMP Format Images#
The BMP file used in this article is from Teacher Chen Yun's tutorial, with permission to use.
Cat image link: cat
To render a BMP file, we first load the BMP file.
Then, we write a drawing function.
Complete code:
Render Images in Other Formats#
We need to include the SDL_image
library, which can be downloaded just like SDL.