List of usage examples for org.lwjgl.opengl GL getCapabilities
public static GLCapabilities getCapabilities()
From source file:org.lwjgl.demo.nanovg.Demo.java
License:Open Source License
static void initGPUTimer(GPUtimer timer) { //memset(timer, 0, sizeof(*timer)); timer.supported = GL.getCapabilities().GL_ARB_timer_query; timer.cur = 0;/*from w w w . j a v a 2 s . co m*/ timer.ret = 0; BufferUtils.zeroBuffer(timer.queries); if (timer.supported) { glGenQueries(timer.queries); } }
From source file:org.lwjgl.demo.opengl.raytracing.Demo20.java
License:Open Source License
/** * Create the ray tracing shader program. * * @return that program id/*from w w w.j av a2 s . co m*/ * * @throws IOException */ private void createRayTracingProgram() throws IOException { String version = GL.getCapabilities().OpenGL30 ? "130" : null; int program = glCreateProgram(); int vshader = DemoUtils.createShader("org/lwjgl/demo/opengl/raytracing/quad110.vs", GL_VERTEX_SHADER); int fshader = DemoUtils.createShader("org/lwjgl/demo/opengl/raytracing/raytracing110.fs", GL_FRAGMENT_SHADER); int randomCommon = DemoUtils.createShader("org/lwjgl/demo/opengl/raytracing/randomCommon.glsl", GL_FRAGMENT_SHADER, version); int random = DemoUtils.createShader("org/lwjgl/demo/opengl/raytracing/random20.glsl", GL_FRAGMENT_SHADER); glAttachShader(program, vshader); glAttachShader(program, fshader); glAttachShader(program, randomCommon); glAttachShader(program, random); glBindAttribLocation(program, 0, "vertex"); glLinkProgram(program); int linked = glGetProgrami(program, GL_LINK_STATUS); String programLog = glGetProgramInfoLog(program); if (programLog.trim().length() > 0) { System.err.println(programLog); } if (linked == 0) { throw new AssertionError("Could not link program"); } this.rayTracingProgram = program; }
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"); }//from w w w. j a v a 2 s .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);// ww w .j a va2s. co 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); // 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.util.par.ParShapesDemo.java
License:Open Source License
private void init() { GLFWErrorCallback.createPrint().set(); if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }// w ww .j a va 2 s . c o m glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); window = glfwCreateWindow(width, height, "par_shapes demo", NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } glfwMakeContextCurrent(window); GL.createCapabilities(); debugCB = GLUtil.setupDebugMessageCallback(); if (debugCB != null && GL.getCapabilities().OpenGL43) { glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_OTHER, GL_DEBUG_SEVERITY_NOTIFICATION, (IntBuffer) null, false); } glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { if (action != GLFW_RELEASE) { return; } int scale; if ((mods & GLFW_MOD_CONTROL) != 0) { scale = 100; } else if ((mods & GLFW_MOD_SHIFT) != 0) { scale = 10; } else { scale = 1; } switch (key) { case GLFW_KEY_DOWN: if (slices > 3) { slices -= scale; if (slices < 3) { slices = 3; } updateMesh(); } break; case GLFW_KEY_UP: slices += scale; updateMesh(); break; case GLFW_KEY_LEFT: if (stacks > 1) { stacks -= scale; if (stacks < 1) { stacks = 1; } updateMesh(); } break; case GLFW_KEY_RIGHT: stacks += scale; updateMesh(); break; case GLFW_KEY_PAGE_DOWN: seed--; updateMesh(); break; case GLFW_KEY_PAGE_UP: seed++; updateMesh(); break; case GLFW_KEY_KP_SUBTRACT: if (subdivisions > 1) { subdivisions--; updateMesh(); } break; case GLFW_KEY_KP_ADD: subdivisions++; updateMesh(); break; case GLFW_KEY_1: case GLFW_KEY_2: case GLFW_KEY_3: case GLFW_KEY_4: case GLFW_KEY_5: case GLFW_KEY_6: case GLFW_KEY_7: case GLFW_KEY_8: updateMesh(key); break; case GLFW_KEY_E: if (mesh != null) { exportMesh(); } break; case GLFW_KEY_W: wireframe = !wireframe; updateHUD(); break; case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, true); break; } }); glfwSetFramebufferSizeCallback(window, (window, width, height) -> { this.width = width; this.height = height; updateViewport(width, height); }); // center window GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor())); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwShowWindow(window); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); updateViewport(width, height); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -3.0f); glRotatef(45.0f, 1.0f, 0.0f, 0.0f); vbo = glGenBuffers(); ibo = glGenBuffers(); hudVBO = glGenBuffers(); updateMesh(GLFW_KEY_1); int vshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vshader, "#version 110\n" + "\n" + "attribute vec3 position;\n" + "attribute vec3 normal;\n" + "\n" + "varying vec3 viewNormal;\n" + "\n" + "void main(void) {\n" + " viewNormal = gl_NormalMatrix * normal;\n" + " gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);\n" + "}\n"); glCompileShader(vshader); if (glGetShaderi(vshader, GL_COMPILE_STATUS) == GL_FALSE) { throw new IllegalStateException(glGetShaderInfoLog(vshader)); } int fshader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fshader, "#version 110\n" + "\n" + "varying vec3 viewNormal;\n" + "\n" + "void main(void) {\n" + " gl_FragColor = vec4(normalize(viewNormal), 1.0);\n" + "}\n"); glCompileShader(fshader); if (glGetShaderi(fshader, GL_COMPILE_STATUS) == GL_FALSE) { throw new IllegalStateException(glGetShaderInfoLog(fshader)); } program = glCreateProgram(); glAttachShader(program, vshader); glAttachShader(program, fshader); glBindAttribLocation(program, 0, "position"); glBindAttribLocation(program, 1, "normal"); glLinkProgram(program); if (glGetProgrami(program, GL_LINK_STATUS) == GL_FALSE) { throw new IllegalStateException(glGetProgramInfoLog(program)); } glDeleteShader(fshader); glDeleteShader(vshader); }
From source file:sgl.opengl.OpenGL.java
License:Open Source License
/** * Gets the state of OpenGL for the calling Thread. If an OpenGL context has been established for the calling * Thread, this method will return true, otherwise it will return false. * * @return true if an OpenGL context is initialized for this thread; false otherwise * @implNote the result of this method depends on the calling thread *//*ww w. j a v a2 s . c om*/ public static boolean initialized() { try { GL.getCapabilities(); return true; } catch (IllegalStateException e) { return false; } }
From source file:silvertiger.tutorial.lwjgl.core.Game.java
License:Open Source License
/** * Determines if the OpenGL context supports version 3.2. * * @return true, if OpenGL context supports version 3.2, else false *///from w w w .ja v a2 s . c om private boolean isDefaultContext() { return GL.getCapabilities().OpenGL32; }
From source file:silvertiger.tutorial.lwjgl.graphic.Window.java
License:Open Source License
/** * Creates a GLFW window and its OpenGL context with the specified width, * height and title.// w w w. j av a2 s . c om * * @param width Width of the drawing area * @param height Height of the drawing area * @param title Title of the window * @param vsync Set to true, if you want v-sync */ public Window(int width, int height, CharSequence title, boolean vsync) { this.vsync = vsync; /* Creating a temporary window for getting the available OpenGL version */ glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); long temp = glfwCreateWindow(1, 1, "", NULL, NULL); glfwMakeContextCurrent(temp); GLContext.createFromCurrent(); ContextCapabilities caps = GL.getCapabilities(); glfwDestroyWindow(temp); /* Reset and set window hints */ glfwDefaultWindowHints(); if (caps.OpenGL32) { /* Hints for OpenGL 3.2 core profile */ 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, GL_TRUE); } else if (caps.OpenGL21) { /* Hints for legacy OpenGL 2.1 */ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); } else { throw new RuntimeException("Neither OpenGL 3.2 nor OpenGL 2.1 is " + "supported, you may want to update your graphics driver."); } glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); /* Create window with specified OpenGL context */ id = glfwCreateWindow(width, height, title, NULL, NULL); if (id == NULL) { glfwTerminate(); throw new RuntimeException("Failed to create the GLFW window!"); } /* Center window on screen */ ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(id, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2); /* Create OpenGL context */ glfwMakeContextCurrent(id); GLContext.createFromCurrent(); /* Enable v-sync */ if (vsync) { glfwSwapInterval(1); } /* Set key callback */ keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { glfwSetWindowShouldClose(window, GL_TRUE); } } }; glfwSetKeyCallback(id, keyCallback); }