2015-06-18 88 views
-1

我正嘗試使用用GCC編譯的C語言中的SDL2,但事件不起作用,例如,我無法用SDL_QUIT關閉窗口。 請問代碼有問題嗎?SDL2事件在C中不起作用

#include <stdlib.h> 
#include <stdio.h> 
#include <SDL2/SDL.h> 

int main(int argc, char** argv) 
{ 
    if (SDL_Init(SDL_INIT_VIDEO) != 0) { 
     fprintf(stdout,"Échec\n", SDL_GetError()); 
     return -1; 
    } 

    SDL_Window* windowImg = NULL; 
    SDL_Renderer* renderImg = NULL; 
    int quit = 0; 
    SDL_Event e; 

    windowImg = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 400, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); 
    renderImg = SDL_CreateRenderer(windowImg, -1, SDL_RENDERER_ACCELERATED); 

    while (!quit) { 
     while (SDL_PollEvent(&e) != 0) { 
      if (e.type == SDL_QUIT) { 
       quit = 1; 
       break; 
      } 
     } 
    } 

    SDL_DestroyWindow(windowImg); 
    SDL_Quit(); 

    return 0; 
} 
+0

日夜不停的細(即,擊打'SDL_QUIT'邏輯退出)上的Win7瓦特/ VS2012當我點擊關閉窗口(「X」)按鈕。你如何試圖產生一個'SDL_QUIT'事件? – genpfault

回答

0

好的,我忘在生成選項>鏈接器選項鍊接庫: -lSDL2main -lSDL2