Jump to content
  • Advertisement
Sign in to follow this  

How do you get rid of "drag lag" in 2D graphics with Cairo.

This topic is 1041 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



I am creating a quite-complex app using GtkD and the D programming language.


When you are moving a 2D graphics item with the mouse, there's a noticeable lag between the intermediately-rendered 2D graphics and the current mouse position.


I have an onMouseMove event handler that does something like:

onMouseMove {
     delta = currMousePos - lastMousePos;
     foreach (obj; freeObjs) {
     queueRedraw(boxList /*calculated above*/);

I queue the redraws (only effected boxes during a move) using:

queuRedraw(boxList) { 
   // calls gtk.DrawingArea.queueDrawArea

The draw callback looks like:

drawCallback() {
     // Draw effected geometry in AABBTree
     // Draw freeObjs

The problem is occuring because too many redraws are accumulating.    How do I limit the redraws or somehow only redraw the free objects at the current mouse pos?   I've tried many things and all have worse performance than the current set up or are buggy.


I've tried incrementing a redrawQCounter variable upon queuing and decrementing upon redraw, but it seems to grow and not converge back to zero.


I've tried playing with the time derivative of the mouse position as well, and failed.


Any ideas?  My next guess is my own queueing function that queues a redraw only when (WHAT? Idk...).


Thank you, Graphics Programming Gods!


If you have VisualD running and GtkD installed I can send you the source code.



Edited by EnjoysMath

Share this post

Link to post
Share on other sites

This little snippet seems to have reduced the number of draws when moving many objects:


I have my own queueDrawRect() function with a Rect[] drawQueue;   Whenever the queue gets full really quickly, I set its size back to zero and only draw the first and last.  Seems to work, though there's not an improvement when moving single objects.


Perhaps I should've used a list over my own AABBTree structure biggrin.png


(See attached photo)

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!