MCPcopy Create free account
hub / github.com/SpaiR/imgui-java / WindowGlfw

Class WindowGlfw

imgui-app/src/main/java/imgui/app/WindowGlfw.java:52–227  ·  view source on GitHub ↗

GLFW + OpenGL 3 implementation of Window. Mirrors the historical (pre-SDL) behavior of Window: GLFW window creation with GL 3.0 / 3.2 context, GL clear, GLFW poll/swap, and multi-viewport handling via ImGuiConfigFlags#ViewportsEnable.

Source from the content-addressed store, hash-verified

50 * and multi-viewport handling via {@link ImGuiConfigFlags#ViewportsEnable}.
51 */
52public class WindowGlfw extends Window {
53 private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
54 private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
55
56 private String glslVersion = null;
57
58 /**
59 * Pointer to the native GLFW window.
60 */
61 private long handle;
62
63 @Override
64 protected void init(final Configuration config) {
65 initWindow(config);
66 owner.initImGui(config);
67 imGuiGlfw.init(handle, true);
68 imGuiGl3.init(glslVersion);
69 }
70
71 @Override
72 protected void dispose() {
73 imGuiGl3.shutdown();
74 imGuiGlfw.shutdown();
75 owner.disposeImGui();
76 disposeWindow();
77 }
78
79 /**
80 * Method to create and initialize GLFW window.
81 *
82 * @param config configuration object with basic window information
83 */
84 protected void initWindow(final Configuration config) {
85 GLFWErrorCallback.createPrint(System.err).set();
86
87 if (!glfwInit()) {
88 throw new IllegalStateException("Unable to initialize GLFW");
89 }
90
91 decideGlGlslVersions();
92
93 glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
94 handle = glfwCreateWindow(config.getWidth(), config.getHeight(), config.getTitle(), MemoryUtil.NULL, MemoryUtil.NULL);
95
96 if (handle == MemoryUtil.NULL) {
97 throw new RuntimeException("Failed to create the GLFW window");
98 }
99
100 try (MemoryStack stack = MemoryStack.stackPush()) {
101 final IntBuffer pWidth = stack.mallocInt(1); // int*
102 final IntBuffer pHeight = stack.mallocInt(1); // int*
103
104 glfwGetWindowSize(handle, pWidth, pHeight);
105 final GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor()));
106 glfwSetWindowPos(handle, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
107 }
108
109 glfwMakeContextCurrent(handle);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected