[Linux – Ubuntu – C / C ] Graphics Programming with C on Linux (Ubuntu) – Programming C with Graphics on Linux (Ubuntu)
Open the screen you can see the following illustration:

To do this you first check the basic package is not installed:
sudo apt-get install build-essential
Next run the following command in the Terminal to install the needed packages (Maybe before you run this command to update):
sudo apt-get update
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-dev
Now go download libgraph here
Copy the file libgraph-1.0.2.tar.gz vào home folder. Right click and select Extract here.
Run the following command to:
cd libgraph-1.0.2
./configure
sudo make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
Normally the windows we have the command to initialize graphics mode:
int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi");
And now we do have rather similar “c:tcbgi” equal NULL
int gd=DETECT,gm; initgraph(&gd,&gm,NULL);
Finally created 1 and compile the program file with the following command graphics.cpp:
g graphics.cpp -o graphics.o -lgraph
Chạy file graphics.o
./graphics.o
A simple example:
#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;
}
Result:

more updates 1 Artwork:

#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;
}
Refer:
C Programming on Ubuntu (Linux)
Document graphics in C: dowload
But now is not known how to set the color for text. If you know how to fix it you are welcome to share.
Article referenced in: http://blog.eternal-thinker.com



oi the board for math 8 I post it tn
Posts 8 the logistics related to this one where you?
Its you search algorithm GG offline. 🙂
Throw away your libgraph always rule. It is the writing on the SDL lib so if thich thi dung always SDL graphics.
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’ failed.
Thế làm thế nào để fix a?
Using nameplace để làm gì vậy a
Để có thể dùng được các lệnh trong std. VD lệnh cin.