bitmap - Double Buffering with vsync (in sync with refresh rate of screen) - C# windows forms -


i've been trying update bmp of picturebox 60 times per second line pattern changes every update. what's happening image being partially updated in between screen refreshes. so, see part of 1 pattern , part of next. need update precisely once every screen refresh. ideally, goal update buffer , copy front buffer. i've heard can use vsync in games lock front buffer such screen updated right after screen refreshes. if take advantage of locking, allow me precisely updated once per refresh. haven't been able figure out how yet.

any ideas?

i did try using doublebuffering = true property in windows forms. might not work picturebox. used copymemory (a native dll call) copy new pattern bitmap in picturebox.

i tried use writeablebitmap same technique in last paragraph, reason buffer never copied front buffer, though did way other people suggested on stack exchange. tried couple hours or so. image never updated on screen technique.

i found solution own question. best way create xna 2d application. forced vsync in graphics card settings. turned property on in xna application. in game constructor, used this: this.isfixedtimestep = true;

public game1() {     this.isfixedtimestep = true;     this.targetelapsedtime = new timespan(0, 0, 0, 0, 1000 / 60);//60 times per second     graphics = new graphicsdevicemanager(this)     {         preferredbackbufferwidth = 800,         preferredbackbufferheight = 600,         synchronizewithverticalretrace = true,     };      graphics.applychanges();     content.rootdirectory = "content"; } 

then declare global variable: bool _isdirty = true; , declare following functions:

protected override bool begindraw() {     if (_isdirty)     {         _isdirty = false;         base.begindraw();         return true;     }     else         return false; } protected override void enddraw() {     if (!_isdirty)     {         base.enddraw();         _isdirty = true;     } }  protected override void draw(gametime gametime) {     //graphics.graphicsdevice.clear(color.black);      // draw sprite.     spritebatch.begin();     spritebatch.draw(textureimg, new rectangle(0, 0, 800, 600), color.white);     spritebatch.end();     base.draw(gametime); } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -