SDL大概流程 : 初始化好 window 跟 renderer 後,存取 Surface (圖片),用 Surface 建立 Texture,再把 Texture 複製(RenderCopy)到 renderer 上,最後 RenderPresent。

之後每一幀(或動作)只要改變 Texture 再重新複製到 renderer 上就好。

int SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);

SDL_Rect * srcrect 是複製上 renderer 時 texture 的哪個部份&大小
NULL代表整張圖片

SDL_Rect * dstrect 是複製上 renderer 時在 renderer 的哪個位置&位置大小
NULL代表複製到整個renderer 

SDL_Rect{
  int x; //x軸位置
  int y; //y軸位置
  int w; //矩形寬
  int h; //矩形高
}

Untitled

Untitled

方向鍵上下控制電量/左右控制AC變亮變暗(模擬開關)