Try   HackMD

VScode + SDL2 + MSYS2 Envrioment Create

MAKE STYLE
https://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php

CMAKE STYLE
https://www.willusher.io/sdl2 tutorials/2013/08/17/lesson-1-hello-world
https://trenki2.github.io/blog/2017/06/02/using-sdl2-with-cmake/

在MSYS 安裝 Gcc Gdb

pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-global

在MSYS 安裝 Gcc Gdb

pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-global

在MSYS 安裝SDL2

64bit

pacman -S mingw-w64-x86_64-SDL2

32bit

pacman -S mingw-w64-i686-SDL2

ucrt64

pacman -S mingw-w64-ucrt-x86_64-SDL2

VSCODE 步驟


VSCODE 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

#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; }