Jump to content
  • Advertisement
Sign in to follow this  
capn_midnight

[.net] Double Buffering in GDI+

This topic is 4877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there class level support for double buffering in GDI+? I'm currently getting a graphics object from a bitmap, painting to that, and then painting the bitmap to the screen with the screen's graphics object, so it sort of suffices, but I'd like something a little more official. For example, in Java there is the BufferStrategy object, and you can create BufferStrategies (which also happen to be hardware accelerated) for any object below a comman java.awt.Window in the hiearchy. Just wondering if there is something similar for GDI+ (as so far GDI+ is pretty much a method-for-method copy of Java2D, which is okay with me).

Share this post


Link to post
Share on other sites
Advertisement
On the form properties, scroll down to "Double Buffer = false" and simply set it to true. Double buffering is now in session, and you don't have to do anything else to make it happen. You don't have to draw to the double buffer, for example. It does it for you.

Share this post


Link to post
Share on other sites
uhmm, that wouldn't be .net 2.0, would it? I'm using .net 1.1 and I don't see it anywhere.

[Edited by - capn_midnight on July 31, 2005 3:10:06 PM]

Share this post


Link to post
Share on other sites
In your control/form's constructor put the following code:


SetStyle( ControlStyles.UserPaint, true );
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
SetStyle( ControlStyles.DoubleBuffer, true );



Then do your drawing in an overriden OnPaint() method. If you need to constantly redraw, call Invalidate() at the end of OnPaint().

Share this post


Link to post
Share on other sites
Or (to constantly redraw) call Invalidate() from a Timer object to lock the framerate.

I was also looking for GDI+ double buffering techniques just before I noticed this thread.

Thanks guys.

Share this post


Link to post
Share on other sites
If you're using a standard control, you can set DoubleBuffered = true from a derived class (it's a protected property).

Share this post


Link to post
Share on other sites
Quote:
Original post by CSharp_Padawan
Or (to constantly redraw) call Invalidate() from a Timer object to lock the framerate.

I was also looking for GDI+ double buffering techniques just before I noticed this thread.

Thanks guys.


Does anyone know what happens if the system can't keep up and the timer event is executing faster than the paint function?

Share this post


Link to post
Share on other sites
Quote:
Original post by jystic
Quote:
Original post by CSharp_Padawan
Or (to constantly redraw) call Invalidate() from a Timer object to lock the framerate.

I was also looking for GDI+ double buffering techniques just before I noticed this thread.

Thanks guys.


Does anyone know what happens if the system can't keep up and the timer event is executing faster than the paint function?

then you'll only see everything at the paint method's rate. Without dobule buffering, you see a defect called tearing, in which half of the next frame is partially covering the current frame.

Share this post


Link to post
Share on other sites
Also, don't forget to call Updatestyles (well it said that on teh intranet)


Setstyle(Controlstyles.DoubleBuffer | Controlstyles.UserPaint | Controlstyles.AllPaintingInWmPaint, true);
Updatestyles();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!