Hello everyone,
I am here now:
I tried just clean HelloWorld.java from Get Started.
public class HelloWorld {
// The window handle
private long window;
private GLFWVidMode vid;
private int width;
private int height;
public void run(String[] args) {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
for(int i = 0; i < args.length; i++)
{
switch(args[i])
{
case "-w":
case "-width":
width = Integer.parseInt(args[i+1]);
System.out.println("argument is for w/width "+args[i+1]+"\n");
break;
case "-h":
case "-height":
height = Integer.parseInt(args[i+1]);
System.out.println("argument is for h/height "+args[i+1]+"\n");
break;
case "-windowed":
vid = glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
glfwSetWindowMonitor(window, glfwGetWindowMonitor(window), (vid.width()-width)/2, (vid.height()-height)/2, width, height, 60);
System.out.println("argument is for windowed = false \n");
break;
default:
break;
}
}
init();
loop();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // the window will be resizable
glfwWindowHint(GLFW_MAXIMIZED, GLFW_FALSE);
// Create the window
window = glfwCreateWindow(640, 480, "Hello World!", glfwGetPrimaryMonitor(), NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// 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 GLCapabilities instance and makes the OpenGL
// bindings available for use.
GL.createCapabilities();
// Set the clear color
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while ( !glfwWindowShouldClose(window) ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwSwapBuffers(window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
}
}
public static void main(String[] args) {
new HelloWorld().run(args);
}
}
Is it correct? But I understand like glfw forum I always tried glfwSetWindowMonitor()
But it crashed now:
Hello LWJGL 3.1.4 SNAPSHOT!
argument is for w/width 1200
argument is for h/height 720
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.system.Checks.check(Checks.java:96)
at org.lwjgl.glfw.GLFW.nglfwGetVideoMode(GLFW.java:1284)
at org.lwjgl.glfw.GLFW.glfwGetVideoMode(GLFW.java:1306)
at HelloWorld.run(HelloWorld.java:35)
at HelloWorld.main(HelloWorld.java:116)
If I use -windowed than glfwSetWindowMonitor will change to width and height. But it won't work. How do I fix?