List of usage examples for org.lwjgl.opengl GL createCapabilities
public static GLCapabilities createCapabilities()
From source file:com.valkrix.engine.Application.java
License:Open Source License
public void start(String title, int width, int height, boolean fullscreen) { initContext();//w w w.j a va2 s. co m window = new Window(title, width, height, fullscreen); window.makeCurrent(); GL.createCapabilities(); init(); running = true; float delta = 1.0f / 60.0f; while (isRunning()) { update(delta); display(); window.swapBuffers(); glfwPollEvents(); } }
From source file:com.w67clement.openw67render.OpenContext.java
License:Open Source License
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(); long timer = System.currentTimeMillis(); // FPS/* w w w . ja v a 2s .co m*/ int frames = 0; TickThread tickThread = new TickThread(this); tickThread.start(); runnable.postInit(window, this); while ((!glfwWindowShouldClose(window.getWindowId()))) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer frames++; currentScreen.paint(currentScreen.getGraphics()); overlays.forEach(overlay -> overlay.paint(overlay.getGraphics())); if (System.currentTimeMillis() - timer > 1000) { timer += 1000; this.frames = frames; ticks = tickThread.resetTempTicks(); frames = 0; } glfwSwapBuffers(window.getWindowId()); // swap the color buffers // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents(); } isRunning = false; }
From source file:core.VisualClient.java
License:Open Source License
public void start() { long window;/* w ww . j a va 2s.com*/ /* Set the error callback */ glfwSetErrorCallback(errorCallback); /* Initialize GLFW */ if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } /* Create window */ window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); if (window == NULL) { glfwTerminate(); throw new RuntimeException("Failed to create the GLFW window"); } /* Center the window on screen */ GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidMode.width() - 640) / 2, (vidMode.height() - 480) / 2); /* Create OpenGL context */ glfwMakeContextCurrent(window); GL.createCapabilities(); /* Enable vertical synchronization */ glfwSwapInterval(1); /* Set the key callback */ glfwSetKeyCallback(window, keyCallback); /* Declare buffers for using inside the loop */ IntBuffer width = MemoryUtil.memAllocInt(1); IntBuffer height = MemoryUtil.memAllocInt(1); /* Loop until window gets closed */ while (!glfwWindowShouldClose(window)) { float ratio; /* Get width and height to calcualte the ratio */ glfwGetFramebufferSize(window, width, height); ratio = width.get() / (float) height.get(); /* Rewind buffers for next get */ width.rewind(); height.rewind(); /* Set viewport and clear screen */ glViewport(0, 0, width.get(), height.get()); glClear(GL_COLOR_BUFFER_BIT); /* Set ortographic projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-ratio, ratio, -1f, 1f, 1f, -1f); glMatrixMode(GL_MODELVIEW); /* Rotate matrix */ glLoadIdentity(); glRotatef((float) glfwGetTime() * 50f, 0f, 0f, 1f); /* Render triangle */ glBegin(GL_TRIANGLES); glColor3f(1f, 0f, 0f); glVertex3f(-0.6f, -0.4f, 0f); glColor3f(0f, 1f, 0f); glVertex3f(0.6f, -0.4f, 0f); glColor3f(0f, 0f, 1f); glVertex3f(0f, 0.6f, 0f); glEnd(); /* Swap buffers and poll Events */ glfwSwapBuffers(window); glfwPollEvents(); /* Flip buffers for next loop */ width.flip(); height.flip(); } /* Free buffers */ MemoryUtil.memFree(width); MemoryUtil.memFree(height); /* Release window and its callbacks */ glfwDestroyWindow(window); keyCallback.free(); /* Terminate GLFW and release the error callback */ glfwTerminate(); errorCallback.free(); }
From source file:cuchaz.jfxgl.prism.JFXGLContext.java
License:Open Source License
public void makeCurrent() { JFXGLContexts.makeCurrent(this); // if this is the first time, get the caps if (caps == null) { caps = GL.createCapabilities(); majorVersion = GL11.glGetInteger(GL30.GL_MAJOR_VERSION); minorVersion = GL11.glGetInteger(GL30.GL_MINOR_VERSION); }//from w w w .j av a2s . co m }
From source file:de.bwravencl.controllerbuddy.gui.OpenVrOverlay.java
License:Open Source License
private static void createGLCapabilitiesIfRequired() { GLCapabilities capabilities = null;/* w w w .j a va 2s . co m*/ try { capabilities = GL.getCapabilities(); } catch (final IllegalStateException e) { } if (capabilities == null) GL.createCapabilities(); }
From source file:displayManager.Display.java
public Display() { System.out.println("Display constructor"); errorCallback.createPrint().set();//from www . j a va 2 s .com //setup window if (glfwInit() != true) { throw new IllegalStateException("Unable to initialize GLFW"); } //set opengl context (3.2) glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); window = glfwCreateWindow(width, height, "Game Window", NULL, NULL); if (window == NULL) { glfwTerminate(); throw new RuntimeException("Failed to create the GLFW window"); } glfwSetKeyCallback(window, keyCallback = new KeyboardHandler()); glfwSetCursorPosCallback(window, mouseCallback = new MouseHandler()); glfwSetMouseButtonCallback(window, mouseButtonCallback = new MouseKeyHandler()); GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidMode.width() - width) / 2, (vidMode.height() - height) / 2); glfwMakeContextCurrent(window); GL.createCapabilities(); //glfwSwapInterval(1);//v-sync //glfwShowWindow(window); //input modes //Keyboard glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE); //Mouse glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);//Mouse cursor //GLFW_CURSOR_NORMAL is the default mode //GLFW_CURSOR_HIDDEN makes the cursor invisible if it is over the window //GLFW_CURSOR_DISABLED will capture the cursor to the window and hides it, useful if you want to make a mouse motion camera control glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, GLFW_TRUE); }
From source file:engine.logic.Multiplayer.java
License:Open Source License
private void renderLoop() { glfwMakeContextCurrent(window);/* w w w. j ava2 s .c o m*/ GL.createCapabilities(); glfwSwapInterval(0); //disable vsync debugProc = GLUtil.setupDebugMessageCallback(); scene = new Scene(); inputHandler = new InputHandler(window, scene); float deltaTime; long lastNanoTime = 0; long lastFpsNanoTime = 0; int fps = 0; long tempTime; while (!destroyed) { long time = System.nanoTime(); deltaTime = (float) (time - lastNanoTime) * 1e-9f; lastNanoTime = time; inputHandler.updateInput(deltaTime); scene.update(deltaTime); scene.render(deltaTime); limitFps(30); fps++; tempTime = time - lastFpsNanoTime; if (tempTime > 1000000000) { glfwSetWindowTitle(window, "FPS: " + fps + " Frametime: " + (float) ((tempTime / fps / 10000)) / 100 + "ms"); lastFpsNanoTime = time; fps = 0; } synchronized (lock) { if (!destroyed) { glfwSwapBuffers(window); } } } }
From source file:engine.logic.Singleplayer.java
License:Open Source License
private void renderLoop() { glfwMakeContextCurrent(window);/*from ww w . j a va 2s. c o m*/ GL.createCapabilities(); glfwSwapInterval(0); //disable vsync debugProc = GLUtil.setupDebugMessageCallback(); scene = new Scene(); inputHandler = new InputHandler(window, scene); float deltaTime; long lastNanoTime = 0; long lastFpsNanoTime = 0; int fps = 0; long tempTime; while (!glfwWindowShouldClose(window)) { long time = System.nanoTime(); deltaTime = (float) (time - lastNanoTime) * 1e-9f; lastNanoTime = time; inputHandler.updateInput(deltaTime); scene.update(deltaTime); scene.render(deltaTime); limitFps(70); fps++; tempTime = time - lastFpsNanoTime; if (tempTime > 1000000000) { glfwSetWindowTitle(window, "FPS: " + fps + " Frametime: " + (float) ((tempTime / fps / 10000)) / 100 + "ms"); lastFpsNanoTime = time; fps = 0; } glfwSwapBuffers(window); glfwPollEvents(); } }
From source file:Engine.rendering.Window.java
License:Apache License
public static void CreateWindow(int width, int height, String title) { // Initialise GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }/*from w ww. ja va2 s . co m*/ // Create the window window = glfwCreateWindow(width, height, title, NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } windowTitle = title; // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); //glfwSetWindowSizeCallback(window, WINDOW_SIZE_CALLBACK); glfwSetFramebufferSizeCallback(window, FRAMEBUFFER_SIZE_CALLBACK); // Make the OpenGL context current glfwMakeContextCurrent(window); // Make the window visible glfwShowWindow(window); GL.createCapabilities(); glViewport(0, 0, width, height); //NEW glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, 0, height, -1, 1); glfwSetKeyCallback(window, Input.GetKeyboardCallback()); glfwSetMouseButtonCallback(window, Input.GetMouseCallback()); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); }
From source file:es.rocammo.engine.Window.java
License:Open Source License
public Window() { // Initialize GLFW. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }//from w w w .j a va 2 s .com glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, 0, 0); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); } } }); // Get the resolution of the primary monitor GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center the window glfwSetWindowPos(windowHandle, (vidMode.width() - width) / 2, (vidMode.height() - height) / 2); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); // Enable v-sync if (isvSync()) glfwSwapInterval(1); // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.027f, 0.212f, 0.259f, 1.0f); }