Hello Guest

Creating bitmap font with Graphics2D causes glfwPollEvents() to hang

  • 3 Replies

I'm having an issue with creating a bitmap font on the fly using a BufferedImage and Graphics2D. 

I'm using a technique that I've found in a few different places (e.g. https://github.com/SilverTiger/lwjgl3-tutorial/blob/master/src/silvertiger/tutorial/lwjgl/text/Font.java) where I load a java.awt.Font, generate glyphs from characters in the font, then create a buffered image, draw the glyphs on the buffered image, and then convert the buffered image to a texture (in a nutshell). 

The issue I'm having is as soon as I call the following...:

Code: [Select]
BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();

...the glfwPollEvents() call in my game loop hangs.  The window I'm using in turn becomes unresponsive with just a red background, although I don't think the red background is significant.

I've tried switching between a few different JDKs to see if perhaps there was something in Java 12 that was causing this problem, but after switching to JDK 11 and JDK 1.8 I've had the same issue.  I've also tried moving this code around to see if maybe it was some kind of timing issue, but regardless of where I make these calls, glfwPollEvents becomes unresponsive.

This is on OSX 10.14.3.

Any ideas?



Offline Cornix

  • *****
  • 488
As far as I know (I don't have an OSX machine myself) it is impossible on OSX to have more than one windowing toolkit in use at the same time within the same process. In your case you try to use both GLFW (from LWJGL3) and AWT (BufferedImage and Graphics) at the same time. That is forbidden by the operating system (dont ask me why).
A better solution would be to use the native stb library which you can get bindings for when downloading LWJGL3. I use it myself and never had any problems with it.

Ah, interesting.  Thanks for the quick reply!  I'll take a look at stb.