Add support for LWJGL3 inside an AWT Canvas
Currently using a snapshot version of https://github.com/LWJGLX/lwjgl3-awt since MacOS Support is not released yet.
Work in Progress! Just opened the PR to be able to discuss issues I encounter.
Fixes #6190
I just experimented a bit with ParticleEditor: moving setVisible(true);out of the EventQueue.invokeLater() block (like here) seems to decrease the chances of the positioning issue happening considerably.
- TexturePackerTest throws the following error:
Assertion failed: (shape[0] == SHAPE_START), function assert_check_shape, file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreGraphics/CoreGraphics-1355.22/CoreGraphics/Regions/shape.c, line 161.
This is caused by a missing -XstartOnFirstThread, that Lwjgl3Application needs. I have replaced it with Lwjgl3AWTFrame now, that doesn't need this parameter, since AWT is doing the correct stuff there for us.
I don't know what all this tools are supposed to do, so I haven't tried them, though. 🙈
ParticleEditordoes render its stuff, which is good. However, if another window is focused (i.e. clicked) before ParticleEditor fully opens, the lwjgl panel is rendered at the wrong location (top left).- Rendering in
Hieroworks as well, but the lwjgl rendering always happens at the wrong position (maybe because of its splash screen?)Flamerenders its output as expected, but the lwjgl panel is in the top left, so the wrong position issue can’t happen here.
The wrong position should be fixed now.
(Waiting for https://github.com/LWJGLX/lwjgl3-awt/pull/34 to be merged, currently using a jitpack build.)
@crykn I have checked the 1.8 language level again.
- gdx-tools needs 1.8, since it is now based on lwjgl3, which needs 1.8
- gdx-tests has a dependency on gdx-tools, for the
BitmapFontWriterTest - the other test projects depend on gdx-tests
So if we could move BitmapFontWriterTest somewhere else, most of the language levels could stay on 1.7. I don't know if and where to move it though. :shrug:
I have added commit 36d51e0003ce2909d2a0b6ae13926dc389c82bb9 to show how it would look like, if the BitmapFontWriterTest would be removed.
Hey @tisoft! I haven't had time yet to look at your recent changes, but they seem rather promising! Regarding the language levels:
- We can't avoid raising
gdx-tools' source level when using LWJGL3, so that is fine. Also, if any third-party projects are depending on gdx-tools those should be desktop projects anyway and on desktop Java 8 is no problem. - Changing the source level of
gdx-testslooks fine to me as well, because no end-user should depend on those projects. And I'd like to avoid moving BitmapFontWriterTest, since at the moment all tests are in gdx-tests. - However, I don't know whether the Android & iOS tests are affected by changing the source level (maybe @PokeMMO, @obigu or any of the others could chime in on this). But they seem to compile, so I don't think there'll be any issues.
Since everything now works for me ™️ , I think this is ready for review.
It's not ready for merge until the lwjgl3-awt project has merged https://github.com/LWJGLX/lwjgl3-awt/pull/34
I tested this on Linux and macOS 10.15 with different java versions, but would really appreciate more testing.
- However, I don't know whether the Android & iOS tests are affected by changing the source level (maybe @PokeMMO, @obigu or any of the others could chime in on this). But they seem to compile, so I don't think there'll be any issues.
I'm not 100% sure of the consequences of setting source level to 8 on android-tests or ios-tests tests while having their platform dependencies on 6, my instinct says it's not a good idea and that we may regret it in the future. Android and Java 8 have some peculiarities and given that we have min SDK 14 we may come across funny lint errors. If the reason for this is just 1 test, I'd rather temporarily not support that test on Android and iOS (until we move to Java 8).
@crykn I think I fixed all review comments. Only missing is the merge and release of https://github.com/LWJGLX/lwjgl3-awt/pull/34
Lwjgl3-awt 0.1.8 has been released, so from my point of view, this could be merged now. 🥳
Hey @tisoft,
last nitpick, I promise: could you add key codes for CAPS_LOCK, PAUSE (aka Break), PRINT_SCREEN, SCROLL_LOCK, F13 to F24, NUMPAD_DIVIDE, NUMPAD_MULTIPLY, NUMPAD_SUBTRACT, NUMPAD_ADD, NUMPAD_DOT, NUMPAD_COMMA, NUMPAD_ENTER, NUMPAD_EQUALS, NUM_LOCK and NUMPAD_LEFT_PAREN, NUMPAD_RIGHT_PAREN to Lwjgl3AwtInput? Those were recently introduced with libGDX 1.9.13. Basically, you need to port the changes made to LwjglAwtInput in these three commits (2437e2afe35337e6f7772321e29ca06e1f407231, 325c6386328a3066bed47cc621bc8b993d4e2c7c, 4648b1ca6d63e7b88b6ec7c48ab59ca7f279161f) to Lwjgl3AwtInput.
Apart from that, as we already talked about, I'm not really sure about the fetch.xml changes, as build stuff isn't my forte, but maybe one of the others can chime in here.
Otherwise, I think this is good to merge. I wasn't able to test the functionality of all classes in gdx-tools (looking at you TiledMapPacker), because I'm not really familiar with their workings in the first place. But all the visual tools started up and rendered correctly and that is also the area where this PR really changed stuff.
Thanks a lot for all the work you put into this! It is very nice to see macOS support for Hiero, Particle Editor, etc. to be finally back.
@crykn I have added the key bindings, rebased and extended AbstractGraphics.
Should be ready now. Might need a little squashing though. :smiling_imp:
- rebased to curent master
- extended AbstractInput
- squashed commits and splited in two semantically meaningful commits
First of all thank you for the effort on this PR.
I've tested building and running the tools on Windows. On both Particle Editors (2D and 3D), the preview window (I think it's the canvas) blinks lile crazy (I can provide a video if you need it). I haven't been able to test Hiero because there's currenlty an issue that makes it crash at startup but it's unrelated to this RP.
Thanks for testing in windows. Unfortunately I don't have a windows system here, so I can't reproduce the error easily. I'll try it in a VM.
Ah darn. Now it no longer misbehaves on macOS but does so on Windows, it seems. Looking back; I seem to remember that it didn't flicker on Windows before your positon fix. I somehow missed to test the PR on Windows after this change.
This lwjgl3-awt test runs fine on Windows btw, so it seems like the issue is in libGDX code.
The Hiero issue with this PR is actually separate to the one @obigu mentioned (which, on another note, I can't reproduce, so it is probably caused by one of the installed fonts). Hiero crashes with this PR, because "No context is current or a function that is not available in the current context was called." See the full stacktrace below:
Click to show full log
> Task :extensions:gdx-tools:Hiero.main() FAILED
FATAL ERROR in native method: Thread[AWT-EventQueue-0,6,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.
at org.lwjgl.opengl.GL11C.nglGenTextures(Native Method)
at org.lwjgl.opengl.GL11C.glGenTextures(GL11C.java:664)
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:2492)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3GL20.glGenTexture(Lwjgl3GL20.java:348)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:142)
at com.badlogic.gdx.graphics.g2d.PixmapPacker$Page$1.<init>(PixmapPacker.java:504)
at com.badlogic.gdx.graphics.g2d.PixmapPacker$Page.updateTexture(PixmapPacker.java:504)
at com.badlogic.gdx.graphics.g2d.PixmapPacker.updatePageTextures(PixmapPacker.java:410)
at com.badlogic.gdx.graphics.g2d.PixmapPacker.updateTextureRegions(PixmapPacker.java:402)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateData(FreeTypeFontGenerator.java:464)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateFont(FreeTypeFontGenerator.java:161)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateFont(FreeTypeFontGenerator.java:152)
at com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont.setRenderType(UnicodeFont.java:647)
at com.badlogic.gdx.tools.hiero.Hiero.updateFont(Hiero.java:315)
at com.badlogic.gdx.tools.hiero.Hiero$3.valueChanged(Hiero.java:439)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1802)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1816)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:459)
at javax.swing.JList.setSelectedIndex(JList.java:2216)
at javax.swing.JList.setSelectedValue(JList.java:2366)
at com.badlogic.gdx.tools.hiero.Hiero.<init>(Hiero.java:190)
at com.badlogic.gdx.tools.hiero.Hiero$21.run(Hiero.java:1591)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Hey @tisoft, did you get the chance to try Lwjgl3AwtCanvas in a Windows VM?
I have rebased against current master. Unfortunately I could not get it to work in windows inside a VM, so the flickering is probably still there. Could anyone look into the windows flickering issue?
Rebased again against master. I still can't test/debug on windows. Would it be better to split the PR? One PR for the addition of the Lwjgl3AWTCanvas, which would not break anything existing. And another PR, that contains the changes of the tools project, which could possibly break, especially on windows, as I can't test there?
Hm, I'm not sure. The Windows issue also happens with Lwjgl3AWTCanvas itself (for example in Lwjgl3AWTCanvasTest and Lwjgl3AwtTestStarter), so this wouldn't really help with the underlining "problem" of this PR. But if you want to do it for the sake of better readability, sure, feel free to go ahead.
I've had a quick test of this on Linux. I see the discussion about flickering above. While I haven't tested on Windows, I can get some flicker on resize, though not enough for it to really be an issue. The bigger issue is I managed to get an old copy stuck in one of my buffers, which could render an application unusable until restarted.
Below is a GIF played at 1/6th speed to clearly demonstrate the issue. It's inside a spoiler thingy because it's quite distracting. The black flicker I'm referring to affects the entire window on frame 6 - other blackness on resize is normal.
GIF

Additionally, closing a test crashes the whole thing, but I expect that's due to it creating an additional window and mightn't be an issue someone would have if their game was developed with AWT from the start. Not many games use multiple windows anyway.
X Error of failed request: RenderBadPicture (invalid Picture parameter)
Major opcode of failed request: 139 (RENDER)
Minor opcode of failed request: 7 (RenderFreePicture)
Picture id in failed request: 0x200004d
Serial number of failed request: 1178
Current serial number in output stream: 1185
AL lib: (EE) alc_cleanup: 1 device not closed
None of the above issues happen when running a non-AWT LWJGL3 application.
Hey, is this issue still being worked on? It looks like most of the work is already done.
Hey there, is this feature considered to be merged any time soon? I would love to see an AWT integration for LWJGL3
What features/bug fixes are missing for this PR, I might be able to help here :)?
@undefinedhuman There's the flickering issue on Windows (see above comments), and in the meantime, some git conflicts popped up. It seems crykn made some improvements tisoft/libgdx#1, which tisoft didn't merge