#include <iostream>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv[]){
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
if(SDL_Init(SDL_INIT_VIDEO) < 0){
cout << "SDL init failed." << endl;
return 1;
}
SDL_Window *window = SDL_CreateWindow("Particle Fire Explosion",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(window == NULL){
SDL_Quit();
return 2;
}
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_Texture *texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, SCREEN_WIDTH, SCREEN_HEIGHT);
if (renderer == NULL){
cout << "Could not create renderer" << endl;
SDL_DestroyWindow(window);
SDL_Quit();
return 3;
}
if(texture == NULL){
cout << "Could not create texture" << endl;
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 4;
}
Uint32 *buffer = new Uint32[SCREEN_WIDTH*SCREEN_HEIGHT];
SDL_UpdateTexture(texture, NULL, buffer, SCREEN_WIDTH*sizeof(Uint32));
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
bool quit = false;
SDL_Event event;
while(!quit){
//Update particles
// Draw particles
// Check for messages/events
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT){
quit = true;
}
}
}
delete [] buffer;
SDL_DestroyRenderer(renderer);
SDL_DestroyTexture(texture);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
代码可以编译,但是我不断得到
-1,073,741,515
的退出值而不是退出值
0
。 SDL窗口不会显示。可能是我的IDE或我的代码有问题吗?控制台输出
>terminated< (exit value -1,073,741,515).
最佳答案
我有同样的问题!我从工作区中的... \ SDL2-2.0.5 \ i686-w64-mingw32 \ bin目录复制了SDL2.dll。工作正常。
关于c++ - Eclipse中没有出现SDL窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44322478/