Hello Guest

Cursor problem

  • 2 Replies
  • 7763 Views
Cursor problem
« on: October 27, 2003, 19:33:05 »
Hi!

I started playing around with the mouse in lwjgl and got a visible cursor on the screen.
My problem is that the cursor's image is somehow turned 90 degrees counter-clockwise,
while creating the Cursor.

I'll put the code where I create it.

Code: [Select]

  private final static void createCursor() {
Image image = (new javax.swing.ImageIcon("cursor.png")).getImage();
 
// Exctract The Image
BufferedImage tex =
 new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)tex.getGraphics();
g.drawImage(image, null, null);
g.dispose();

// Put Image In Memory
IntBuffer scratch =
IntBuffer.allocate(4 * tex.getWidth() * tex.getHeight());
                                                                               
int data[] =
(int[]) tex.getRaster().getDataElements(
0,
0,
tex.getWidth(),
tex.getHeight(),
null);
scratch.clear();
scratch.put(data);
scratch.rewind();
 
try {
cursor = new Cursor(tex.getWidth(), tex.getHeight(), 0, tex.getHeight(), 1,
scratch, null);
Mouse.setNativeCursor(cursor);
} catch(Exception e) {
System.err.println("Could not create cursor.");
}
  }


Any ideas how I could get it the cursor's image to point to the right direction?

O.

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Cursor problem
« Reply #1 on: October 28, 2003, 08:36:07 »
The cursor image data has the origin like OpenGL, that is, in the lower left corner. Image formats in general use the upper left corner as the origin, and if that's the case with your image data, you just have to swap all the image rows, so row number 0 becomes row number imageheight - 1, row 1 becomes row imageheight - 2 etc.

 - elias

Cursor problem
« Reply #2 on: October 28, 2003, 14:15:02 »
+ as a quick fix you could just prepend a .rotate(Math.PI/2) before your drawImage (not tested - but should work?) :)