当我运行我的程序时,我遇到了一个问题:"prog.exe刚刚停止工作“。
#include <SDL.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
SDL_Surface *screen; // even with SDL2, we can still bring ancient code back
SDL_Window *window;
SDL_Surface *image;
SDL_Init(SDL_INIT_VIDEO); // init video
// create the window like normal
window = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
// but instead of creating a renderer, we can draw directly to the screen
screen = SDL_GetWindowSurface(window);
// let's just show some classic code for reference
SDL_FillRect(image, NULL, SDL_MapRGB(image->format, 0, 255, 0));
SDL_BlitSurface(image, NULL, screen, NULL); // blit it to the screen
SDL_FreeSurface(image);
// this works just like SDL_Flip() in SDL 1.2
SDL_UpdateWindowSurface(window);
// show image for 2 seconds
SDL_Delay(2000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
// gcc src/main.c -o bin/prog -I include -L lib -lmingw32 -lSDL2main -lSDL2
发布于 2018-02-26 23:53:16
名为尤金·施瓦茨。指出你的表面没有初始化
您需要以某种方式创建曲面,通过加载IMG或使用SDL_CreateRGBSurface。在调用SDL_FillRect之前添加此代码,现在您的代码将显示一个绿色屏幕。
image = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
https://stackoverflow.com/questions/48997996
复制相似问题