Java 类org.lwjgl.glfw.GLFWImage 实例源码

项目:TorchEngine    文件:Cursor.java   
/**
 * <p>
 * Set the shape of the cursor to a custom image.
 * </p>
 *
 * @param texture The cursor shape.
 * @param hot The hot point of the shape.
 */
public static void setShape(Texture2D texture, Vector2f hot)
{
    if(CursorShape.hasCursor(texture, hot))
    {
        setShape(CursorShape.getCursor(texture, hot));
        LoggerInternal.log("Loaded existing cursor shape");
    }
    else
    {
        GLFWImage image = GLFWImage.malloc().set(texture.getWidth(), texture.getHeight(), texture.getByteBuffer());

        long cursor = glfwCreateCursor(image, Math.round(hot.x), Math.round(hot.y));
        CursorShape.addCursor(texture, hot, cursor);

        setShape(cursor);
        LoggerInternal.log("Created new cursor shape");
    }
}
项目:ether    文件:GLFWWindow.java   
@Override
public void setPointerIcon(File file, int hotX, int hotY) {
    checkMainThread();
    Long cursor = FILE2CRSR.get(file);
    if(cursor == null) {
        try {
            IHostImage src = Platform.get().getImageSupport().readHost(new FileInputStream(file), ComponentType.BYTE, ComponentFormat.RGBA, AlphaMode.POST_MULTIPLIED);
            GLFWImage image = GLFWImage.malloc();
            image.set(src.getWidth(), src.getHeight(), flip(src.getPixels(), src.getHeight()));         
            cursor = Long.valueOf(GLFW.glfwCreateCursor(image, hotX, hotY));
            FILE2CRSR.put(file, cursor);
            image.free();
        } catch(Throwable t) {
            log.warning(t);
        }
    }
    if(cursor != null)
        GLFW.glfwSetCursor(window, cursor.longValue());
}
项目:CubeEngine    文件:GLIcon.java   
protected GLIcon(String imagePath) {
    this.image = GLFWImage.malloc();
    this.buffer = GLFWImage.malloc(1);

    BufferedImage bufferedImage = ImageUtils.readImage(imagePath);
    int imwidth = bufferedImage.getWidth();
    int imheight = bufferedImage.getHeight();
    ByteBuffer pixels = BufferUtils.createByteBuffer(imwidth * imheight * 4);
    for (int y = 0; y < imheight; y++) {
        for (int x = 0; x < imwidth; x++) {
            Color color = new Color(bufferedImage.getRGB(x, y), true);
            pixels.put((byte) color.getRed());
            pixels.put((byte) color.getGreen());
            pixels.put((byte) color.getBlue());
            pixels.put((byte) color.getAlpha());
        }
    }
    pixels.flip();
    this.image.set(imwidth, imheight, pixels);
    this.buffer.put(0, this.image);
}
项目:Lwjgl3-Game-Engine-Programming-Series    文件:Window.java   
public void create(int width, int height)
{
    setWidth(width);
    setHeight(height);

    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);  
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);  
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  

    window = glfwCreateWindow(width, height, "OREON ENGINE Programming Tutorial Series", 0, 0);

    if(window == 0) {
        throw new RuntimeException("Failed to create window");
    }

    ByteBuffer bufferedImage = ImageLoader.loadImageToByteBuffer("./res/logo/oreon_lwjgl_icon32.png");

    GLFWImage image = GLFWImage.malloc();

    image.set(32, 32, bufferedImage);

    GLFWImage.Buffer images = GLFWImage.malloc(1);
       images.put(0, image);

    glfwSetWindowIcon(window, images);

    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    glfwShowWindow(window);
}
项目:LD38    文件:Window.java   
public void setIcon(String icon16Path, String icon32Path){
    //setup buffers to work with stb
    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);

    //these will be the data buffers for the textures
    ByteBuffer icon16,icon32;
    try{
        //populate the buffers with the raw image data
        icon16 = ResourceLoader.getBytes(icon16Path);
        icon32 = ResourceLoader.getBytes(icon32Path);

        //setup image buffers for the images to be processed
        try(GLFWImage.Buffer icons = GLFWImage.malloc(2)){
            //process both images with stb
            //16x16 icon
            ByteBuffer p16 = STBImage.stbi_load_from_memory(icon16, w, h, comp, 4);
            icons.position(0).width(w.get(0)).height(h.get(0)).pixels(p16);

            //32x32 icon
            ByteBuffer p32 = STBImage.stbi_load_from_memory(icon32, w, h, comp, 4);
            icons.position(1).width(w.get(0)).height(h.get(0)).pixels(p32);

            //reset the icons buffer position
            icons.position(0);
            GLFW.glfwSetWindowIcon(handle, icons);

            //free the stb resources
            STBImage.stbi_image_free(p16);
            STBImage.stbi_image_free(p32);
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}
项目:Laser-Amazer    文件:Window.java   
/**
 * Sets the taskbar and window icon for the game
 */
private void setWindowIcon() {
    GLFWImage image = GLFWImage.malloc();
    image.set(32, 32, loadIcon("/icon.png"));
    GLFWImage.Buffer images = GLFWImage.malloc(1);
    images.put(0, image);

    glfwSetWindowIcon(window, images);

    images.free();
    image.free();
}
项目:gdx-backend-jglfw    文件:JglfwCursor.java   
public JglfwCursor(JglfwGraphics graphics, Pixmap pixmap, int xHotspot, int yHotspot) {
    this.graphics = graphics;

    if (pixmap == null) {
        glfwCursor = 0;
        return;
    }

    if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
        throw new GdxRuntimeException("Cursor image pixmap is not in RGBA8888 format.");
    }

    if ((pixmap.getWidth() & (pixmap.getWidth() - 1)) != 0) {
        throw new GdxRuntimeException("Cursor image pixmap width of " + pixmap.getWidth()
                + " is not a power-of-two greater than zero.");
    }

    if ((pixmap.getHeight() & (pixmap.getHeight() - 1)) != 0) {
        throw new GdxRuntimeException("Cursor image pixmap height of " + pixmap.getHeight()
                + " is not a power-of-two greater than zero.");
    }

    if (xHotspot < 0 || xHotspot >= pixmap.getWidth()) {
        throw new GdxRuntimeException("xHotspot coordinate of " + xHotspot + " is not within image width bounds: [0, "
                + pixmap.getWidth() + ").");
    }

    if (yHotspot < 0 || yHotspot >= pixmap.getHeight()) {
        throw new GdxRuntimeException("yHotspot coordinate of " + yHotspot + " is not within image height bounds: [0, "
                + pixmap.getHeight() + ").");
    }

    final GLFWImage img = GLFWImage.malloc();
    img.width(pixmap.getWidth());
    img.height(pixmap.getHeight());
    img.pixels(pixmap.getPixels());

    glfwCursor = glfwCreateCursor(img, xHotspot, yHotspot);
    if (glfwCursor == 0) {
        throw new GdxRuntimeException("Could not create cursor image.");
    }
}
项目:CubeEngine    文件:GLIcon.java   
public final GLFWImage getGLFWImage() {
    return (this.image);
}
项目:SilenceEngine    文件:Cursor.java   
/**
 * Constructs a cursor object using the pixels from an Image object and also the location of the pointer hot point
 * in the image pixels retrieved from the OpenGL Texture.
 *
 * @param image The Image object to retrieve the image data from.
 * @param xHot  The x-coordinate of the cursor hotspot in pixels.
 * @param yHot  The y-coordinate of the cursor hotspot in pixels.
 */
public Cursor(Image image, int xHot, int yHot)
{
    int width = image.getWidth();
    int height = image.getHeight();

    GLFWImage glfwImage = GLFWImage.calloc();
    glfwImage.width(width);
    glfwImage.height(height);

    ByteBuffer data = BufferUtils.createByteBuffer(width * height * 4);

    Color color = Color.REUSABLE_STACK.pop();

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            image.getPixel(x, y, color);

            float r = (color.r * 255f);
            float g = (color.g * 255f);
            float b = (color.b * 255f);
            float a = ((1 - color.a) * 255f);

            data.put((byte) r)
                    .put((byte) g)
                    .put((byte) b)
                    .put((byte) a);
        }
    }

    Color.REUSABLE_STACK.push(color);

    data.flip();
    glfwImage.pixels(data);

    handle = glfwCreateCursor(glfwImage, xHot, yHot);

    if (handle == NULL)
        throw new SilenceException("Unable to load cursor from texture");

    glfwImage.free();
}
项目:EmergencyLanding    文件:ELTexture.java   
public GLFWImage convertToGLFWImage() {
    return GLFWImage.create().set(this.dim.getX(), this.dim.getY(), this.buf);
}
项目:oreon-engine    文件:Window.java   
public void setIcon(String path){

    ByteBuffer bufferedImage = ResourceLoader.loadImageToByteBuffer(path);

    GLFWImage image = GLFWImage.malloc();

    image.set(32, 32, bufferedImage);

    GLFWImage.Buffer images = GLFWImage.malloc(1);
       images.put(0, image);

    glfwSetWindowIcon(getId(), images);
}