Re: Animation in GTK



CyborgHead netscape net wrote:

> Hi
> I am writing a game and have to use GTK. THe game is similar to Robot Battle for Windows (www.RobotBattle.com) On screen there are up to 6 tanks, numerous bullets, mines and health kits. The graphics are very simple, looking from above. > I tried numerous ways to program the simple amimation needed to represent the battle between the robots. My first was was as follows
>
> //Colour Background
> gdk_gc_set_foreground( plot_gc , color + 0 ); > gdk_draw_polygon( GTK_WIDGET(work_area)->window, plot_gc, fillin, map_vertices, 4);
> //Color Tank
> gdk_gc_set_foreground( plot_gc , color + 2 );
> gdk_draw_polygon( GTK_WIDGET(work_area)->window, plot_gc, fillin, tank, 4);
> //Color Gun
> gdk_gc_set_foreground( plot_gc , color + 3 );
> gdk_draw_polygon( GTK_WIDGET(work_area)->window, plot_gc, TRUE, gun, 4);
> > //Draw Wheels
> gdk_gc_set_foreground( plot_gc , color + 1 );
> gdk_draw_polygon( GTK_WIDGET(work_area)->window, plot_gc, TRUE, wheel1,4);
> gdk_gc_set_foreground( plot_gc , color + 1 );
> gdk_draw_polygon( GTK_WIDGET(work_area)->window, plot_gc, TRUE,wheel2,4);
> gdk_colormap_free_colors( colormap, color, 4 );
>
> This doesn't work, it flickers continully.
> I then tried to place the onscreen image in a pixmap, but this is to slow. I think that pixmaps are only supposed to be used for static images, not realtime movement. The position if the tanks is updated many times a second by a idle function.
>
> Does anyone know how to get smooth fast animation using GTK. It does not have to look great, just once you can see what is going on.

I'd suggest using OpenGL, since it's

a) A simple, clean API.
b) Your code will be portable to other platforms / toolkits.
c) OpenGL's transformations will simplify your code significantly -
drawing the tanks and their turrets at different angles becomes trivial.
d) Easily double-buffered.

Incorporating OpenGL in a GTK+ program is easy - try using GtkGLArea or
the SDPGTK library (www.k-3d.com).

Tim Shead





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]