簡體   English   中英

我需要有關SDL 2的幫助

[英]I need help about SDL 2

運行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

如Eugene Sh。 指出您的表面未初始化

您需要通過加載IMG或使用SDL_CreateRGBSurface來創建曲面。 在調用SDL_FillRect之前添加此代碼,現在您的代碼將顯示綠色屏幕。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM