title: Lwjgl 3, How to get OpenGL context current in the current thread?
body: <p>I am using OpenGL in LWJGL 3 and I get the following error;</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
      at org.lwjgl.opengl.GL.getCapabilities(GL.java:157)
      at org.lwjgl.opengl.GL11.getInstance(GL11.java:1390)
      at org.lwjgl.opengl.GL11.glClearColor(GL11.java:1842)
      at com.base.engine.RenderUtil.initGraphics(RenderUtil.java:13)
      at com.base.engine.Main.&lt;init&gt;(Main.java:14)
      at com.base.engine.Main.main(Main.java:24)
  </code></pre>
  <p>This is the RenderUtil class where initGraphics is called from the constructor of my main class. I have also tried to call initGraphics after creating a window with GLFW which has also generated a similar error message.</p>
  <pre><code>    package com.base.engine;
      
      import static org.lwjgl.opengl.GL11.*;
      import static org.lwjgl.opengl.GL30.*;
      
      public class RenderUtil {
      
          public static void clearScreen() {
              glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          }
      
          public static void initGraphics() {
              glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      
              glFrontFace(GL_CW);
              glCullFace(GL_BACK);
              glEnable(GL_CULL_FACE);
              glEnable(GL_DEPTH_TEST);
      
              glEnable(GL_FRAMEBUFFER_SRGB);
          }
      }
  </code></pre>
  <p>Also, I am not using multithreading. To create a window I call the method <code>Window.createWindow(1366, 768, &quot;Test&quot;);</code> from my main method.
  ```
  private static Long window;</p>
  <pre><code>    public static String createWindow(int width, int height, String title) {
          if (GLFW.glfwInit() == 0) {
              return &quot;GLFW failed to initialise.&quot;;
          }
  
          GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, 4);
          window = GLFW.glfwCreateWindow(width, height, title,
                  GLFW.glfwGetPrimaryMonitor(), 0);
  
          if (window == null) {
              GLFW.glfwTerminate();
              return &quot;Failed to create window.&quot;;
          }
  
          GLFW.glfwMakeContextCurrent(window);
          return &quot;GLFW has established a window.&quot;;
      }
  </code></pre>
  <pre><code>I have tried putting `RenderUtil.initGraphics();` two different position in my main method, both resulting in errors.
  
          private boolean isRunning = false;
          private Game game;
      
  
          // This is the constructor
          public Main() {
              // Pos 1 - RenderUtil.initGraphics();
              isRunning = false;
              game = new Game();
          }
  
          public static void main(String[] args) {
              System.out.println(Window.createWindow(1366, 768, &quot;Test&quot;));
              // Pos 2 - RenderUtil.initGraphics();
              Main game = new Main();
              game.start();
          }
  </code></pre>