创建窗口 绘制图片
…
获得图片宽高
int iW, iH; SDL_QueryTexture(image, NULL, NULL, &iW, &iH); int x = SCREEN_WIDTH / 2 - iW / 2; int y = SCREEN_HEIGHT / 2 - iH / 2;
开始事件循环
创建SDL_Event 然后等待事件
当点击退出/按下键盘/点击鼠标 马上退出图片渲染 退出程序
//Our event union SDL_Event e; //For tracking if we want to quit bool quit = false; while (!quit) { //Read any events that occured, for now we'll just quit if any event occurs while (SDL_PollEvent(&e)) { //If user closes the window if (e.type == SDL_QUIT) { quit = true; } //If user presses any key if (e.type == SDL_KEYDOWN) { quit = true; } //If user clicks the mouse if (e.type == SDL_MOUSEBUTTONDOWN) { quit = true; } } //Rendering SDL_RenderClear(renderer); //Draw the image renderTexture(image, renderer, x, y); //Update the screen SDL_RenderPresent(renderer); }