程式語言 - Wine - C/C++ - SDL v2.0 - Hello, world!



參考資訊:
http://www.winprog.org/tutorial/start.html
https://www.libsdl.org/release/?utm_source=chatgpt.com
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox

main.c

#undef __WIN32__
#undef __WIN32
#undef _WIN32
#undef WIN32

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

#include <SDL.h>
#include <SDL2_gfxPrimitives.h> 
  
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    const int w = 320;
    const int h = 240;
    const int bpp = 16;
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;
 
    SDL_Init(SDL_INIT_VIDEO);
    window = SDL_CreateWindow("main", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_SHOWN);
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
 
    SDL_RenderClear(renderer);
    stringRGBA(renderer, 100, 100, "Hello, world!", 0xff, 0xff, 0xff, 0xff);
    SDL_RenderPresent(renderer);
 
    SDL_Delay(3000);
 
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

編譯、執行

$ winegcc main.c -o main.exe -I/usr/include/SDL2 -lSDL2 -lSDL2_gfx
$ wine main.exe.so