试试sdl
$ ls
main.c Makefile pic.bmp
$ cat main.c
#include <SDL2/SDL.h>
int main(void) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *win = SDL_CreateWindow("hello world", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1440, 900, SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Surface *bmp = SDL_LoadBMP("pic.bmp");
SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
SDL_FreeSurface(bmp);
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderPresent(ren);
while(1) {
SDL_Event event;
SDL_WaitEvent(&event);
SDL_Log("Event type is %u\n", event.type);
switch(event.type) {
case SDL_QUIT:
goto QUIT_LOOP;
}
}
QUIT_LOOP:
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
$ cat Makefile
main: main.o
gcc -g -Wall -o $@ $^ `pkg-config --libs sdl2`
clean:
rm -f *.o main
$ make
cc -c -o main.o main.c
gcc -g -Wall -o main main.o `pkg-config --libs sdl2`
$ ls
main main.c main.o Makefile pic.bmp
$ pacman -Qi sdl2
Name : sdl2
Version : 2.0.22-2
Description : A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard
(Version 2)
Architecture : x86_64
URL : https://www.libsdl.org
Licenses : MIT
Groups : None
Provides : None
Depends On : glibc libxext libxrender libx11 libgl libxcursor hidapi libusb
Optional Deps : alsa-lib: ALSA audio driver [installed]
libpulse: PulseAudio audio driver [installed]
jack: JACK audio driver [installed]
pipewire: PipeWire audio driver
libdecor: Wayland client decorations
Required By : ffmpeg ffmpeg4.4 qemu-audio-sdl qemu-ui-sdl sdl12-compat sdl2_image
Optional For : None
Conflicts With : None
Replaces : None
Installed Size : 3.70 MiB
Packager : Sven-Hendrik Haase <svenstaro@gmail.com>
Build Date : Mon 23 May 2022 10:18:28 AM CST
Install Date : Thu 02 Jun 2022 10:03:26 PM CST
Install Reason : Installed as a dependency for another package
Install Script : No
Validated By : Signature
$
|