Search code examples
javajavafxnetbeansjframelwjgl

How to put an lwjgl app into a Javafx/swing canvas


is it possible to put the lwjgl display onto a canvas created in a Jframe Form? I'm using the Netbeans IDE v8.2 and lwjgl 2.9.3. Thanks for the help! Heres some of my code from the DisplayManager which is called from the MainLoop.

public class DisplayManager{

private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private static final int FPS_CAP = 120;

private static long lastFrameTime;
private static float delta;

public static void createDisplay() {

    ContextAttribs attribs = new ContextAttribs(3,2).withForwardCompatible(true).withProfileCore(true);


    try { 

        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
        Display.create(new PixelFormat(), attribs);
        Display.setTitle("Coffee Beans V1");
        Display.setParent(EditorGUI.canvas1);
        new EditorGUI().setVisible(true);



    } catch (LWJGLException e) {
       e.printStackTrace();
    }

    GL11.glViewport(0,0,WIDTH,HEIGHT);
    lastFrameTime = getCurrentTime();

}

Solution

  • Yes, via org.lwjgl.opengl.Display.setParent(java.awt.Canvas).