Mouse and Screen Bounds

Howzit

How do I keep the mouse within the bounds of the screen when I am in full screen.

What I’ve done is attached a image onto the co-ordinates of the mouse so I can see where it is. But if I carry on moving the mouse say for example left it goes out of the screen. It doesn’t just say at the edge.

How do I fix this.

Are you using the hardware mouse feature, or tracking and rendering your own mouse pointer?

Cas :slight_smile:

Just clamp the mouse coordinates to the size of the window.


// mousex, mousey is the coordinate of the mouse cursor on screen
Mouse.poll();
mousex = Math.min(windowWidth, Math.max(0, mousex+Mouse.dx));
mousey = Math.min(windowHeight, Math.max(0, y-Mouse.dy));

You can get the bounds of the window by using GL.glGetInteger(GL.GL_VIEWPORT, intBufferWith4Elements);