[prev in list] [next in list] [prev in thread] [next in thread]
List: gtkmm
Subject: Re: the right way to draw in a drawingarea
From: Rob Benton <rob.benton () conwaycorp ! net>
Date: 2005-10-22 18:06:22
Message-ID: 435A9091.6070206 () conwaycorp ! net
[Download RAW message or body]
Paul Davis wrote:
> Foster, Gareth wrote:
>
>>> the display flickers, even when drawing a simple square.
>>>
>>>
>>
>>
>> Doesn't this often mean you need to be double buffering?
>> _______________________________________________
>> gtkmm-list mailing list
>> gtkmm-list@gnome.org
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>>
> This is a point I am completely unsure about. I haven't the foggiest on
> Gtk internals and the ramifications of a simple call such as
> draw_rectangle. I've used double buffering in both OpenGL and Java.
> I've just never really seen any real reference to it in gtk. Now that
> I've had a couple beers, I seem to rememeber some reference to getting
> an offscreen graphics context, drawing to that, and then switching the
> main gc with it back and forth. But I could be completely making that
> up. ( the beer )
>
> Double buffering isn't really that hard of a concept. I'm just not sure
> of if its needed. Because its more than possible that gtk has its own
> buffering scheme burried somewhere. I've actually written a couple
> programs to animate image data using Gtkmm. I've never had a problem
> with flickering that wasn't because I was doing something silly like
> clearing and then redrawing. So the answer is I dunno. Its possible.
> If I get time I'll write a test program to try and play with the idea.
>
> And if I had thought to take a moment to google something as silly as
> gtkmm double buffering, I would have noticed that the gtkmm docs specify
> that widgets are double buffered by default. In which case, no double
> buffering will not solve this problem cause its already being done.
> Which goes to show that yes, I was making up the graphics context
> thing. Must be something from java I was thinking of.
> http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#a175
>
>
> In other news, Unleashed wasn't half bad if anyone cares.
>
> Cheers,
> Paul
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>
In my experience you always need double-buffering when you draw to a
Gtk::DrawingArea. I have not seen that
Gtk::Widget::set_double_buffered() function before. But you are not
drawing directly to the Gtk::DrawingArea. Instead you are drawing to a
Gdk::Drawable such as a pixmap. Here's how I do it in my code:
bool my_expose_event(GdkEventExpose * e)
{
Glib::RefPtr<Gdk::Window> window = _drawarea.get_window();
_pixmap->draw_rectangle(_gc, true, 0, 0, size, size);
window->draw_drawable(_gc, _pixmap, e->area.x, e->area.y, e->area.x,
e->area.y, e->area.width, e->area.height);
return true;
}
And I can't speak for Unleashed but Shadow of the Colossus is pretty
awesome. :)
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic