GLCanvas's mouseDragged problem

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

GLCanvas's mouseDragged problem

JimmyCai
Hi,
I am writing a program of drawing lines. In init method of GLEventListener, I add a mouesMotionListener to GLCanvas, in mouseDragged method of mouseMotionListener, I add Points to my lines, but I find that the mouseDragged method picks up points slowly, if I drag mouse quickly, it did't pick up enough points. is it triggering mouseDragged event at set intervals? if so, can I change the interval time? Or what should I do?

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

gouessej
Administrator
Hi

You have to compute the points yourself between two successive calls to mouseDragged(MouseEvent). If you want a better frame rate and less trouble, disable v-sync and use NEWT but if it doesn't allow you to get more events, it won't solve your problem.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

JimmyCai
Hi

Thank you for your answer first.

I want to hava a try, because it's not easy to guess and compute the points between two successive calls to mouseDragged(MouseEvent).

How to disable v-sync? and what is NEWT?
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

gouessej
Administrator
If the interval is quite small, you just have to compute the points along the line between the previous point and the current point with a discretization step, it is not difficult.

Look at GL.setSwapInterval() to modify v-sync. NEWT is the native windowing toolkit of JOGL 2.0. I think it wouldn't really solve your problem because you wouldn't get something continuous anyway.

Edit.: You might obtain a more accurate result with v-sync disabled and by getting your point directly in display(GLAutoDrawable). Use java.awt.MouseInfo.getPointerInfo().getLocation() but if AWT doesn't update it more often than with mouseDragged, it won't solve your problem.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

Sven Gothel
Administrator
On 03/12/2013 03:10 PM, gouessej [via jogamp] wrote:
> If the interval is quite small, you just have to compute the points along the
> line between the previous point and the current point with a discretization
> step, it is not difficult.
>
> Look at GL.setSwapInterval() to modify v-sync. NEWT is the native windowing
> toolkit of JOGL 2.0. I think it wouldn't really solve your problem because you
> wouldn't get something continuous anyway.

vsync is unrelated to the granularity of mouse dragged events.

actually granularity of all input events are platform dependent,
i.e. they are being created by the native toolkit (X11, GDI, ..)
and forwarded to NEWT .. AWT .. etc.

~Sven



signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

gouessej
Administrator
I find no obvious way of getting "more" events even with JInput.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

JimmyCai
In reply to this post by gouessej
Thanks for reply.

I hava found the problem why the interval between MouseDragged(MouseMotionListener) in my GLCanvas is a litter longer than normal JInput. because I call some GPU codes in display(GLAutoDrawable) method. I will find a way to slove my problem.

Thanks again.
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

gouessej
Administrator
You won't have something perfectly continuous even in plain AWT especially on very fast movements during freehand drawing, keep it in mind.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas's mouseDragged problem

JimmyCai
Thanks。

Now, I hava a new problem, can I draw some lines or other things after gl.glDrawPixels().

I try as below, but it did't work.

                gl.glDrawPixels(tex.getWidth(), tex.getHeight(), GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, tex.getByteBuffer());
               
                gl.glColor3f(0.0f, 1.0f, 0.0f);
                gl.glBegin(GL2.GL_QUADS);
                gl.glVertex2f(-1.0f, -1.0f);
                gl.glVertex2f(-1.0f, 1.0f);
                gl.glVertex2f(1.0f, 1.0f);
                gl.glVertex2f(1.0f, -1.0f);
                gl.glEnd();