import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.GL_FALSE;
import static org.lwjgl.opengl.GL11.GL_TRUE;
import static org.lwjgl.system.MemoryUtil.*;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
public class Window {
private GLFWErrorCallback errorCallback = GLFWErrorCallback.createPrint(System.err);
private long id;
private String title;
private int width, height;
public Window(String title, int width, int height){
this.title = title;
this.width = width;
this.height = height;
}
public void init(){
glfwSetErrorCallback(this.errorCallback);
if(!glfwInit()) throw new IllegalStateException("GLFW initialization has failed!");
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_VISIBLE, GL_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
this.id = glfwCreateWindow(this.width, this.height, this.title, NULL, NULL);
if(id == NULL){
glfwTerminate();
throw new RuntimeException("GLFW window creation has failed!");
}
glfwSetWindowPos(this.id, 100, 100);
glfwMakeContextCurrent(this.id);
GL.createCapabilities();
GL11.glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
System.out.println("GLFW Version: " + glfwGetVersionString());
System.out.println("OpenGL Version: " + GL11.glGetString(GL11.GL_VERSION));
glfwSwapInterval(1);
glfwShowWindow(this.id);
}
public void destroy(){
glfwDestroyWindow(this.id);
glfwTerminate();
}
//GETTERS
public long getId(){
return this.id;
}
public String getTitle(){
return this.title;
}
public int getWidth(){
return this.width;
}
public int getHeight(){
return this.height;
}
}
In the main method I just create a new window and call the init method and start the loop. I really hope it is not a code error, I think it might have something to do with the natives maybe or so, I have been getting the error since you could customize the lwjgl download file.