// Setup an error callback. The default implementation
// will print the error message in System.err.
glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
// Configure our window
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable
// Create the window
window = glfwCreateWindow(width, height, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Get the resolution of the primary monitor
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1); // 60 fps
// Make the window visible
glfwShowWindow(window);
// Setup several callbacks...
[...]
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the ContextCapabilities instance and makes the OpenGL
// bindings available for use.
GLContext.createFromCurrent();
// Set the clear color
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// init Gl
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, 1, -1);
Timer timer = new Timer();
timer.setResolution(Timer.MILLISECONDS);
timer.reset();
// Setup an error callback. The default implementation
// will print the error message in System.err.
glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
// Configure our window
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable
// Create the window
window = glfwCreateWindow(width, height, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Get the resolution of the primary monitor
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
//glfwSwapInterval(0); // max fps
glfwSwapInterval(1); // 60 fps
//glfwSwapInterval(2); // 30 fps
timer.advance();
System.out.println("before show " + timer.getDeltaTime());
// Make the window visible
glfwShowWindow(window);
timer.advance();
System.out.println("after show " + timer.getDeltaTime());
// Setup several callbacks...
[...]
timer.advance();
System.out.println("after callback " + timer.getDeltaTime());
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the ContextCapabilities instance and makes the OpenGL
// bindings available for use.
GLContext.createFromCurrent();
timer.advance();
System.out.println("after context " + timer.getDeltaTime());
// Set the clear color
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// init Gl
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, 1, -1);
timer.advance();
System.out.println("after remains " + timer.getDeltaTime());
befor show 164.75491 after show 332.10287 after callback 0.142434 after context 29549.367 after remains 0.135119 | before show 331.3022 after show 241.0179 after callback 0.158602 after context 8035.149 after remains 0.21981 | before show 182.13263 after show 299.50977 after callback 0.156292 after context 7514.9365 after remains 0.251762 | before show 255.975 after show 208.50523 after callback 1.454751 after context 13989.93 after remains 4.016637 | before show 347.0369 after show 301.42838 after callback 0.222505 after context 12058.213 after remains 0.18093 | before show 235.8818 after show 364.6444 after callback 0.159757 after context 27760.44 after remains 0.199023 |