gpt4 book ai didi

c - 我需要有关 SDL 2 的帮助

转载 作者:行者123 更新时间:2023-11-30 14:50:25 29 4
gpt4 key购买 nike

运行我的 prog 时遇到问题:“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

最佳答案

作为尤金·Sh.指出您的表面未初始化

您需要以某种方式创建曲面,可以通过加载 IMG 或使用 SDL_CreateRGBSurface 。在调用 SDL_FillRect 之前添加此内容,现在您的代码将显示绿屏。

image = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);

关于c - 我需要有关 SDL 2 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48997996/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com