我想将SDL与C而不是C++一起使用,但我无法使事件发挥作用.如果它是一个.c或cpp文件并使用g ++编译,如果它是.cpp文件并使用gcc编译,则此代码可以正常工作.但是,如果它是一个.c文件并使用gcc编译它编译得很好,但SDL_QUIT事件实际上并没有做任何事情,窗口就会永远挂起.
#include<SDL2/SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 400;
int init();
int loadMedia();
void mainLoop();
void close();
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
SDL_Surface* helloWorld = NULL;
int main( int argc, char* args[] ){
if( !init() ){
printf("Failed to initialize!\n");
}
else{
if( !loadMedia() ){
printf("Failed to load media!\n");
}
else{
mainLoop();
}
}
close();
return 0;
}
void mainLoop(){
int quit = 0;
SDL_Event e;
while( !quit ){ …Run Code Online (Sandbox Code Playgroud)