org.lwjgl.glfw.GLFWImage Java Examples

The following examples show how to use org.lwjgl.glfw.GLFWImage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowManager.java    From LWJGUI with MIT License 5 votes vote down vote up
/**
 * Adds or replaces a cursor.
 * 
 * @param cursor       Cursor to be replaced
 * @param customCursor Cursor image
 */
public static void addCursor(Cursor cursor, CustomCursor customCursor) {
	runLater(() -> {
		try (MemoryStack stack = stackPush()) {
			IntBuffer w = stack.mallocInt(1);
			IntBuffer h = stack.mallocInt(1);
			IntBuffer comp = stack.mallocInt(1);

			ByteBuffer imageBuffer;
			try {
				imageBuffer = Context.ioResourceToByteBuffer(customCursor.getPath(), 1 * 1024);
			} catch (IOException e) {
				throw new GLFWException(e);
			}

			if (!stbi_info_from_memory(imageBuffer, w, h, comp))
				throw new DecodeTextureException("Failed to read image information: " + stbi_failure_reason());

			ByteBuffer image = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
			if (image == null)
				throw new DecodeTextureException("Failed to load image: " + stbi_failure_reason());

			GLFWImage img = GLFWImage.mallocStack(stack).set(w.get(0), h.get(0), image);
			long custom = glfwCreateCursor(img, customCursor.getHotX(), customCursor.getHotY());

			memFree(imageBuffer);
			stbi_image_free(image);

			Long prev = cursors.put(cursor, custom);
			if (prev != null)
				glfwDestroyCursor(prev);
		}
	});
}
 
Example #2
Source File: Window.java    From Lwjgl3-Game-Engine-Programming-Series with MIT License 5 votes vote down vote up
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);
}
 
Example #3
Source File: GlfwMouseInputVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private long createGlfwCursor(JmeCursor jmeCursor) {
    GLFWImage glfwImage = new GLFWImage(BufferUtils.createByteBuffer(GLFWImage.SIZEOF));

    // TODO: currently animated cursors are not supported
    IntBuffer imageData = jmeCursor.getImagesData();
    ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity() * 4);
    buf.asIntBuffer().put(imageData);

    glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);

    return glfwCreateCursor(glfwImage, jmeCursor.getXHotSpot(), jmeCursor.getYHotSpot());
}
 
Example #4
Source File: Lwjgl3Mini2DxCursor.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
Lwjgl3Mini2DxCursor(Lwjgl3Mini2DxWindow window, Pixmap pixmap, int xHotspot, int yHotspot) {
	this.window = window;
	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() + ").");
	}

	this.pixmapCopy = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
	this.pixmapCopy.setBlending(Pixmap.Blending.None);
	this.pixmapCopy.drawPixmap(pixmap, 0, 0);

	glfwImage = GLFWImage.malloc();
	glfwImage.width(pixmapCopy.getWidth());
	glfwImage.height(pixmapCopy.getHeight());
	glfwImage.pixels(pixmapCopy.getPixels());
	glfwCursor = GLFW.glfwCreateCursor(glfwImage, xHotspot, yHotspot);
	cursors.add(this);
}
 
Example #5
Source File: Window.java    From oreon-engine with GNU General Public License v3.0 3 votes vote down vote up
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);
}