# VScode + SDL2 + MSYS2 Envrioment Create MAKE STYLE https://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php CMAKE STYLE https://www.willusher.io/sdl2%20tutorials/2013/08/17/lesson-1-hello-world https://trenki2.github.io/blog/2017/06/02/using-sdl2-with-cmake/ ## 在MSYS 安裝 GCC GDB SDL2 ```bash case "$MSYSTEM" in UCRT64) pacman -S --noconfirm mingw-w64-ucrt-x86_64-gcc \ mingw-w64-ucrt-x86_64-gdb \ mingw-w64-ucrt-x86_64-global \ mingw-w64-ucrt-x86_64-SDL2 \ mingw-w64-ucrt-x86_64-make \ mingw-w64-ucrt-x86_64-cmake ;; MINGW64) pacman -S --noconfirm mingw-w64-x86_64-gcc \ mingw-w64-x86_64-gdb \ mingw-w64-x86_64-global \ mingw-w64-x86_64-SDL2 \ mingw-w64-x86_64-make \ mingw-w64-x86_64-cmake ;; *) echo "Unsupported or unknown MSYS2 environment: $MSYSTEM" exit 1 ;; esac ``` 32bit ```shell= pacman -S mingw-w64-i686-SDL2 ``` add alias > alias make=mingw32-make # VSCODE 步驟 ![](https://i.imgur.com/sqbulVa.png) ![](https://i.imgur.com/FoVVETY.png) # VSCODE CMAKE 最後結果 ![](https://i.imgur.com/zpVVloT.png) ```cmake= cmake_minimum_required(VERSION 3.0.0) project(SDL2_HELLOWLRD VERSION 0.1.0) include(CTest) enable_testing() find_package(SDL2 REQUIRED) include_directories(SDL2_HELLOWLRD ${SDL2_INCLUDE_DIRS}) add_executable(SDL2_HELLOWLRD main.c) target_link_libraries(SDL2_HELLOWLRD ${SDL2_LIBRARIES}) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack) ``` # Main.c ```cpp= #include "SDL.h" int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow( "SDL2Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0 ); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE); SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_RenderClear(renderer); SDL_RenderPresent(renderer); SDL_Delay(3000); SDL_DestroyWindow(window); SDL_Quit(); return 0; } ```