List of usage examples for org.lwjgl.opengl GL createCapabilities
public static GLCapabilities createCapabilities()
From source file:fr.veridiangames.client.rendering.Display.java
License:Open Source License
private void init() { Log.println("glfwInit..."); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints();// w w w. j ava2s . co m glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); if (SystemUtils.isMac()) { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); } glfwWindowHint(GLFW_SAMPLES, 4); Log.println("glfwCreateWindow..."); window = glfwCreateWindow(width, height, title, NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); long monitor = glfwGetPrimaryMonitor(); if (monitor != 0) { Log.println("glfwSetWindowPos..."); GLFWVidMode vidmode = glfwGetVideoMode(monitor); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); } glfwDefaultWindowHints(); Log.println("glfw inputs callbacks..."); this.input = new Input(this); glfwSetKeyCallback(window, input.getKeyboardCallback()); glfwSetCharCallback(window, input.getTextInputCallback()); glfwSetKeyCallback(window, input.getKeyboardCallback()); glfwSetCursorPosCallback(window, input.getMouse().getCursorPosCallback()); glfwSetMouseButtonCallback(window, input.getMouse().getMouseButtonCallback()); glfwSetScrollCallback(window, input.getMouse().getScrollCallback()); Log.println("glfwMakeContextCurrent..."); glfwMakeContextCurrent(window); glfwShowWindow(window); Log.println("glfwSwapInterval..."); glfwSwapInterval(vsync ? 1 : 0); Log.println("GL.createCapabilities()..."); GL.createCapabilities(); Renderer.setDX11(); }
From source file:gamepadhandler.GamepadHandlerLWJGL.java
public void loop() throws InterruptedException { // 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(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GL11.glMatrixMode(GL_PROJECTION);/*from w w w. ja v a 2s . co m*/ GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, 0, HEIGHT, -1, 1); GL11.glMatrixMode(GL_MODELVIEW); GL11.glDisable(GL_DEPTH_TEST); GL11.glEnable(GL_BLEND); GL11.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); frameLooper.init(window, WIDTH, HEIGHT); boolean keepRunning = true; long currentTime = System.nanoTime(); // Run the rendering loop until the user has attempted to close // the window or has pressed the ESCAPE key. while (!glfwWindowShouldClose(window) && keepRunning) { long elapsedNanoTime; // Putting on a frame cap (of ~120fps when this comment was made) if (FPS_CAPPED) { while (System.nanoTime() - currentTime < minFrameWaitNanoTime) { Thread.sleep(2); } } elapsedNanoTime = System.nanoTime() - currentTime; currentTime = System.nanoTime(); glClear(GL_COLOR_BUFFER_BIT); // clear the framebuffer // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents(); // Where all the game logic is handled: keepRunning = frameLooper.frame(); glfwSwapBuffers(window); // swap the color buffers } }
From source file:game_test._Startup.java
public void init() { System.out.println("init"); //glfwSetErrorCallback(errorCallback); errorCallback.createPrint().set();/*from w ww . j ava 2s. c o m*/ //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, (window, key, scancode, action, mods) -> { //key-key pressed //action- GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT //mods- a bitfield of modifier keys //that were pressed, it can contain GLFW_MOD_SHIFT, //GLFW_MOD_CONTROL, GLFW_MOD_ALT and GLFW_MOD_SUPER ctrlDown = (mods & GLFW_MOD_CONTROL) != 0; if (action == GLFW_RELEASE) return; switch (key) { case GLFW_KEY_W: camera.move_forward(.8f); break; case GLFW_KEY_S: camera.move_backward(.8f); break; case GLFW_KEY_A: camera.move_left(.8f); break; case GLFW_KEY_D: camera.move_right(.8f); break; case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, true); break; case GLFW_KEY_KP_ADD: case GLFW_KEY_EQUAL: setScale(scale + 1); break; case GLFW_KEY_KP_SUBTRACT: case GLFW_KEY_MINUS: setScale(scale - 1); break; case GLFW_KEY_0: case GLFW_KEY_KP_0: if (ctrlDown) setScale(0); break; } }); glfwSetMouseButtonCallback(window, mouseButtonCallback = GLFWMouseButtonCallback.create((window, button, action, mods) -> { if (action == GLFW_RELEASE) return; switch (button) { case GLFW_MOUSE_BUTTON_1: } })); glfwSetCursorPosCallback(window, cursorPosCallback = GLFWCursorPosCallback.create((window, xpos, ypos) -> { //System.out.println("CursorPos: " + xpos + "," + ypos); camera.setYaw((float) (xpos / width) * 2f);//sensitivity camera.setPitch((float) (ypos / height) * 2f); return; })); GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidMode.width() - width) / 2, (vidMode.height() - height) / 2); glfwMakeContextCurrent(window); GL.createCapabilities(); //glfwSwapInterval(1);//v-sync //glfwShowWindow(window); //set callbacks //glfwSetKeyCallback(window, keyCallback); //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:graphics.Introduction.java
License:Open Source License
private static long createWindow() { long window;/*from w ww. ja 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(); glEnable(GL_DEPTH_TEST); /* Enable vertical synchronization */ glfwSwapInterval(1); /* Set the key callback */ glfwSetKeyCallback(window, keyCallback); return window; }
From source file:jacobgc.grafx.grafxngine.display.Display.java
License:Open Source License
public static void init() { if (GLFW.glfwInit() != GL11.GL_TRUE) { System.err.println("GLFW initialziation failed!"); }/*from w w w. j a v a 2s.c o m*/ GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GL11.GL_TRUE); window = GLFW.glfwCreateWindow(width, height, title, NULL, NULL); if (window == NULL) { System.err.println("Could not create the window!"); } GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); GLFW.glfwMakeContextCurrent(window); GL.createCapabilities(); GLFW.glfwShowWindow(window); }
From source file:javaapplication2.JavaApplication2.java
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(); // Set the clear color glClearColor(1.0f, 0.0f, 0.0f, 0.0f); // Run the rendering loop until the user has attempted to close // the window or has pressed the ESCAPE key. while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer glfwSwapBuffers(window); // swap the color buffers // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents();//from w ww .j av a 2 s .c o m } }
From source file:lwjglprojecto.LWJGLprojecto.java
private static void initGL() { GL.createCapabilities(); glMatrixMode(GL_PROJECTION);/*from w w w .jav a 2 s . co m*/ glLoadIdentity(); glOrtho(0, pWidth.get(0), 0, pHeight.get(0), -1, 1); glMatrixMode(GL_MODELVIEW); glClearColor(0.6f, 0.6f, 0.6f, 0.0f); glDisable(GL_DEPTH_TEST);//SOLO 2D }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
public void createWindow(int width, int height, String name) { this.width = width; this.height = height; glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err)); if (glfwInit() != GL11.GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); // optional, the current window hints are glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); // the window will stay // hidden/*from ww w .j av a2 s . c om*/ glfwWindowHint(GLFW_RESIZABLE, GL11.GL_TRUE); // the window will be // resizable window = glfwCreateWindow(width, height, name, NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); // glfwSetKeyCallback(window,this.keyCallback = keyCallback); glfwSetWindowSizeCallback(window, resizeCallback()); ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.asIntBuffer().get(0) - width) / 2, (vidmode.asIntBuffer().get(1) - height) / 2); glfwMakeContextCurrent(window); Graphic.instance = this; glfwSwapInterval(1); GL.createCapabilities(); setCapabilities(); glfwShowWindow(window); // Setup an XNA like background color GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0); // Map the internal OpenGL coordinate system to the entire screen GL11.glViewport(0, 0, width, height); matBuff = BufferUtils.createFloatBuffer(16); vaoId = GL30.glGenVertexArrays(); vboiId = GL15.glGenBuffers(); vboId = GL15.glGenBuffers(); tid_charmap = texManager.loadTexture("textures/charmap.png", GL13.GL_TEXTURE0); shader.setupShader(); // testQuad(); }
From source file:net.bryanbergen.lwjgl.display.Window.java
private void initGLFW() { if (GLFW.glfwInit() != GL_TRUE) { throw new IllegalStateException("Failed to initialize GLFW"); }/* w w w .java 2 s . c o m*/ GLFW.glfwDefaultWindowHints(); GLFW.glfwWindowHint(GLFW_VISIBLE, visible ? GL_TRUE : GL_FALSE); GLFW.glfwWindowHint(GLFW_RESIZABLE, resizable ? GL_TRUE : GL_FALSE); windowHandle = GLFW.glfwCreateWindow(dimension.getWidth(), dimension.getHeight(), title, fullscreen ? GLFW.glfwGetPrimaryMonitor() : NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to initialized GLFW Window"); } GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(windowHandle, (vidmode.width() - dimension.getWidth()) / 2, (vidmode.height() - dimension.getHeight()) / 2); GLFW.glfwMakeContextCurrent(windowHandle); initCallbacks(); GLFW.glfwSwapInterval(vsync ? 1 : 0); GL.createCapabilities(); GL11.glClearColor((float) background.getRed(), (float) background.getGreen(), (float) background.getBlue(), (float) background.getAlpha()); }
From source file:net.caseif.cubic.gl.GraphicsMain.java
License:Open Source License
private void initGLFW() { glfwSetErrorCallback(errorCallback); // set the error callback if (glfwInit() != GL_TRUE) { throw new IllegalStateException("Unable to initialize GLFW"); }/*from w ww . j a v a 2s .co m*/ glfwDefaultWindowHints(); // reset the window hints glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // make it unresizble glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // hide it until we're done initializing it glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // using OpenGL 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // use core profile window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Cubic", NULL, NULL); // create the window if (window == NULL) { throw new RuntimeException("Could not create GLFW window"); } glfwSetKeyCallback(window, keyCallback); keyListener = new KeyListener(window); mouseListener = new MouseListener(window); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // get the video mode of the primary monitor // center the window glfwSetWindowPos(window, (vidmode.width() - WINDOW_WIDTH) / 2, (vidmode.height() - WINDOW_HEIGHT) / 2); glfwMakeContextCurrent(window);// set the current context glfwSwapInterval(1); // enable vsync GL.createCapabilities(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); TEXTURE_REGISTRY.registerTextures(); try { ShaderHelper.initCameraShader(); } catch (IOException ex) { System.err.println("Failed to initialize shaders!"); ex.printStackTrace(); } float fov = 15f; float znear = 1f; float zfar = 10f; glUseProgram(ShaderHelper.cameraShader); Matrix4f prMatrix = MatrixHelper.perspective(znear, zfar, fov, (float) WINDOW_WIDTH / WINDOW_HEIGHT); glUniformMatrix4fv(glGetUniformLocation(ShaderHelper.cameraShader, "perspectiveMatrix"), false, prMatrix.toBuffer()); glUseProgram(0); // show the window glfwShowWindow(window); }