2424
2525package org .overrun .swgl .core ;
2626
27+ import org .lwjgl .glfw .GLFWErrorCallback ;
2728import org .lwjgl .opengl .GL ;
2829import org .overrun .swgl .core .gl .GLStateMgr ;
2930import org .overrun .swgl .core .io .Keyboard ;
@@ -87,6 +88,11 @@ public void updateTime() {
8788 public void boot () {
8889 try {
8990 prepare ();
91+ if (initialErrorCallback == null ) {
92+ GLFWErrorCallback .createPrint (getDebugStream ()).set ();
93+ } else {
94+ GLFWErrorCallback .create (initialErrorCallback ).set ();
95+ }
9096 if (!glfwInit ())
9197 throw new IllegalStateException ("Unable to initialize GLFW" );
9298
@@ -103,43 +109,42 @@ public void boot() {
103109 preStart ();
104110 window = new Window ();
105111 window .createHandle (initialWidth , initialHeight , initialTitle );
106- long hWnd = window .getHandle ();
107- window .setResizeFunc ((handle , width , height ) -> onResize (width , height ));
112+ window .setResizeCb ((handle , width , height ) -> onResize (width , height ));
108113
109114 // Setup IO
110115 keyboard = new Keyboard ();
111116 keyboard .setWindow (window );
112- glfwSetKeyCallback ( hWnd , (handle , key , scancode , action , mods ) -> {
117+ window . setKeyCb ( (handle , key , scancode , action , mods ) -> {
113118 if (action == GLFW_PRESS ) onKeyPress (key , scancode , mods );
114119 else if (action == GLFW_RELEASE ) onKeyRelease (key , scancode , mods );
115120 else if (action == GLFW_REPEAT ) onKeyRepeat (key , scancode , mods );
116121 });
117122 mouse = new Mouse (this );
118123 mouse .registerToWindow (window );
119- glfwSetMouseButtonCallback ( hWnd , (handle , button , action , mods ) -> {
124+ window . setMouseBtnCb ( (handle , button , action , mods ) -> {
120125 if (action == GLFW_PRESS ) onMouseBtnPress (button , mods );
121126 else if (action == GLFW_RELEASE ) onMouseBtnRelease (button , mods );
122127 });
123- glfwSetWindowFocusCallback ( hWnd , (handle , focused ) -> {
128+ window . setFocusCb ( (handle , focused ) -> {
124129 if (!focused ) mouse .firstFocus = true ;
125130 });
126- glfwSetScrollCallback ( hWnd , (handle , xoffset , yoffset ) -> onScroll (xoffset , yoffset ));
131+ window . setScrollCb ( (handle , xoffset , yoffset ) -> onScroll (xoffset , yoffset ));
127132
128133 timer = new Timer ();
129- glfwMakeContextCurrent ( hWnd );
134+ window . makeContextCurr ( );
130135 glfwSwapInterval (initialSwapInterval );
131136 GL .createCapabilities (true );
132137 GLStateMgr .init ();
133138 start ();
134- glfwShowWindow ( hWnd );
139+ window . show ( );
135140 postStart ();
136141 int frames = 0 ;
137142 double lastTime = Timer .getTime ();
138- while (!glfwWindowShouldClose ( hWnd )) {
143+ while (!window . shouldClose ( )) {
139144 updateTime ();
140145 update ();
141146 run ();
142- glfwSwapBuffers ( hWnd );
147+ window . swapBuffers ( );
143148 glfwPollEvents ();
144149 ++frames ;
145150 while (Timer .getTime () >= lastTime + 1.0 ) {
@@ -167,6 +172,10 @@ public void boot() {
167172 glfwTerminate ();
168173 }
169174 postClose ();
175+ var cb = glfwSetErrorCallback (null );
176+ if (cb != null ) {
177+ cb .free ();
178+ }
170179 }
171180 }
172181
0 commit comments