Hiding mouse cursor

Hey, I have a problem.
I might use

Mouse.setGrabbed(true);

which is fine, but in the case where I want to be able to use the mouse outside the window:


Cursor emptyCursor = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null);
Mouse.setNativeCursor(emptyCursor);

taken from http://lwjgl.org/forum/index.php?topic=594.0

This doesn’t actually completely hide the cursor. It creates a 1x1 BLACK pixel cursor.
I have tried to create an int buffer that contains a single integer with no alpha (eg new Color(0,0,0,0).getRGB()), this doesn’t work.

Anyone have any ideas?

Use your own 1x1 transparent texture?

Here is the code I use:

... in loop ...
if (emptyCursor==null && Mouse.isCreated() && Mouse.isInsideWindow()) {
        int min = Cursor.getMinCursorSize();
        IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
        emptyCursor = new Cursor(min, min, min/2, min/2, 1, tmp, null);
        Mouse.setNativeCursor(emptyCursor);
}

Some systems may not support transparency. You can check for the cursor’s capabilities like so:

System.out.println( "1 bit transparency? "+
     ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARANCY) 
     == Cursor.CURSOR_ONE_BIT_TRANSPARANCY) );
System.out.println( "8 bit transparency? "+
     ((Cursor.getCapabilities() & Cursor. CURSOR_8_BIT_ALPHA) 
     == Cursor.CURSOR_8_BIT_ALPHA) );

Thanks davedes! it works perfectly :slight_smile: