MingW-v4.8.0+EDE-v13.04 配置使用C语言图形库

From: http://www.cnblogs.com/killerlegend/p/3946768.html

Author:KillerLegend

Date:2014.8.30

MingW的配置教程在这儿: http://www.cnblogs.com/killerlegend/p/3746504.html

EDE图形库可以到这儿下载: http://misakamm.bitbucket.org/man/index.htm,其源代码在这儿: http://sourceforge.net/p/tcgraphics/code/HEAD/tree/

在这篇文章书写的时候,最新版是13.04,你也可以到我的百度云下载(

库文件下载: 链接:http://pan.baidu.com/s/1i3qqTm9 密码:chwl

源代码下载: 链接:http://pan.baidu.com/s/1jG9lLII 密码:fdds).

解压后文件内容大致如下:

如上图所示,拷贝红色方框中的文件到MingWincludelib文件夹下:

拷贝完成后,建立一个C++文件,输入代码如下:

 1 #include <graphics.h>
 2 
 3 #include <time.h>
 4 
 5 #include <math.h>
 6 
 7  
 8 
 9 void paintstar(double x, double y, double r, double a)
10 
11 {
12 
13 int pt[10];
14 
15 for (int n = 0; n < 5; ++n)
16 
17 {
18 
19 pt[n*2] = (int)( -cos( PI * 4 / 5 * n + a ) * r + x );
20 
21 pt[n*2+1] = (int)( sin( PI * 4 / 5 * n + a) * r + y );
22 
23 }
24 
25 fillpoly(5, pt);
26 
27 }
28 
29  
30 
31 int main()
32 
33 {
34 
35 initgraph( 640, 480 );
36 
37 setcolor( RGB(0xff, 0xff, 0xff) );
38 
39 setfillcolor( RGB(0, 0, 0xff) );
40 
41 setrendermode(RENDER_MANUAL);
42 
43 double r = 0;
44 
45 for ( ; is_run(); delay_fps(60) )
46 
47 {
48 
49 r += 0.02;
50 
51 if (r > PI * 2) r -= PI * 2;
52 
53  
54 
55 cleardevice();
56 
57 paintstar(300, 200, 100, r);
58 
59 }
60 
61 return 0;
62 
63 }

 

然后在命令行中输入:

g++ main.cpp -o main -g -w -lgraphics -lgdi32 -limm32 -lmsimg32 -lole32 -loleaut32 -lwinmm -luuid –mwindows

若出现 "note: attribute for 'struct ege::MOUSEMSG' must follow the 'struct' keyword struct MOUSEMSG {" 提示,不用理会即可.

然后运行生成的main.exe程序,那么就会出现一个旋转的五角星,如下:

 

看起来还不错吧!

图形库的API文件在man文件夹下面有,自己看着学习就可以了!

另外还有一个类似的图形库,叫做EasyX,主页是: http://www.easyx.cn/,也不错,支持VC系列,不支持MingW,也不开源,由于我不怎么使用IDE进行编程,所以我就选择了使用EDE,EDE开源,这个真心很赞.

 

稍后我会将配置好的MingW发布到百度云,上传完后具体地址会发布到这里,http://www.cnblogs.com/killerlegend/p/3821416.html,解压密码KillerLegend.

posted @ 2014-08-30 19:43  KillerLegend  Views(2085)  Comments(0Edit  收藏  举报