我已经在互联网上搜索了数周,但没有一个答案有效。我的代码是:
#include <SDL.h>
#include <iostream>
using namespace std;
int main(int argc, char** argv[])
{
SDL_Window *win = nullptr;
SDL_Renderer *ren = nullptr;
SDL_Surface *bmp = nullptr;
SDL_Texture *tex = nullptr;
if (SDL_Init(SDL_INIT_EVERYTHING))
{
cout << SDL_GetError();
return 1;
}
win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if (win == nullptr)
{
cout << SDL_GetError();
return 1;
}
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == nullptr)
{
cout << SDL_GetError();
return 1;
}
bmp = SDL_LoadBMP("hello.bmp");
tex = SDL_CreateTextureFromSurface(ren, bmp);
SDL_FreeSurface(bmp);
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderPresent(ren);
SDL_Delay(2000);
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
我试过#undef main
(这又出现了另一个错误),甚至重新定义它都无济于事。我还尝试了其他几种尝试,例如将其创建为 Windows 控制台项目。
无论如何,我真的希望你能帮助我和其他人。干杯,
用户(在此处插入伪随机生成的整数)