在虚拟机linux里面怎么用c编写带图形界面的程序
跟着小甲鱼的带你学c带你飞学了一遍,47还是48以后就没题目了,然后我又自己看了一遍c primer plus,现在想自己动手写点东西,发现自己好像只会在那个黑色方框里敲代码,在百度上查了好像是要安装一个叫什么图形界面的东西才能编写像俄罗斯方块,贪吃蛇这种带图形的程序,想问问论坛里的大佬们,在虚拟机的linux系统里面怎么安装这个东西(虚拟机安装linux就是跟着论坛里面那个系列教程弄的,我现在还有点懵,只会用,不会装){:10_269:} 试试sdl
$ ls
main.cMakefilepic.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
mainmain.cmain.oMakefilepic.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 : glibclibxextlibxrenderlibx11libgllibxcursorhidapilibusb
Optional Deps : alsa-lib: ALSA audio driver
libpulse: PulseAudio audio driver
jack: JACK audio driver
pipewire: PipeWire audio driver
libdecor: Wayland client decorations
Required By : ffmpegffmpeg4.4qemu-audio-sdlqemu-ui-sdlsdl12-compatsdl2_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
$
https://cn.bing.com/search?form=MOZLBR&pc=MOZI&q=centos+sdl2
人造人 发表于 2022-8-30 14:54
https://cn.bing.com/search?form=MOZLBR&pc=MOZI&q=centos+sdl2
十分感谢!距离我跟着论坛里的教程在虚拟机里安装linux并配置相关的设置到现在大概四个月了,我早忘了那些乱七八糟的命令,今天再用,我第一次感觉到linux的强大 人造人 发表于 2022-8-30 14:54
https://cn.bing.com/search?form=MOZLBR&pc=MOZI&q=centos+sdl2
大佬,我能不能再问个问题,我按照下面那个连接安装了sdl2,但是你第一个发的那个代码是干嘛,我没看懂 gbdx 发表于 2022-8-30 22:50
大佬,我能不能再问个问题,我按照下面那个连接安装了sdl2,但是你第一个发的那个代码是干嘛,我没看懂
一个sdl的测试程序,显示一张图片
页:
[1]