List of usage examples for org.lwjgl.opengl GL createCapabilities
public static GLCapabilities createCapabilities()
From source file:Jexx.java
License:Open Source License
private void init() { // OpenAL stuff alcDevice = alcOpenDevice((ByteBuffer) null); alcContext = alcCreateContext(alcDevice, (IntBuffer) null); alcMakeContextCurrent(alcContext);/*from ww w . ja va2 s . co m*/ AL.createCapabilities(ALC.createCapabilities(alcDevice)); clickSource = loadAudioSource("click.ogg"); slideSource = loadAudioSource("slide.ogg"); popSource = loadAudioSource("pop.ogg"); // OpenGL stuff GLFWErrorCallback.createPrint(System.err).set(); if (!glfwInit()) { throw new IllegalStateException("glfwInit() failed"); } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(WIDTH, HEIGHT, "Jexx", NULL, NULL); if (window == NULL) { throw new RuntimeException("glfwCreateWindow() failed"); } glfwMakeContextCurrent(window); GL.createCapabilities(); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); glfwGetFramebufferSize(window, w, h); glViewport(0, 0, w.get(0), h.get(0)); glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); } else if (key == GLFW_KEY_RIGHT && action == GLFW_PRESS) { for (int i = 0; i < 5; ++i) { for (int j = 0; j < NUM_BLOCKS; ++j) { // swap color with block immediately to the left blocks[i][j].color += blocks[i + 1][j].color - (blocks[i + 1][j].color = blocks[i][j].color); } } rotationOffset -= Math.PI / 3; alSourcePlay(popSource); } else if (key == GLFW_KEY_LEFT && action == GLFW_PRESS) { for (int i = 4; i >= 0; --i) { for (int j = 0; j < NUM_BLOCKS; ++j) { // swap color with block immediately to the left blocks[i][j].color += blocks[i + 1][j].color - (blocks[i + 1][j].color = blocks[i][j].color); } } rotationOffset += Math.PI / 3; alSourcePlay(popSource); } }); glfwSwapInterval(1); // v-sync hex.compileShader(); hex.genVAO(); Block.compileShaders(); for (int i = 0; i < 6; ++i) { for (int j = 0; j < NUM_BLOCKS; ++j) { blocks[i][j] = new Block(); blocks[i][j].genVAO(i, j, GL_STATIC_DRAW); } } glfwShowWindow(window); }
From source file:TruetypeOversample.java
License:Open Source License
private void createWindow(String title) { glfwSetErrorCallback(errorfun);//from w w w .j a v a 2 s . c o m if (glfwInit() != GLFW_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); this.window = glfwCreateWindow(ww, wh, title, NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); windowSizefun.set(window); framebufferSizefun.set(window); keyfun.set(window); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - ww) / 2, (vidmode.height() - wh) / 2); glfwMakeContextCurrent(window); GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); glfwSwapInterval(1); glfwShowWindow(window); glfwInvoke(window, windowSizefun, framebufferSizefun); // Detect sRGB support GLCapabilities caps = GL.getCapabilities(); supportsSRGB = caps.OpenGL30 || caps.GL_ARB_framebuffer_sRGB || caps.GL_EXT_framebuffer_sRGB; }
From source file:RobotDemo.java
private void init() { GLFW.glfwInit();//w ww . j a va2 s.com window = GLFW.glfwCreateWindow(WIDTH, HEIGHT, "Robot Demo", 0, 0); GLFW.glfwMakeContextCurrent(window); GL.createCapabilities(); robots = new Robot[2]; robots[0] = new Robot(); robots[0].setColor(0.4f, 0.1f, 0.0f); robots[1] = new Robot(); robots[1].setColor(0.0f, 0.1f, 0.4f); selectedRobot = 0; GLFW.glfwSetKeyCallback(window, new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { if (key == GLFW.GLFW_KEY_ESCAPE) GLFW.glfwSetWindowShouldClose(window, GL11.GL_TRUE); if (key == GLFW.GLFW_KEY_P && action == GLFW.GLFW_PRESS) robots[selectedRobot].toggleBouncing(); if (key == GLFW.GLFW_KEY_H && action == GLFW.GLFW_PRESS) robots[selectedRobot].toggleSelected("HEAD"); if (key == GLFW.GLFW_KEY_N && action == GLFW.GLFW_PRESS) robots[selectedRobot].toggleSelected("NECK"); if (key == GLFW.GLFW_KEY_T && action == GLFW.GLFW_PRESS) robots[selectedRobot].toggleSelected("TORSO"); if (key == GLFW.GLFW_KEY_U && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("UPPER_RIGHT_ARM"); if (key == GLFW.GLFW_KEY_U && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("UPPER_LEFT_ARM"); if (key == GLFW.GLFW_KEY_L && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("LOWER_RIGHT_ARM"); if (key == GLFW.GLFW_KEY_L && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("LOWER_LEFT_ARM"); if (key == GLFW.GLFW_KEY_G && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("RIGHT_THIGH"); if (key == GLFW.GLFW_KEY_G && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("LEFT_THIGH"); if (key == GLFW.GLFW_KEY_C && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("RIGHT_CALF"); if (key == GLFW.GLFW_KEY_C && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT) robots[selectedRobot].toggleSelected("LEFT_CALF"); if (key == GLFW.GLFW_KEY_RIGHT && action != GLFW.GLFW_RELEASE) robots[selectedRobot].moveRight(); if (key == GLFW.GLFW_KEY_LEFT && action != GLFW.GLFW_RELEASE) robots[selectedRobot].moveLeft(); if (key == GLFW.GLFW_KEY_1 && action == GLFW.GLFW_PRESS) selectedRobot = 0; if (key == GLFW.GLFW_KEY_2 && action == GLFW.GLFW_PRESS) selectedRobot = 1; } }); }
From source file:EnvironmentTeapotDemo.java
License:Open Source License
void init() throws IOException { if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints();//w w w . jav a 2 s. c o m glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(width, height, "Spherical environment mapping with teapot demo", NULL, NULL); if (window == NULL) throw new AssertionError("Failed to create the GLFW window"); System.out.println("Move the mouse to look around"); System.out.println("Zoom in/out with mouse wheel"); glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (EnvironmentTeapotDemo.this.fbWidth != width || EnvironmentTeapotDemo.this.fbHeight != height)) { EnvironmentTeapotDemo.this.fbWidth = width; EnvironmentTeapotDemo.this.fbHeight = height; } } }); glfwSetWindowSizeCallback(window, wsCallback = new GLFWWindowSizeCallback() { @Override public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (EnvironmentTeapotDemo.this.width != width || EnvironmentTeapotDemo.this.height != height)) { EnvironmentTeapotDemo.this.width = width; EnvironmentTeapotDemo.this.height = height; } } }); glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { if (action != GLFW_RELEASE) return; if (key == GLFW_KEY_ESCAPE) { glfwSetWindowShouldClose(window, true); } } }); glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() { @Override public void invoke(long window, double x, double y) { float nx = (float) x / width * 2.0f - 1.0f; float ny = (float) y / height * 2.0f - 1.0f; rotX = ny * (float) Math.PI * 0.5f; rotY = nx * (float) Math.PI; } }); glfwSetScrollCallback(window, sCallback = new GLFWScrollCallback() { @Override public void invoke(long window, double xoffset, double yoffset) { if (yoffset < 0) fov *= 1.05f; else fov *= 1f / 1.05f; if (fov < 10.0f) fov = 10.0f; else if (fov > 120.0f) fov = 120.0f; } }); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwMakeContextCurrent(window); glfwSwapInterval(0); glfwShowWindow(window); glfwSetCursorPos(window, width / 2, height / 2); IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4); fbWidth = framebufferSize.get(0); fbHeight = framebufferSize.get(1); caps = GL.createCapabilities(); if (!caps.GL_ARB_shader_objects) throw new AssertionError("This demo requires the ARB_shader_objects extension."); if (!caps.GL_ARB_vertex_shader) throw new AssertionError("This demo requires the ARB_vertex_shader extension."); if (!caps.GL_ARB_fragment_shader) throw new AssertionError("This demo requires the ARB_fragment_shader extension."); debugProc = GLUtil.setupDebugMessageCallback(); /* Create all needed GL resources */ loadMesh(); createTexture(); createFullScreenQuad(); createTeapotProgram(); createEnvironmentProgram(); }
From source file:Image.java
private void init() { GLFWErrorCallback.createPrint().set(); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints();/*from ww w. j av a2 s. c o m*/ glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); this.window = glfwCreateWindow(ww, wh, "STB Image Demo", NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); glfwSetWindowSizeCallback(window, this::windowSizeChanged); glfwSetFramebufferSizeCallback(window, Image::framebufferSizeChanged); glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { ctrlDown = (mods & GLFW_MOD_CONTROL) != 0; if (action == GLFW_RELEASE) return; switch (key) { 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; } }); glfwSetScrollCallback(window, (window, xoffset, yoffset) -> { if (ctrlDown) setScale(scale + (int) yoffset); }); // Center window GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - ww) / 2, (vidmode.height() - wh) / 2); // Create context glfwMakeContextCurrent(window); GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); glfwSwapInterval(1); glfwShowWindow(window); //glfwInvoke(window, this::windowSizeChanged, Image::framebufferSizeChanged); }
From source file:SpaceGame.java
License:Open Source License
private void init() throws IOException { if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints();/* w ww. j av a 2s .c o m*/ glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); glfwWindowHint(GLFW_SAMPLES, 4); long monitor = glfwGetPrimaryMonitor(); GLFWVidMode vidmode = glfwGetVideoMode(monitor); if (!windowed) { width = vidmode.width(); height = vidmode.height(); fbWidth = width; fbHeight = height; } window = glfwCreateWindow(width, height, "Little Space Shooter Game", !windowed ? monitor : 0L, NULL); if (window == NULL) { throw new AssertionError("Failed to create the GLFW window"); } glfwSetCursor(window, glfwCreateStandardCursor(GLFW_CROSSHAIR_CURSOR)); glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() { public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (SpaceGame.this.fbWidth != width || SpaceGame.this.fbHeight != height)) { SpaceGame.this.fbWidth = width; SpaceGame.this.fbHeight = height; } } }); glfwSetWindowSizeCallback(window, wsCallback = new GLFWWindowSizeCallback() { public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (SpaceGame.this.width != width || SpaceGame.this.height != height)) { SpaceGame.this.width = width; SpaceGame.this.height = height; } } }); System.out.println("Press W/S to move forward/backward"); System.out.println("Press L.Ctrl/Spacebar to move down/up"); System.out.println("Press A/D to strafe left/right"); System.out.println("Press Q/E to roll left/right"); System.out.println("Hold the left mouse button to shoot"); System.out.println("Hold the right mouse button to rotate towards the mouse cursor"); glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() { public void invoke(long window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_UNKNOWN) return; if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); } if (action == GLFW_PRESS || action == GLFW_REPEAT) { keyDown[key] = true; } else { keyDown[key] = false; } } }); glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() { public void invoke(long window, double xpos, double ypos) { float normX = (float) ((xpos - width / 2.0) / width * 2.0); float normY = (float) ((ypos - height / 2.0) / height * 2.0); SpaceGame.this.mouseX = Math.max(-width / 2.0f, Math.min(width / 2.0f, normX)); SpaceGame.this.mouseY = Math.max(-height / 2.0f, Math.min(height / 2.0f, normY)); } }); glfwSetMouseButtonCallback(window, mbCallback = new GLFWMouseButtonCallback() { public void invoke(long window, int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_LEFT) { if (action == GLFW_PRESS) leftMouseDown = true; else if (action == GLFW_RELEASE) leftMouseDown = false; } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { if (action == GLFW_PRESS) rightMouseDown = true; else if (action == GLFW_RELEASE) rightMouseDown = false; } } }); glfwMakeContextCurrent(window); glfwSwapInterval(0); glfwShowWindow(window); IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4); fbWidth = framebufferSize.get(0); fbHeight = framebufferSize.get(1); caps = GL.createCapabilities(); if (!caps.OpenGL20) { throw new AssertionError("This demo requires OpenGL 2.0."); } debugProc = GLUtil.setupDebugMessageCallback(); /* Create all needed GL resources */ createCubemapTexture(); createFullScreenQuad(); createCubemapProgram(); createShipProgram(); createParticleProgram(); createShip(); createAsteroid(); createShotProgram(); createSphere(); glEnableClientState(GL_VERTEX_ARRAY); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE); }
From source file:UtilsLWJGL.java
License:Open Source License
/** * Do whatever is necessary to open a GLFW window. This code is heavily * based on code from lwjgl3-demo-master. * /* www. j a v a2 s . c o m*/ * @author rdb * @par:am winW int width of window to create * @param winH * int height of window * @param int * openglMajor major version # for opengl * @param int * openglMinor minor version # for opengl * @return int window Id for created window * * Returns the window id. */ public static long openWindow(String title, int winW, int winH, int openglMajor, int openglMinor) { long windowId = NULL; // NULL is defined in glfw. // Initialize GLFW. Most GLFW functions won't before doing this. if (!glfwInit()) // rdb 8 throw new IllegalStateException("Unable to initialize GLFW"); // Configure our window glfwWindowHint(GLFW_VISIBLE, GL_TRUE); // window visible after create glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // window is resizable glfwWindowHint(GLFW_DEPTH_BITS, 32); // is this needed for depth // ---- next two are critical --------- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 09/10/15: Mac OS/X, Windows, and Linux all support 3.3! // 09/22/15: Well, kind of ??? while (openglMajor > 1 && windowId == NULL) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, openglMajor); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, openglMinor); // Create the window windowId = glfwCreateWindow(winW, winH, title, NULL, NULL); if (windowId == NULL) { System.err.println("GLFW window creation failed for Open GL " + openglMajor + "." + openglMinor); if (openglMinor > 0) openglMinor--; else { openglMinor = 5; // a hack; this means we'll miss 3.6+ etc openglMajor--; } } } if (windowId == NULL) { throw new RuntimeException("Failed to create the GLFW window: "); } // Get the resolution of the primary monitor GLFWVidMode vmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); int centerX = (vmode.width() - winW) / 2; int centerY = (vmode.height() - winH) / 2; // Center our window glfwSetWindowPos(windowId, centerX, centerY); // Make the OpenGL context current glfwMakeContextCurrent(windowId); // rdb: true => forward compatible; do not use forward compatibility GL.createCapabilities(); // Enable v-sync glfwSwapInterval(0); String glv = glGetString(GL_VERSION); System.err.println("*** Using GL version: " + glv); glfwShowWindow(windowId); return windowId; }
From source file:analog.clock.AnalogClock.java
private void init() { GLFW.glfwInit();/* w w w . j a v a 2 s . c o m*/ window = GLFW.glfwCreateWindow(600, 600, "Analog Clock", 0, 0); GLFW.glfwMakeContextCurrent(window); GL.createCapabilities(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GLFW.glfwSwapBuffers(window); }
From source file:ar.com.quark.backend.lwjgl.system.DesktopDisplay.java
License:Apache License
/** * <p>Handle when the module create</p> *///from w w w . ja v a 2 s . co m public void onModuleCreate(Display.Preference preference, GLFWFramebufferSizeCallback resize, GLFWWindowIconifyCallback iconify) { if (GLFW.glfwInit()) { final DisplayMode mode = preference.getMode(); //! //! Fill each window hint from the configuration. //! GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, preference.isResizable() ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, preference.isDecorated() ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_SRGB_CAPABLE, preference.isSRGB() ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, preference.getSamples()); if (preference.isFullscreen()) { GLFW.glfwWindowHint(GLFW.GLFW_REFRESH_RATE, mode.getRate()); mHandle = GLFW.glfwCreateWindow(mode.getWidth(), mode.getHeight(), preference.getTitle(), GLFW.glfwGetPrimaryMonitor(), mHandle); if (mHandle == MemoryUtil.NULL) { throw new RuntimeException("Pixel-format not accelerated"); } } else { mHandle = GLFW.glfwCreateWindow(mode.getWidth(), mode.getHeight(), preference.getTitle(), MemoryUtil.NULL, mHandle); if (mHandle == MemoryUtil.NULL) { throw new RuntimeException("Pixel-format not accelerated"); } //! //! Center window on windowed mode. //! final GLFWVidMode video = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(mHandle, (video.width() - mode.getWidth()) / 2, (video.height() - mode.getHeight()) / 2); } setSynchronised(preference.isSynchronised()); //! //! Attach resizable and iconify callback. //! GLFW.glfwSetFramebufferSizeCallback(mHandle, resize); GLFW.glfwSetWindowIconifyCallback(mHandle, iconify); //! //! Initialise the context for OpenGL. //! GLFW.glfwMakeContextCurrent(mHandle); GL.createCapabilities(); } }
From source file:bd.ac.seu.lwjgldemo.Renderer.java
private void init() { System.out.println("LWJGL version " + Version.getVersion()); if (!GLFW.glfwInit()) { throw new IllegalStateException("Could not initialize GLFW"); }//from w w w . ja v a 2 s . com window = GLFW.glfwCreateWindow(800, 800, "VAO VBO Demo", 0, 0); GLFW.glfwMakeContextCurrent(window); GLFW.glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { if (key == GLFW.GLFW_KEY_ESCAPE) { GLFW.glfwSetWindowShouldClose(window, true); } }); GL.createCapabilities(); setupModel(); GLFW.glfwShowWindow(window); }