Search in sources :

Example 1 with GLFWImage

use of org.lwjgl.glfw.GLFWImage in project jmonkeyengine by jMonkeyEngine.

the class LwjglWindow method imagesToGLFWImages.

/**
     * Convert array of images to array of {@link GLFWImage}.
     */
private GLFWImage[] imagesToGLFWImages(final Object[] images) {
    final GLFWImage[] out = new GLFWImage[images.length];
    for (int i = 0; i < images.length; i++) {
        final BufferedImage image = (BufferedImage) images[i];
        out[i] = imageToGLFWImage(image);
    }
    return out;
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint) BufferedImage(java.awt.image.BufferedImage)

Example 2 with GLFWImage

use of org.lwjgl.glfw.GLFWImage in project jmonkeyengine by jMonkeyEngine.

the class LwjglWindow method imageToGLFWImage.

/**
     * Convert the {@link BufferedImage} to the {@link GLFWImage}.
     */
private GLFWImage imageToGLFWImage(BufferedImage image) {
    if (image.getType() != BufferedImage.TYPE_INT_ARGB_PRE) {
        final BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics2D graphics = convertedImage.createGraphics();
        final int targetWidth = image.getWidth();
        final int targetHeight = image.getHeight();
        graphics.drawImage(image, 0, 0, targetWidth, targetHeight, null);
        graphics.dispose();
        image = convertedImage;
    }
    final ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
    for (int i = 0; i < image.getHeight(); i++) {
        for (int j = 0; j < image.getWidth(); j++) {
            int colorSpace = image.getRGB(j, i);
            buffer.put((byte) ((colorSpace << 8) >> 24));
            buffer.put((byte) ((colorSpace << 16) >> 24));
            buffer.put((byte) ((colorSpace << 24) >> 24));
            buffer.put((byte) (colorSpace >> 24));
        }
    }
    buffer.flip();
    final GLFWImage result = GLFWImage.create();
    result.set(image.getWidth(), image.getHeight(), buffer);
    return result;
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) ByteBuffer(java.nio.ByteBuffer) BufferedImage(java.awt.image.BufferedImage) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint) Graphics2D(java.awt.Graphics2D)

Example 3 with GLFWImage

use of org.lwjgl.glfw.GLFWImage in project libgdx by libgdx.

the class Lwjgl3Window method setIcon.

static void setIcon(long windowHandle, Pixmap[] images) {
    if (SharedLibraryLoader.isMac)
        return;
    GLFWImage.Buffer buffer = GLFWImage.malloc(images.length);
    Pixmap[] tmpPixmaps = new Pixmap[images.length];
    for (int i = 0; i < images.length; i++) {
        Pixmap pixmap = images[i];
        if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
            Pixmap rgba = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
            rgba.setBlending(Pixmap.Blending.None);
            rgba.drawPixmap(pixmap, 0, 0);
            tmpPixmaps[i] = rgba;
            pixmap = rgba;
        }
        GLFWImage icon = GLFWImage.malloc();
        icon.set(pixmap.getWidth(), pixmap.getHeight(), pixmap.getPixels());
        buffer.put(icon);
        icon.free();
    }
    buffer.position(0);
    GLFW.glfwSetWindowIcon(windowHandle, buffer);
    buffer.free();
    for (Pixmap pixmap : tmpPixmaps) {
        if (pixmap != null) {
            pixmap.dispose();
        }
    }
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 4 with GLFWImage

use of org.lwjgl.glfw.GLFWImage in project jmonkeyengine by jMonkeyEngine.

the class GlfwMouseInput method createGlfwCursor.

private long createGlfwCursor(JmeCursor jmeCursor) {
    // TODO: currently animated cursors are not supported
    IntBuffer imageData = jmeCursor.getImagesData();
    ByteBuffer buf = transformCursorImage(imageData, jmeCursor.getWidth(), jmeCursor.getHeight());
    GLFWImage glfwImage = new GLFWImage(BufferUtils.createByteBuffer(GLFWImage.SIZEOF));
    glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);
    int hotspotX = jmeCursor.getXHotSpot();
    int hotspotY = jmeCursor.getHeight() - jmeCursor.getYHotSpot();
    return glfwCreateCursor(glfwImage, hotspotX, hotspotY);
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) IntBuffer(java.nio.IntBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 5 with GLFWImage

use of org.lwjgl.glfw.GLFWImage in project jmonkeyengine by jMonkeyEngine.

the class LwjglWindow method setWindowIcon.

/**
     * Set custom icons to the window of this application.
     */
protected void setWindowIcon(final AppSettings settings) {
    final Object[] icons = settings.getIcons();
    if (icons == null)
        return;
    final GLFWImage[] images = imagesToGLFWImages(icons);
    try (final GLFWImage.Buffer iconSet = GLFWImage.malloc(images.length)) {
        for (int i = images.length - 1; i >= 0; i--) {
            final GLFWImage image = images[i];
            iconSet.put(i, image);
        }
        glfwSetWindowIcon(window, iconSet);
    }
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint)

Aggregations

GLFWImage (org.lwjgl.glfw.GLFWImage)6 ByteBuffer (java.nio.ByteBuffer)3 GLFW.glfwWindowHint (org.lwjgl.glfw.GLFW.glfwWindowHint)3 BufferedImage (java.awt.image.BufferedImage)2 IntBuffer (java.nio.IntBuffer)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Graphics2D (java.awt.Graphics2D)1