首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >我需要有关SDL 2的帮助

我需要有关SDL 2的帮助
EN

Stack Overflow用户
提问于 2018-02-26 22:16:02
回答 1查看 61关注 0票数 0

当我运行我的程序时,我遇到了一个问题:"prog.exe刚刚停止工作“。

代码语言:javascript
运行
AI代码解释
复制
#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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-26 23:53:16

名为尤金·施瓦茨。指出你的表面没有初始化

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

代码语言:javascript
运行
AI代码解释
复制
image = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48997996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档