-2

I am learning OpenGL in Java with LWJGL and would like to use it to simulate physical models and would therefore like to have a set of displays and controls like buttons, sliders, text labels, etc. I have experience creating these kinds of things in AWT, and so to my mind it seems logical to embed a GLFW window inside an AWT window so as to only use the openGL context for rendering things that need to be rendered. Yet everything I have found online seems to want me to create my own HUD inside the openGL window, and I can't find any useful information on embedded GLFW inside some other existing thing like a JPanel or something? I'm still quite new to the subject so would appreciate being pointed in the right direction.

JeneralJames
  • 314
  • 1
  • 3
  • 10
  • You would have to render your gui into an offscreen image then render it using opengl, or just search for an lwjgl gui library – Mehdi Mar 05 '17 at 20:26
  • I believe LWJGL only allows you to create an OpenGL context for a whole window. You might be able to find a library that lets you create one as an AWT/Swing control. I know you can do it with SWT for example (but SWT is quite big and you might be able to find a smaller library that just does this) – user253751 Mar 05 '17 at 22:54

1 Answers1

0

Integrating GUI components with LWJGL3 (if it's what you're using) is quite difficult, espcially if you don't want to code it yourself. However, here are some solutions you can think of :

  • Use LWJGL 2 (still maintained, but old), which is known to be able to integrate into AWT/Swing components (but with some troubles)
  • Use a library such as lwjglx which provides a compatibility layer between LWJGL 2, and use it with a GUI library for LWJGL 2 (I don't think there are GUI libs available for LWJGL 3, but it's highly possible this has changed)

If you choose the first solution, you can refer to these questions before you get started :

To put a LWJGL 2 Display in a java.awt.Canvas, you can do something like this :

try {
    Display.setDisplayMode(new DisplayMode(width, height));
    Display.setParent(canvas);
    Display.create();
} catch (LWJGLException e) {
    e.printStackTrace();
    System.exit(0);
}
Community
  • 1
  • 1
cocosushi
  • 144
  • 10