SDL窗口没有出现在Eclipse中

时间:2017-06-02 06:45:48

标签: c++ eclipse sdl

#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).

1 个答案:

答案 0 :(得分:0)

我有同样的问题!我从我的工作区中的... \ SDL2-2.0.5 \ i686-w64-mingw32 \ bin目录中复制了SDL2.dll。它工作正常。