For some reason I have this code:
GLFW.glfwMakeContextCurrent(gameInstance.window.windowHandle);
System.out.println("made context current");
GL.createCapabilities();
I still get an error when I create capabilities saying I do not have an OpenGL current context. All GLFW and GL functions are called in the same thread. Here is my full code:
private void gameThread()
{
if (gameInstance == null)
{
System.err.println("game is null");
return;
}
else if (!GLFW.glfwInit())
{
System.err.println("could not initialise GLFW");
return;
}
GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MAJOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MINOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
resolutions.clear();
GLFWVidMode.Buffer b = GLFW.glfwGetVideoModes(GLFW.glfwGetPrimaryMonitor());
while (b.hasRemaining())
{
GLFWVidMode vidMode = b.get();
boolean alreadyIn = false;
for (Resolution r : resolutions)
{
if (r.getWidth() == vidMode.width() && r.getHeight() == vidMode.height())
{
alreadyIn = true;
}
}
if (!alreadyIn)
{
resolutions.add(new Resolution(vidMode.width(), vidMode.height()));
}
}
gameInstance.initialise();
if (gameInstance.window == null)
{
GLFW.glfwTerminate();
System.err.println("window is null");
return;
}
gameInstance.window.windowHandle = GLFW.glfwCreateWindow(
gameInstance.window.resolution.getWidth(), gameInstance.window.resolution.getHeight(), gameInstance.window.title,
gameInstance.window.fullscreen ? GLFW.glfwGetPrimaryMonitor() : 0, 0);
if (gameInstance.window.verticalSync)
{
GLFW.glfwSwapInterval(1);
}
GLFW.glfwMakeContextCurrent(gameInstance.window.windowHandle);
System.out.println("made context current");
GL.createCapabilities();
while (!GLFW.glfwWindowShouldClose(gameInstance.window.windowHandle))
{
GL33.glClear(GL33.GL_COLOR_BUFFER_BIT | GL33.GL_DEPTH_BUFFER_BIT);
GLFW.glfwSwapBuffers(gameInstance.window.windowHandle);
GLFW.glfwPollEvents();
}
gameRunning.set(false);
GLFW.glfwDestroyWindow(gameInstance.window.windowHandle);
GLFW.glfwTerminate();
}
What did I do wrong?