[Linux的 – Ubuntu的 – C / C ] 显卡用C在Linux编程 (Ubuntu的) – 编程C本与图形在Linux (Ubuntu的)
打开屏幕,你可以看到下图:
要做到这一点,你先检查一下是不是安装基本包:
命令和apt-get安装建立必要的
接下来在终端运行下面的命令来安装所需的软件包 (运行此命令来更新之前也许):
sudo易于得到更新
命令和apt-get安装libsdl-image1.2 libsdl-image1.2-dev的诡计 - 1.8狡猾-1.8-dev的libsdl1.2debian libart-2.0-dev的libaudiofile-dev的libesd0-dev的libdirectfb-dev的libdirectfb-额外libfreetype6-dev的libxext-开发x11proto-xext-dev的libfreetype6 libaa1 libaa1-的libslang2开发,开发中的libasound2中的libasound2-dev的
现在就去下载libgraph 这里
复制文件libgraph-1.0.2.tar.gz维罗主文件夹. 右键点击这里选择Extract.
运行以下命令:
CD libgraph-1.0.2
./配置
sudo的使
须藤使安装
须藤CP /usr/local/lib/libgraph.* / usr / lib目录
通常情况下,我们的窗户都初始化图形模式的命令:
int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi");
现在我们确实有相当类似 “Ç:tcbgi” 平等 NULL
int gd=DETECT,gm; initgraph(&gd,&gm,NULL);
终于创造 1 和编译使用以下命令graphics.cpp程序文件:
G graphics.cpp -o graphics.o -lgraph
斋文件graphics.o
./graphics.o
一个简单的例子:
#include<graphics.h> #include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int main() { int gd,gm=VGAMAX; gd=DETECT; initgraph(&gd,&gm,NULL); setbkcolor(1); cleardevice(); setcolor(4); char s1[] = "nguyenvanquan7826", s2[] = "Welcome to C++ graphics!", s3[] = "graphics on Linux"; outtextxy(100,60,s3); outtextxy(70,40,s2); outtextxy(130,80,s1); setcolor(14); line(50,200,400,200); setcolor(4); for (int i=1; i<20; i++) { setcolor(i); delay(500); circle(100+10*i,200,80); } cin.get(); return 0; }
结果:
更多更新 1 艺术品:
#include<graphics.h> #include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int main() { int gd=DETECT,gm; initgraph(&gd,&gm,NULL); setbkcolor(1); // set backgroud int x = 250; setcolor(12); //outline heart circle(x+50,50,40); delay(1000); circle(x+110,50,40); delay(500); line(x+22,80,x+80,140); delay(500); line(x+80,140,x+138,80); delay(500); floodfill(x+50,50,12); //fill heart delay(500); floodfill(x+110,50,12); delay(500); floodfill(x+80,50,12); delay(500); floodfill(x+80,100,12); delay(500); setcolor(RED); outtextxy(x+35,50,"We love Linux"); outtextxy(x+35,150,"VietSource.net"); cin.get(); closegraph(); return 0; }
参考:
在C中的图形文件: 下载中心
但现在不知道如何设置文本的颜色. 如果你知道如何解决它,欢迎您分享.
在文章中引用: HTTP://blog.eternal-thinker.com
OI董事会的数学 8 我张贴TN
帖子 8 与此相关的一个物流在那里你?
其算法你GG离线搜索. 🙂
Vất luôn cai libgraph đi bạn. No la bộ lib viết trên SDL nên nếu thich đồ họa thi dung luôn sdl.
cho mình hỏi lúc nhập ./graphics.o thì vẫn chạy nhưng ma nó báo lỗi:
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
1: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost’ 失败.
Thế làm thế nào để fix a?
Using nameplace để làm gì vậy a
为了能够用在std命令. VD CIN命令.