youtube:cpp-intro-031
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
youtube:cpp-intro-031 [2024/02/28 18:26] – 削除 - 外部編集 (不明な日付) 127.0.0.1 | youtube:cpp-intro-031 [2024/02/29 11:52] (現在) – freemikan | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== HelloSDL-window ====== | ||
+ | |||
+ | 作成日: 2023-07-21 (金) | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== main.cpp ===== | ||
+ | |||
+ | <file cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main(int argc, char **argv) { | ||
+ | int const ScreenWidth = 400; | ||
+ | int const ScreenHeight = 400; | ||
+ | |||
+ | if (SDL_Init(SDL_INIT_VIDEO) < 0) { | ||
+ | std::cerr << " | ||
+ | std:: | ||
+ | } | ||
+ | | ||
+ | SDL_Window *window = SDL_CreateWindow( | ||
+ | " | ||
+ | SDL_WINDOWPOS_CENTERED, | ||
+ | SDL_WINDOWPOS_CENTERED, | ||
+ | ScreenWidth, | ||
+ | ScreenHeight, | ||
+ | 0); | ||
+ | if (window == nullptr) { | ||
+ | std::cerr << " | ||
+ | std:: | ||
+ | } | ||
+ | | ||
+ | SDL_Renderer *renderer = SDL_CreateRenderer(window, | ||
+ | if (renderer == nullptr) { | ||
+ | std::cerr << " | ||
+ | std:: | ||
+ | } | ||
+ | | ||
+ | bool running = true; | ||
+ | while (running) { | ||
+ | SDL_Event event; | ||
+ | while (SDL_PollEvent(& | ||
+ | if (event.type == SDL_QUIT) { | ||
+ | running = false; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | SDL_SetRenderDrawColor(renderer, | ||
+ | SDL_RenderClear(renderer); | ||
+ | | ||
+ | SDL_SetRenderDrawColor(renderer, | ||
+ | SDL_Rect rect{100, 150, 150, 100}; | ||
+ | SDL_RenderFillRect(renderer, | ||
+ | | ||
+ | SDL_RenderPresent(renderer); | ||
+ | | ||
+ | SDL_Delay(1); | ||
+ | } | ||
+ | | ||
+ | SDL_DestroyRenderer(renderer); | ||
+ | SDL_DestroyWindow(window); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Makefile ===== | ||
+ | |||
+ | <file makefile> | ||
+ | SRCS = \ | ||
+ | main.cpp | ||
+ | OBJS = ${SRCS: | ||
+ | DEPS = ${SRCS: | ||
+ | EXECUTABLE = HelloSDL-window.exe | ||
+ | CXXFLAGS = -IC: | ||
+ | LDFLAGS = -LC: | ||
+ | LDLIBS = -lmingw32 -lSDL2main -lSDL2 | ||
+ | |||
+ | .PHONY: all | ||
+ | all: ${EXECUTABLE} | ||
+ | |||
+ | ${EXECUTABLE}: | ||
+ | ${CXX} -o $@ $^ ${LDFLAGS} ${LDLIBS} | ||
+ | |||
+ | %.o: %.cpp | ||
+ | ${CXX} -c -o $@ $< -MMD -MP ${CXXFLAGS} | ||
+ | |||
+ | .PHONY: clean | ||
+ | clean: | ||
+ | ${RM} ${EXECUTABLE} ${OBJS} ${DEPS} | ||
+ | |||
+ | -include ${DEPS} | ||
+ | </ | ||
+ | |||
+ | '' | ||