Grab mouse using OpenGL

I am making a game and I want to grab the mouse using OpenGL. How could I do this?

1 Like

Please explain what you mean by grab

Essentially look at screenX in the reference

in LWJGL 2, there is a function in the Mouse class named setGrabbed(). I want similar functionality like that.

I actually meant “Hide and constrain mouse cursor inside the window”

reference for setGrabbed() function in LWJGL 2: Mouse (LWJGL API)

See the link at Is there mouse locking in processing? - #4 by neilcsmith and if you’re using OpenGL, make sure to use the JOGL version near the bottom of the post.

1 Like

I am using P3D mode.

1 Like

Yes, it wasn’t meant as a question! :laughing: Just ignore the bit about Robot - it’s better to do this directly with the JOGL classes.

2 Likes

it didn’t work :frowning:

This works for me on Ubuntu -

import com.jogamp.newt.opengl.GLWindow;

void setup() {
 size(640,480,P3D);
 background(0);
 GLWindow window = (GLWindow)surface.getNative();
 window.confinePointer(true);
 window.setPointerVisible(false);
}

void draw() {
 stroke(255);
 line(pmouseX, pmouseY, mouseX, mouseY);
}

Added draw() or pressing ESCAPE to close the window doesn’t work, and it’s useful to see where the mouse is.

1 Like

Ok! I don’t need it! somehow i managed to edit queasycam code to make cursor trap inside the window! it works fine now! now how do i close this question?

No need to close the question - just leave it here.

1 Like