openGL capabilitises not working got error how do i fix it?

Started by pheonixfirewingz, January 13, 2019, 16:22:20

Previous topic - Next topic

pheonixfirewingz

Exception in thread "main" java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:378)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:322)
   at enigne.Display.create(Display.java:63)
   at wolfenginetestgame.WolfEngineTestGame.loadgame(WolfEngineTestGame.java:42)
   at wolfenginetestgame.WolfEngineTestGame.main(WolfEngineTestGame.java:18)

-------------------------------Code-----------------------------------------------------------------------------------
package enigne;

import enigne.utils.Utils;
import enigne.utils.math.Vector3f;

import java.nio.DoubleBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;

public class Display
{
    private static int width = ((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth()) - 200,
          height = (width / 16) * 9;
    private static long displayID;
    private static String title;
    @SuppressWarnings("unused")
   private double fps_Max, time , unprocessedTime = 0, processedTime;
    private boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST],
          mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
    //temp
    private Vector3f color = new Vector3f(0.0F,0.0F,0.0F);
   
    @SuppressWarnings("static-access")
   public Display(String title,int fps)
    {
       this.fps_Max = 1.0/fps;
        this.title = title;
    }
   
    @SuppressWarnings("unused")
   public void create()
    {
        if(GLFW.glfwInit() == false)
        {
            Utils.engineError("GLFW failed to load", "could not boot right and returned false");
            System.exit(-1);
        }
        displayID = GLFW.glfwCreateWindow(width, height, title, 0, 0);
         if(displayID == 0)
        {
            Utils.engineError("failed to Create display", "check display class");
            System.exit(-1);
        }     
         GLFW.glfwMakeContextCurrent(displayID);
         
         GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
         GLFW.glfwSetWindowPos(displayID, (width / 12), (height / 10));
         
         GLFW.glfwShowWindow(displayID);
         GL.createCapabilities();
         
         time = getTime();
         
    }
   
    public void bufferSwap()
    {
       GLFW.glfwSwapBuffers(displayID);
    }
   
    //-------------------start--IO-----------------------------------
   
    public boolean getKeyDown(int KeyDown)
    {
       return GLFW.glfwGetKey(displayID, KeyDown) == 1;
    }
   
    public boolean getMouseDown(int MouseButton)
    {
       return GLFW.glfwGetMouseButton(displayID, 0) == 1;
    }
   
    public boolean isKeyDown(int keyCode)
    {
       return getKeyDown(keyCode) && keys[keyCode];
    }
   
    public boolean isKeyReleased(int keyCode)
    {
       return !getKeyDown(keyCode) && keys[keyCode];
    }
   
    public boolean isMouseButtonDown(int keyCode)
    {
       return getMouseDown(keyCode) && mouseButtons[keyCode];
    }
   
    public boolean isMouseButtonReleased(int keyCode)
    {
       return !isMouseButtonDown(keyCode) && mouseButtons[keyCode];
    }
   
    public double getMouseXPos()
    {
       DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
       GLFW.glfwGetCursorPos(displayID, buffer, null);
       return buffer.get(0);
       
    }
   
    public double getMouseYPos()
    {
       DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
       GLFW.glfwGetCursorPos(displayID, null, buffer);
       return buffer.get(0);
       
    }
   
    //-------------------end--IO---------------------------------------
   
    //-------------------FPS--CONTROL----------------------------------
    public double getTime()
    {
       return System.nanoTime() / 1000000000;
    }
   
    public boolean shouldUpdate()
    {
       double nextTime = getTime();
       double passedTime = nextTime - time;
       processedTime += passedTime;
       time = nextTime;
       while (processedTime > fps_Max)
       {
          processedTime -= fps_Max;
          return true;
       }
       return false;
    }
    //-------------END--FPS--CONTROL-------------------------------------
    public void update(int fps)
    {
       if(!(fps <= 30))
       {
       fps_Max = 1.0/fps;
       }
       for(int i = 0; i < GLFW.GLFW_KEY_LAST; i++)
       {
          keys = isKeyDown(i);
       }
       for(int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++)
       {
          mouseButtons = isMouseButtonDown(i);
       }
       GL11.glClearColor(color.x,color.y , color.z, 1.0F);
       GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
       GLFW.glfwPollEvents();
    }
   
    public boolean close()
    {
        return GLFW.glfwWindowShouldClose(displayID);
    }

   public static int getWidth() {
      return width;
   }

   public static int getHeight() {
      return height;
   }

   public static long getDisplayID() {
      return displayID;
   }

   public static String getTitle() {
      return title;
   }   
   
   
}