use of org.lwjgl.input.Cursor in project Voxel_Game by ASasseCreations.
the class MouseSystem method getCursor.
public static final Cursor getCursor(final BufferedImage img) throws LWJGLException {
final int w = img.getWidth();
final int h = img.getHeight();
final int[] rgbData = new int[w * h];
for (int i = 0; i < rgbData.length; i++) {
final int x = i % w;
final int y = h - 1 - i / w;
rgbData[i] = img.getRGB(x, y);
}
final IntBuffer buffer = BufferUtils.createIntBuffer(w * h);
buffer.put(rgbData);
buffer.rewind();
return new Cursor(w, h, 0, h - 1, 1, buffer, null);
}
use of org.lwjgl.input.Cursor in project Catacomb-Snatch by Catacomb-Snatch.
the class DesktopLauncher method main.
public static void main(String[] arg) {
System.out.println("Starting game in DESKTOP mode!");
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
// TODO Re-enable if it got fixed on all systems (currently throws a shader error)
// config.useGL30 = true;
config.title = "Catacomb Snatch";
config.width = GAME_WIDTH;
config.height = GAME_HEIGHT;
new LwjglApplication(new CatacombSnatch(new PlatformDependent() {
@Override
public void create() {
// Set game cursor
try {
int size = 16, center = (size / 2);
IntBuffer buffer = BufferUtils.newIntBuffer(size * size);
int x = 0, y = 0;
for (int n = 0; n < buffer.limit(); n++) {
if ((x == center || y == center) && (x < center - 1 || y < center - 1 || x > center + 1 || y > center + 1)) {
buffer = buffer.put(n, 0xFFFFFFFF);
}
x++;
if (x == size) {
x = 0;
y++;
}
}
Mouse.setNativeCursor(new Cursor(size, size, center, center, 1, buffer, null));
} catch (LWJGLException e) {
System.err.print("Error setting native cursor!\n" + e);
}
}
@Override
public Object[] createPlatformObjects() {
throw new UnsupportedOperationException("Unimplemented");
}
@Override
public void dispose() {
}
}), config);
}
use of org.lwjgl.input.Cursor in project jmonkeyengine by jMonkeyEngine.
the class LwjglMouseInput method setNativeCursor.
public void setNativeCursor(JmeCursor jmeCursor) {
try {
Cursor newCursor = null;
if (jmeCursor != null) {
newCursor = cursorMap.get(jmeCursor);
if (newCursor == null) {
newCursor = new Cursor(jmeCursor.getWidth(), jmeCursor.getHeight(), jmeCursor.getXHotSpot(), jmeCursor.getYHotSpot(), jmeCursor.getNumImages(), jmeCursor.getImagesData(), jmeCursor.getImagesDelay());
// Add to cache
cursorMap.put(jmeCursor, newCursor);
}
}
Mouse.setNativeCursor(newCursor);
} catch (LWJGLException ex) {
Logger.getLogger(LwjglMouseInput.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.lwjgl.input.Cursor in project jmonkeyengine by jMonkeyEngine.
the class LwjglMouseInput method destroy.
public void destroy() {
if (!context.isRenderable())
return;
Mouse.destroy();
// Destroy the cursor cache
for (Cursor cursor : cursorMap.values()) {
cursor.destroy();
}
cursorMap.clear();
logger.fine("Mouse destroyed.");
}
use of org.lwjgl.input.Cursor in project lwjgl by LWJGL.
the class HWCursorTest method processKeyboard.
/**
* Processes keyboard input
*/
private void processKeyboard() {
//check for fullscreen key
if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
try {
try {
Mouse.setNativeCursor(null);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
for (Cursor aCursor : cursors) {
aCursor.destroy();
}
Display.setFullscreen(true);
glInit();
initNativeCursors();
} catch (Exception e) {
e.printStackTrace();
}
}
//check for window key
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
try {
try {
Mouse.setNativeCursor(null);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
for (Cursor cursor : cursors) {
cursor.destroy();
}
Display.setFullscreen(false);
glInit();
initNativeCursors();
} catch (Exception e) {
e.printStackTrace();
}
}
if (Keyboard.isKeyDown(Keyboard.KEY_M)) {
try {
Mouse.setNativeCursor(null);
} catch (Exception e) {
e.printStackTrace();
}
}
if (Keyboard.isKeyDown(Keyboard.KEY_N)) {
switchCursor();
}
while (Keyboard.next()) {
if (Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
Mouse.setGrabbed(!Mouse.isGrabbed());
}
}
}
Aggregations