在win32下使用clutter-1.0进行2.5D桌面开发[1026]

转载请注明出处 blog.csdn.net/pingf0 或 www.cnblogs.com/pingf


 clutter是个很不错的库,也正因为有了它,Intel的moblin才显得有点光彩【个人愚见,吼吼】

  官方并没有给出很详尽的在win32下使用clutter的方法,毕竟要推moblin嘛。。。XD,仿佛在说我用linux我骄傲一般。

  但还是有些喜欢hacking的老外爱想点法子,将它移植到了了win32平台上。

  下面的文章,除了做点翻译之外,还有一些自己的总结,使之更为易懂易用

  STEP 1

   基本配置,我对微软似乎是有些反感的,所以本文只讲基于mingw的方法,而不提msvc的。。。。。。吼吼

   首先要做的就是将mingw装上【需要额外装下libiconv,需要调试肯定要装高蛋白(GDB)的】,还有glib相关的一些库,什么gio 啦,gobject啦。。。。。太多,太碎,怕麻烦的可以直接状glade套件或者gtk+的all in one bundle!

    所有这些都可从sourceforge.net下载

    当然要下载clutter的源码包【本文介绍的适用于1.0.X各个版本,也是目前(09.10.26)最稳定版本】,可从clutter-project.org下载

   顺带把qt套件给装上,主要是用到那个qmake,比automake用起来方便不少。[这个从nokia网站下载]

   STEP 2

     将MINGW中include\GL下glext.h更换为http://www.opengl.org/registry/api/glext.h ,据说是因为自带的太旧的原因。

   STEP 3

     在说下面之前说明下我装的是glade套件,对应目录C:\GTK+,所以下面的一些修改也是针对此的

     下载如下7zip包

      http://files.cnblogs.com/pingf/prebuild.7z

     然后将该prebuild文件夹放在clutter源码包build目录下,并修改configure.pl中

     local $GLIB_DIR = Cwd::realpath("$HOME_DIR/glib-2.18.4");一行修改为

     local $GLIB_DIR = Cwd::realpath("C:/GTK+");

     然后运行那个批处理,运行完后看提示,要修改pro文件中

    ..\..\clutter\cogl\gl\cogl-primitives.c \
    以及
    ..\..\clutter\cogl\gl\cogl.c \

     两行前面各加个#号

     并将pro文件中

    CAIRO_DIR = ..\..\..\cairo_1.8.6
    GLIB_DIR = ..\..\..\glib-2.18.4
    CLUTTER_DIR = ..\..
    PANGO_DIR = ..\..\..\pango-1.22.4
    GETTEXT_DIR = ..\..\..\mingw32-gettext-0.17

    修改为

    CAIRO_DIR = C:\GTK+
    GLIB_DIR = C:\GTK+
    CLUTTER_DIR = ..\..
    PANGO_DIR = C:\GTK+
    GETTEXT_DIR = C:\GTK+

     然后cmd下【当前目录】先qmake 再 make

     然后就会产生libclutter.a文件啦,这个是静态的哟!

    step 4

    整理下.h文件【这步我就不说了】,

    为了省事儿

    我将编译的头文件放在C:\Gtk+\lib\clutter-1.0

    将整理的头文件放在C:\Gtk+\include\clutter-1.0

    step 5

    然后就是运行你的程序了

    gcc怎么用我是不会在此赘述的,但很有必要说一下一些标志为的设置

    cflags设置为

-g -Wall  -Ic:\gtk+\include\glib-2.0 -Ic:\gtk+\lib\glib-2.0\include -Ic:\gtk+\include  
-Ic:\gtk+\include\cairo  -Ic:\gtk+\include\pango-1.0  
-Ic:\gtk+\include\clutter-1.0 -Ic:\gtk+\include\clutter-1.0\clutter
     libs 设置为
 
   
c:\gtk+\lib\clutter-1.0\libclutter.a c:\gtk+\lib\glib-2.0.lib c:\gtk+\lib\gobject-2.0.lib 

c:\gtk+\lib\gmodule-2.0.lib c:\gtk+\lib\gthread-2.0.lib c:\gtk+\lib\pango-1.0.lib 

c:\gtk+\lib\pangocairo-1.0.lib c:\gtk+\lib\cairo.lib c:\gtk+\lib\libintl.dll.a 

-lopengl32 -lglu32 -lgdi32 -luser32 -lwinmm


     连接附加选项

-mwindows  -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl, -mthreads -Wl
     step  6
下面给出经典的clutter下开罗花的程序
ContractedBlock.gif ExpandedBlockStart.gif Code
   1/* 
   2.  * Pretty cairo flower hack. 
   3.  
*/  
   
4.   
   
5. #include <clutter/clutter.h>  
   
6.   
   
7. #ifndef _MSC_VER  
   
8. #include <unistd.h>       /* for sleep(), used for screenshots */  
   
9#endif  
  
10. #include <stdlib.h>  
  
11. #ifdef _MSC_VER  
  
12#define _USE_MATH_DEFINES  
  
13#endif  
  
14. #include <math.h>  
  
15.   
  
16#define PETAL_MIN 20  
  
17#define PETAL_VAR 40  
  
18#define N_FLOWERS 40 /* reduce if you have a small card */  
  
19.   
  
20. typedef struct Flower  
  
21. {  
  
22.   ClutterActor *ctex;  
  
23.   gint          x,y,rot,v,rv;  
  
24. }  
  
25. Flower;  
  
26.   
  
27. ClutterActor*  
  
28. make_flower_actor (void)  
  
29. {  
  
30.   /* No science here, just a hack from toying */  
  
31.   gint i, j;  
  
32.   
  
33.   double colors[] = {  
  
34.     0.710.810.83,  
  
35.     1.0,  0.780.57,  
  
36.     0.640.300.35,  
  
37.     0.730.400.39,  
  
38.     0.910.560.64,  
  
39.     0.700.470.45,  
  
40.     0.920.750.60,  
  
41.     0.820.860.85,  
  
42.     0.510.560.67,  
  
43.     1.00.790.58,  
  
44.   
  
45.   };  
  
46.   
  
47.   gint size;  
  
48.   gint petal_size;  
  
49.   gint n_groups;    /* Num groups of petals 1-3 */  
  
50.   gint n_petals;    /* num of petals 4 - 8  */  
  
51.   gint pm1, pm2;  
  
52.   
  
53.   gint idx, last_idx = -1;  
  
54.   
  
55.   ClutterActor *ctex;  
  
56.   cairo_t      *cr;  
  
57.   
  
58.   petal_size = PETAL_MIN + rand() % PETAL_VAR;  
  
59.   size = petal_size * 8;  
  
60.   
  
61.   n_groups = rand() % 3 + 1;  
  
62.   
  
63.   ctex = clutter_cairo_texture_new (size, size);  
  
64.   
  
65.   cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (ctex));  
  
66.   
  
67.   cairo_set_tolerance (cr, 0.1);  
  
68.   
  
69.   /* Clear */  
  
70.   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);  
  
71.   cairo_paint(cr);  
  
72.   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);  
  
73.   
  
74.   cairo_translate(cr, size/2, size/2);  
  
75.   
  
76.   for (i=0; i<n_groups; i++)  
  
77.     {  
  
78.       n_petals = rand() % 5 + 4;  
  
79.       cairo_save (cr);  
  
80.   
  
81.       cairo_rotate (cr, rand() % 6);  
  
82.   
  
83.       do {  
  
84.     idx = (rand() % (sizeof (colors) / sizeof (double/ 3)) * 3;  
  
85.       } while (idx == last_idx);  
  
86.   
  
87.       cairo_set_source_rgba (cr, colors[idx], colors[idx+1],  
  
88.                  colors[idx+2], 0.5);  
  
89.   
  
90.       last_idx = idx;  
  
91.   
  
92.       /* some bezier randomness */  
  
93.       pm1 = rand() % 20;  
  
94.       pm2 = rand() % 4;  
  
95.   
  
96.       for (j=1; j<n_petals+1; j++)  
  
97.     {  
  
98.       cairo_save (cr);  
  
99.       cairo_rotate (cr, ((2*M_PI)/n_petals)*j);  
 
100.   
 
101.       /* Petals are made up beziers */  
 
102.       cairo_new_path (cr);  
 
103.       cairo_move_to (cr, 00);  
 
104.       cairo_rel_curve_to (cr,  
 
105.                   petal_size, petal_size,  
 
106.                   (pm2+2)*petal_size, petal_size,  
 
107.                   (2*petal_size) + pm1, 0);  
 
108.       cairo_rel_curve_to (cr,  
 
109.                   0 + (pm2*petal_size), -petal_size,  
 
110.                   -petal_size, -petal_size,  
 
111.                   -((2*petal_size) + pm1), 0);  
 
112.       cairo_close_path (cr);  
 
113.       cairo_fill (cr);  
 
114.       cairo_restore (cr);  
 
115.     }  
 
116.   
 
117.       petal_size -= rand() % (size/8);  
 
118.   
 
119.       cairo_restore (cr);  
 
120.     }  
 
121.   
 
122.   /* Finally draw flower center */  
 
123.   do {  
 
124.       idx = (rand() % (sizeof (colors) / sizeof (double/ 3)) * 3;  
 
125.   } while (idx == last_idx);  
 
126.   
 
127.   if (petal_size < 0)  
 
128.     petal_size = rand() % 10;  
 
129.   
 
130.   cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5);  
 
131.   
 
132.   cairo_arc(cr, 00, petal_size, 0, M_PI * 2);  
 
133.   cairo_fill(cr);  
 
134.   
 
135.   cairo_destroy(cr);  
 
136.   
 
137.   return ctex;  
 
138. }  
 
139.   
 
140. gboolean  
 
141. tick (gpointer data)  
 
142. {  
 
143.   Flower **flowers = (Flower**)data;  
 
144.   gint i = 0;  
 
145.   
 
146.   for (i=0; i< N_FLOWERS; i++)  
 
147.     {  
 
148.       flowers[i]->y   += flowers[i]->v;  
 
149.       flowers[i]->rot += flowers[i]->rv;  
 
150.   
 
151.       if (flowers[i]->> (gint)clutter_actor_get_height  
 
152.                             (clutter_stage_get_default ()))  
 
153.         flowers[i]->= -clutter_actor_get_height (flowers[i]->ctex);  
 
154.   
 
155.       clutter_actor_set_position (flowers[i]->ctex,  
 
156.                   flowers[i]->x, flowers[i]->y);  
 
157.   
 
158.       clutter_actor_set_rotation (flowers[i]->ctex,  
 
159.                                   CLUTTER_Z_AXIS,  
 
160.                                   flowers[i]->rot,  
 
161.                                   clutter_actor_get_width (flowers[i]->ctex)/2,  
 
162.                                   clutter_actor_get_height (flowers[i]->ctex)/2,  
 
163.                                   0);  
 
164.     }  
 
165.   
 
166.   return TRUE;  
 
167. }  
 
168.   
 
169void foo(void) { g_usleep(10000000); }  
 
170.   
 
171int  
 
172. main (int argc, char **argv)  
 
173. {  
 
174.   int           i;  
 
175.   ClutterActor *stage;  
 
176.   ClutterColor  stage_color = { 0x00x00x00xff };  
 
177.   Flower       *flowers[N_FLOWERS];  
 
178.   
 
179.   srand (time (NULL));  
 
180.   
 
181.   clutter_init (&argc, &argv);  
 
182.   
 
183.   stage = clutter_stage_get_default ();  
 
184.   
 
185.   clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);  
 
186.  // clutter_stage_set_fullscreen (CLUTTER_STAGE (stage), TRUE);  
 187.   
 
188.   for (i=0; i< N_FLOWERS; i++)  
 
189.     {  
 
190.       flowers[i]       = g_new0(Flower, 1);  
 
191.       flowers[i]->ctex = make_flower_actor();  
 
192.       flowers[i]->x    = rand() % (int) clutter_actor_get_width (stage)  
 
193.                        - (PETAL_MIN + PETAL_VAR) * 2;  
 
194.       flowers[i]->y    = rand() % (int) clutter_actor_get_height (stage);  
 
195.       flowers[i]->rv   = rand() % 5 + 1;  
 
196.       flowers[i]->v    = rand() % 10 + 2;  
 
197.   
 
198.       clutter_container_add_actor (CLUTTER_CONTAINER (stage),  
 
199.                                    flowers[i]->ctex);  
 
200.       clutter_actor_set_position (flowers[i]->ctex,  
 
201.                   flowers[i]->x, flowers[i]->y);  
 
202.     }  
 
203.   
 
204.   g_timeout_add (50, tick, flowers);  
 
205.   
 
206.   clutter_actor_show (stage);  
 
207.   
 
208.   g_signal_connect (stage, "key-press-event",  
 
209.             G_CALLBACK (clutter_main_quit),  
 
210.             NULL);  
 
211.   
 
212.   clutter_main();  
 
213.   
 
214.   return EXIT_SUCCESS;  
 
215. }  


o(∩_∩)o...哈哈,至此在win下也可以用clutter进行开发啦!!!


转载于:https://www.cnblogs.com/pingf/archive/2009/10/27/1590419.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值