I have been trying to create a custom mouse cursor in my LWJGL2 application running under Linux and I am almost there. I have implemented the following method that I call right after creating the game window:
public void loadCursor(BufferedImage img) throws LWJGLException
{
final int w = img.getWidth();
final int h = img.getHeight();
int rgbData[] = new int[w * h];
for (int i = 0; i < rgbData.length; i++)
{
int x = i % w;
int y = h - 1 - i / w; // this will also flip the image vertically
rgbData[i] = img.getRGB(x, y);
}
IntBuffer buffer = BufferUtils.createIntBuffer(w * h);
buffer.put(rgbData);
buffer.rewind();
Cursor cursor = new Cursor(w, h, 2, h - 2, 1, buffer, null);
Mouse.setNativeCursor(cursor);
}
The resulting cursor is almost perfect, except for a horizontal blank line in the middle.
Note: The image is being flipped vertically in my code because otherwise the cursor is displayed upside down in OpenGL. I have seen other implementations that flip the IntBuffer instead of doing this in the for-loop but they lead to the same result for me.
I don't think it has to do with screen tearing either since I enabled VSync and the blank line is always at 50% of the cursor's height (there is no flickering).
Can anybody tell what I am doing wrong or if my code example is missing something essential in order to find the problem? Thank you!