C++ SDL#U BlitSurface不';好像不行

C++ SDL#U BlitSurface不';好像不行,c++,struct,sdl,C++,Struct,Sdl,由头脑风暴解决。下面的代码已修复,现在可以使用。 窗宽:640,窗高:480 函数调用顺序: 开始() 循环() Stop()(当前已注释,因为如果循环不返回0,它将在返回1之前调用Stop) 结构: #define MAX_IMAGES 50 struct ImageStructure{ SDL_Surface* Texture; int x; int y; }; ImageStructure Image[MAX_IMAGES]; //All Image Textu

由头脑风暴解决。下面的代码已修复,现在可以使用。 窗宽:640,窗高:480

函数调用顺序: 开始()

循环()

Stop()(当前已注释,因为如果循环不返回0,它将在返回1之前调用Stop)

结构:

#define MAX_IMAGES 50

struct ImageStructure{
    SDL_Surface* Texture;
    int x;
    int y;
};

ImageStructure Image[MAX_IMAGES]; //All Image Textures are set to NULL by default in the start function
SDL_Event Event;
SDL_Surface* Screen = NULL;
现在启动函数。我已经清除了所有的设置代码

int Program::Start(){
    for(int id = 0; id < MAX_IMAGES; id++){
        Image[id].Texture = NULL;
        Image[id].x = 0;
        Image[id].y = 0;
    }

    if(LoadIMG(1, 0, 0) != 0){
        return 1;
    }

    if(PrintText(2, "Hello World", 10, 310) != 0){
        return 2;
    }

    return 0;
}
ShowIMG函数

int Program::LoadIMG(int id, int x, int y){
    SDL_Surface* loadedImage = NULL;
    switch(id){
        case 0:
            loadedImage = IMG_Load("Textures\\Icon.jpeg");
            break;
        case 1:
            loadedImage = IMG_Load("Textures\\Test.jpeg");
            break;
        default:
            return 1;
    }
    if(loadedImage != NULL){
        Image[id].Texture = SDL_DisplayFormat(loadedImage);
        Image[id].x = x;
        Image[id].y = y;
    }
    else{
        return 1;
    }
    SDL_FreeSurface(loadedImage);
    return 0;
}
int Program::ShowIMG(int id){
    SDL_Rect position;
    position.x = Image[id].x;
    position.y = Image[id].y;
    SDL_BlitSurface(Image[id].Texture, NULL, Screen, &position);
    return 0;
}
和PrintText函数

int Program::PrintText(int id, std::string Text, int x, int y){
    TTF_Font *Font = NULL;
    SDL_Color TextColor = {255, 255, 255};
    Font = TTF_OpenFont("Other\\PoseiAOE.ttf", 22);
    if(Font == NULL){
        return 1;
    }
    Image[id].Texture = TTF_RenderText_Solid(Font, Text.c_str(), TextColor);
    Image[id].x = x;
    Image[id].y = y;
    if(Image[id].Texture == NULL){
        return 1;
    }
    return 0;
}

除非在某个地方显式地声明,否则我不能确定所有的曲面在默认情况下都设置为NULL。另外,在您的
for(int-id;id
int Program::PrintText(int id, std::string Text, int x, int y){
    TTF_Font *Font = NULL;
    SDL_Color TextColor = {255, 255, 255};
    Font = TTF_OpenFont("Other\\PoseiAOE.ttf", 22);
    if(Font == NULL){
        return 1;
    }
    Image[id].Texture = TTF_RenderText_Solid(Font, Text.c_str(), TextColor);
    Image[id].x = x;
    Image[id].y = y;
    if(Image[id].Texture == NULL){
        return 1;
    }
    return 0;
}