List of usage examples for org.lwjgl.opengl GL createCapabilities
public static GLCapabilities createCapabilities()
From source file:org.lwjgl.demo.opengl.textures.FullscreenCubemapDemo.java
License:Open Source License
void init() throws IOException { glfwSetErrorCallback(errCallback = new GLFWErrorCallback() { GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err); @Override/*from w w w . j av a 2s . c o m*/ public void invoke(int error, long description) { if (error == GLFW_VERSION_UNAVAILABLE) System.err.println("This demo requires OpenGL 1.1 or higher."); delegate.invoke(error, description); } @Override public void free() { delegate.free(); } }); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(width, height, "Cubemap texture sampling", NULL, NULL); if (window == NULL) { throw new AssertionError("Failed to create the GLFW window"); } glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (FullscreenCubemapDemo.this.width != width || FullscreenCubemapDemo.this.height != height)) { FullscreenCubemapDemo.this.width = width; FullscreenCubemapDemo.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); } } }); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwMakeContextCurrent(window); glfwSwapInterval(0); glfwShowWindow(window); IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4); width = framebufferSize.get(0); height = framebufferSize.get(1); caps = GL.createCapabilities(); String vendor = glGetString(GL_VENDOR); isCrappyIntel = vendor != null && vendor.toLowerCase().contains("intel"); 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."); } if (!caps.GL_ARB_texture_cube_map && !caps.OpenGL13) { throw new AssertionError("This demo requires the ARB_texture_cube_map extension or OpenGL 1.3."); } debugProc = GLUtil.setupDebugMessageCallback(); /* Create all needed GL resources */ createTexture(); createFullScreenQuad(); createProgram(); }
From source file:org.lwjgl.demo.opengl.textures.SimpleProceduralTextureDemo.java
License:Open Source License
private void init() { glfwSetErrorCallback(errCallback = GLFWErrorCallback.createPrint(System.err)); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints();//from w w w. ja v a2s . com glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(width, height, "Simple texture demo", NULL, NULL); if (window == NULL) { throw new AssertionError("Failed to create the GLFW window"); } glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (SimpleProceduralTextureDemo.this.width != width || SimpleProceduralTextureDemo.this.height != height)) { SimpleProceduralTextureDemo.this.width = width; SimpleProceduralTextureDemo.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); } } }); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwMakeContextCurrent(window); glfwShowWindow(window); IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4); width = framebufferSize.get(0); height = framebufferSize.get(1); caps = GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); String vendor = glGetString(GL_VENDOR); isCrappyIntel = vendor != null && vendor.toLowerCase().contains("intel"); /* Set state and create all needed GL resources */ glEnable(GL_TEXTURE_2D); int tex = glGenTextures(); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, (IntBuffer) null); glBindTexture(GL_TEXTURE_2D, tex); IntBuffer bb = BufferUtils.createIntBuffer(4 * 4); bb.put(new int[] { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }).rewind(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, bb); }
From source file:org.lwjgl.demo.opengl.textures.SimpleTexturedQuad.java
License:Open Source License
void init() throws IOException { glfwInit();//from w w w . j a v a 2 s. c o m glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); window = glfwCreateWindow(width, height, "Simple textured quad", NULL, NULL); glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() { public void invoke(long window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) glfwSetWindowShouldClose(window, true); } }); glfwMakeContextCurrent(window); glfwShowWindow(window); IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4); width = framebufferSize.get(0); height = framebufferSize.get(1); caps = GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); createTexture(); createQuadProgram(); createFullScreenQuad(); }
From source file:org.lwjgl.demo.opengl.textures.Texture2DArrayMipmapping.java
License:Open Source License
private void init() throws IOException { glfwSetErrorCallback(errCallback = new GLFWErrorCallback() { private GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err); @Override/* www. j a v a 2 s . co m*/ public void invoke(int error, long description) { if (error == GLFW_VERSION_UNAVAILABLE) System.err.println("This demo requires OpenGL 3.0 or higher."); delegate.invoke(error, description); } @Override public void free() { delegate.free(); } }); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(width, height, "Mipmapping with 2D array textures", NULL, NULL); if (window == NULL) { throw new AssertionError("Failed to create the GLFW window"); } glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (Texture2DArrayMipmapping.this.width != width || Texture2DArrayMipmapping.this.height != height)) { Texture2DArrayMipmapping.this.width = width; Texture2DArrayMipmapping.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); } } }); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwMakeContextCurrent(window); glfwSwapInterval(0); glfwShowWindow(window); caps = GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); /* Create all needed GL resources */ createTexture(); createVao(); createRasterProgram(); initProgram(); }
From source file:org.lwjgl.demo.opengl.UniformArrayDemo.java
License:Open Source License
private void init() throws IOException { glfwSetErrorCallback(errCallback = new GLFWErrorCallback() { private GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err); @Override/*ww w . j a va2s . co m*/ public void invoke(int error, long description) { if (error == GLFW_VERSION_UNAVAILABLE) System.err.println("This demo requires OpenGL 3.0 or higher."); delegate.invoke(error, description); } @Override public void free() { delegate.free(); } }); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(width, height, "Uniform array test", NULL, NULL); if (window == NULL) { throw new AssertionError("Failed to create the GLFW window"); } System.out.println("Press 'up' or 'down' to cycle through some colors."); glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { if (width > 0 && height > 0 && (UniformArrayDemo.this.width != width || UniformArrayDemo.this.height != height)) { UniformArrayDemo.this.width = width; UniformArrayDemo.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); } else if (key == GLFW_KEY_UP) { chosen = (chosen + 1) % 4; } else if (key == GLFW_KEY_DOWN) { chosen = (chosen + 3) % 4; } } }); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwMakeContextCurrent(window); glfwSwapInterval(0); glfwShowWindow(window); IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4); width = framebufferSize.get(0); height = framebufferSize.get(1); GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); /* Create all needed GL resources */ createVao(); createRasterProgram(); initProgram(); }
From source file:org.lwjgl.demo.stb.FontDemo.java
License:Open Source License
private void init(String title) { GLFWErrorCallback.createPrint().set(); if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }// w ww. j a v a2 s. c om glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); long monitor = glfwGetPrimaryMonitor(); int framebufferW; int framebufferH; try (MemoryStack s = stackPush()) { FloatBuffer px = s.mallocFloat(1); FloatBuffer py = s.mallocFloat(1); glfwGetMonitorContentScale(monitor, px, py); contentScaleX = px.get(0); contentScaleY = py.get(0); if (Platform.get() == Platform.MACOSX) { framebufferW = ww; framebufferH = wh; } else { framebufferW = round(ww * contentScaleX); framebufferH = round(wh * contentScaleY); } } this.window = glfwCreateWindow(framebufferW, framebufferH, title, NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } glfwSetWindowSizeCallback(window, this::windowSizeChanged); glfwSetFramebufferSizeCallback(window, FontDemo::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_PAGE_UP: setLineOffset(lineOffset - wh / FontDemo.this.lineHeight); break; case GLFW_KEY_PAGE_DOWN: setLineOffset(lineOffset + wh / FontDemo.this.lineHeight); break; case GLFW_KEY_HOME: setLineOffset(0); break; case GLFW_KEY_END: setLineOffset(lineCount - wh / FontDemo.this.lineHeight); 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; case GLFW_KEY_B: lineBBEnabled = !lineBBEnabled; break; case GLFW_KEY_K: kerningEnabled = !kerningEnabled; break; } }); glfwSetScrollCallback(window, (window, xoffset, yoffset) -> { if (ctrlDown) { setScale(scale + (int) round(yoffset)); } else { setLineOffset(lineOffset - (int) round(yoffset) * 3); } }); // Center window GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(monitor)); glfwSetWindowPos(window, (vidmode.width() - framebufferW) / 2, (vidmode.height() - framebufferH) / 2); // Create context glfwMakeContextCurrent(window); GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); glfwSwapInterval(1); glfwShowWindow(window); glfwInvoke(window, this::windowSizeChanged, FontDemo::framebufferSizeChanged); }
From source file:org.lwjgl.demo.stb.Image.java
License:Open Source License
private void init() { GLFWErrorCallback.createPrint().set(); if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }// w w w.ja v a2s .c om glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor())); ww = max(800, min(w, vidmode.width() - 160)); wh = max(600, min(h, vidmode.height() - 120)); this.window = glfwCreateWindow(ww, wh, "STB Image Demo", NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Center window glfwSetWindowPos(window, (vidmode.width() - ww) / 2, (vidmode.height() - wh) / 2); glfwSetWindowRefreshCallback(window, window -> render()); 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); } }); // Create context glfwMakeContextCurrent(window); GL.createCapabilities(); debugProc = GLUtil.setupDebugMessageCallback(); glfwSwapInterval(1); glfwShowWindow(window); glfwInvoke(window, this::windowSizeChanged, Image::framebufferSizeChanged); }
From source file:org.lwjgl.demo.stb.TruetypeOversample.java
License:Open Source License
private void createWindow(String title) { GLFWErrorCallback.createPrint().set(); if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }/* w w w . j a v a 2s . co m*/ 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"); } glfwSetWindowSizeCallback(window, this::windowSizeChanged); glfwSetFramebufferSizeCallback(window, this::framebufferSizeChanged); glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { if (action == GLFW_RELEASE) { return; } switch (key) { case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, true); break; case GLFW_KEY_O: font = (font + 1) % 3 + (font / 3) * 3; break; case GLFW_KEY_S: font = (font + 3) % 6; break; case GLFW_KEY_T: translating = !translating; translate_t = 0.0f; break; case GLFW_KEY_R: rotating = !rotating; rotate_t = 0.0f; break; case GLFW_KEY_P: integer_align = !integer_align; break; case GLFW_KEY_G: if (!supportsSRGB) { break; } srgb = !srgb; if (srgb) { glEnable(GL_FRAMEBUFFER_SRGB); } else { glDisable(GL_FRAMEBUFFER_SRGB); } break; case GLFW_KEY_V: show_tex = !show_tex; break; case GLFW_KEY_B: black_on_white = !black_on_white; break; } }); // 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, this::framebufferSizeChanged); // Detect sRGB support GLCapabilities caps = GL.getCapabilities(); supportsSRGB = caps.OpenGL30 || caps.GL_ARB_framebuffer_sRGB || caps.GL_EXT_framebuffer_sRGB; }
From source file:org.lwjgl.demo.stb.TrueTypeOversampleDemo.java
License:Open Source License
private void createWindow(String title) { glfwSetErrorCallback(errorfun);/*w w w .j av a 2 s . c om*/ 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); // 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, 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:org.lwjgl.demo.system.jawt.LWJGLCanvas.java
License:Open Source License
private void createContext(JAWTWin32DrawingSurfaceInfo dsi_win) { long hdc = dsi_win.hdc(); try (PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.calloc().nSize((byte) PIXELFORMATDESCRIPTOR.SIZEOF) .nVersion((short) 1).dwFlags(PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER) .iPixelType(PFD_TYPE_RGBA).cColorBits((byte) 32).cAlphaBits((byte) 8).cDepthBits((byte) 24) .iLayerType(PFD_MAIN_PLANE)) { int pixelFormat = GetPixelFormat(hdc); if (pixelFormat != 0) { if (DescribePixelFormat(hdc, pixelFormat, pfd) == 0) { throw new IllegalStateException("DescribePixelFormat() failed: " + WinBase.getLastError()); }// ww w . j a v a 2s .c o m } else { pixelFormat = ChoosePixelFormat(hdc, pfd); if (pixelFormat < 1) { throw new IllegalStateException("ChoosePixelFormat() failed: " + WinBase.getLastError()); } if (!SetPixelFormat(hdc, pixelFormat, null)) { throw new IllegalStateException("SetPixelFormat() failed: " + WinBase.getLastError()); } } } hglrc = wglCreateContext(hdc); if (hglrc == NULL) { throw new IllegalStateException("wglCreateContext() failed"); } if (!wglMakeCurrent(hdc, hglrc)) { throw new IllegalStateException("wglMakeCurrent() failed"); } caps = GL.createCapabilities(); }