List of usage examples for org.lwjgl.opengl GL createCapabilities
public static GLCapabilities createCapabilities()
From source file:com.goosejs.tester.MandleBrot.java
License:Open Source License
public MandleBrot(long platform, CLCapabilities platformCaps, GLFWWindow window, int deviceType, boolean debugGL, int maxIterations) { this.platform = platform; this.window = window; this.maxIterations = maxIterations; IntBuffer size = BufferUtils.createIntBuffer(2); nglfwGetWindowSize(window.handle, memAddress(size), memAddress(size) + 4); ww = size.get(0);//from w w w . j av a 2 s.c om wh = size.get(1); nglfwGetFramebufferSize(window.handle, memAddress(size), memAddress(size) + 4); fbw = size.get(0); fbh = size.get(1); glfwMakeContextCurrent(window.handle); GLCapabilities glCaps = GL.createCapabilities(); if (!glCaps.OpenGL30) throw new RuntimeException("OpenGL 3.0 is required to run this demo."); debugProc = debugGL ? GLUtil.setupDebugMessageCallback() : null; glfwSwapInterval(0); errcode_ret = BufferUtils.createIntBuffer(1); try { // Find devices with GL sharing support { long device = getDevice(platform, platformCaps, deviceType); if (device == NULL) device = getDevice(platform, platformCaps, CL_DEVICE_TYPE_CPU); if (device == NULL) throw new RuntimeException("No OpenCL devices found with OpenGL sharing support."); this.device = device; this.deviceCaps = CL.createDeviceCapabilities(device, platformCaps); } // Create the context PointerBuffer ctxProps = BufferUtils.createPointerBuffer(7); switch (Platform.get()) { case WINDOWS: ctxProps.put(CL_GL_CONTEXT_KHR).put(glfwGetWGLContext(window.handle)).put(CL_WGL_HDC_KHR) .put(wglGetCurrentDC()); break; case LINUX: ctxProps.put(CL_GL_CONTEXT_KHR).put(glfwGetGLXContext(window.handle)).put(CL_GLX_DISPLAY_KHR) .put(glfwGetX11Display()); break; case MACOSX: ctxProps.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE) .put(CGLGetShareGroup(CGLGetCurrentContext())); } ctxProps.put(CL_CONTEXT_PLATFORM).put(platform).put(NULL).flip(); clContext = clCreateContext(ctxProps, device, clContextCB = CLContextCallback.create((errinfo, private_info, cb, user_data) -> log(String.format("cl_context_callback\n\tInfo: %s", memUTF8(errinfo)))), NULL, errcode_ret); checkCLError(errcode_ret); // create command queues for every GPU, setup colormap and init kernels IntBuffer colorMapBuffer = BufferUtils.createIntBuffer(32 * 2); initColorMap(colorMapBuffer, 32, Color.BLUE, Color.GREEN, Color.RED); clColorMap = clCreateBuffer(clContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, colorMapBuffer, errcode_ret); checkCLError(errcode_ret); // create command queue and upload color map buffer clQueue = clCreateCommandQueue(clContext, device, NULL, errcode_ret); checkCLError(errcode_ret); // load program(s) if (deviceType == CL_DEVICE_TYPE_GPU) log("OpenCL Device Type: GPU (Use -forceCPU to use CPU)"); else log("OpenCL Device Type: CPU"); log("Max Iterations: " + maxIterations + " (Use -iterations <count> to change)"); log("Display resolution: " + ww + "x" + wh + " (Use -res <width> <height> to change)"); log("OpenGL glCaps.GL_ARB_sync = " + glCaps.GL_ARB_sync); log("OpenGL glCaps.GL_ARB_cl_event = " + glCaps.GL_ARB_cl_event); buildProgram(); // Detect GLtoCL synchronization method syncGLtoCL = !glCaps.GL_ARB_cl_event; // GL3.2 or ARB_sync implied log(syncGLtoCL ? "GL to CL sync: Using clFinish" : "GL to CL sync: Using OpenCL events"); // Detect CLtoGL synchronization method syncCLtoGL = !deviceCaps.cl_khr_gl_event; log(syncCLtoGL ? "CL to GL sync: Using glFinish" : "CL to GL sync: Using implicit sync (cl_khr_gl_event)"); vao = glGenVertexArrays(); glBindVertexArray(vao); vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, stackPush().floats(0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f), GL_STATIC_DRAW); stackPop(); vsh = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vsh, "#version 150\n" + "\n" + "uniform mat4 projection;\n" + "\n" + "uniform vec2 size;\n" + "\n" + "in vec2 posIN;\n" + "in vec2 texIN;\n" + "\n" + "out vec2 texCoord;\n" + "\n" + "void main(void) {\n" + "\tgl_Position = projection * vec4(posIN * size, 0.0, 1.0);\n" + "\ttexCoord = texIN;\n" + "}"); glCompileShader(vsh); String log = glGetShaderInfoLog(vsh, glGetShaderi(vsh, GL_INFO_LOG_LENGTH)); if (!log.isEmpty()) log(String.format("VERTEX SHADER LOG: %s", log)); fsh = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fsh, "#version 150\n" + "\n" + "uniform isampler2D mandelbrot;\n" + "\n" + "in vec2 texCoord;\n" + "\n" + "out vec4 fragColor;\n" + "\n" + "void main(void) {\n" + "\tfragColor = texture(mandelbrot, texCoord) / 255.0;\n" + "}"); glCompileShader(fsh); log = glGetShaderInfoLog(fsh, glGetShaderi(fsh, GL_INFO_LOG_LENGTH)); if (!log.isEmpty()) log(String.format("FRAGMENT SHADER LOG: %s", log)); glProgram = glCreateProgram(); glAttachShader(glProgram, vsh); glAttachShader(glProgram, fsh); glLinkProgram(glProgram); log = glGetProgramInfoLog(glProgram, glGetProgrami(glProgram, GL_INFO_LOG_LENGTH)); if (!log.isEmpty()) log(String.format("PROGRAM LOG: %s", log)); int posIN = glGetAttribLocation(glProgram, "posIN"); int texIN = glGetAttribLocation(glProgram, "texIN"); glVertexAttribPointer(posIN, 2, GL_FLOAT, false, 4 * 4, 0); glVertexAttribPointer(texIN, 2, GL_FLOAT, false, 4 * 4, 2 * 4); glEnableVertexAttribArray(posIN); glEnableVertexAttribArray(texIN); projectionUniform = glGetUniformLocation(glProgram, "projection"); sizeUniform = glGetUniformLocation(glProgram, "size"); glUseProgram(glProgram); glUniform1i(glGetUniformLocation(glProgram, "mandelbrot"), 0); } catch (Exception e) { // TODO: cleanup throw new RuntimeException(e); } glDisable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); initGLObjects(); glFinish(); setKernelConstants(); glfwSetWindowSizeCallback(window.handle, (windowHandle, width, height) -> { if (width == 0 || height == 0) return; events.add(() -> { this.ww = width; this.wh = height; shouldInitBuffers = true; }); }); glfwSetFramebufferSizeCallback(window.handle, (windowHandle, width, height) -> { if (width == 0 || height == 0) return; events.add(() -> { this.fbw = width; this.fbh = height; shouldInitBuffers = true; }); }); glfwSetKeyCallback(window.handle, (windowHandle, key, scancode, action, mods) -> { switch (key) { case GLFW_KEY_LEFT_CONTROL: case GLFW_KEY_RIGHT_CONTROL: ctrlDown = action == GLFW_PRESS; return; } if (action != GLFW_PRESS) return; switch (key) { case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(windowHandle, true); break; case GLFW_KEY_D: events.offer(() -> { doublePrecision = !doublePrecision; log("DOUBLE PRECISION IS NOW: " + (doublePrecision ? "ON" : "OFF")); rebuild = true; }); break; case GLFW_KEY_HOME: events.offer(() -> { offsetX = -0.5; offsetY = 0.0; zoom = 1.0; }); break; } }); glfwSetMouseButtonCallback(window.handle, (windowHandle, button, action, mods) -> { if (button != GLFW_MOUSE_BUTTON_LEFT) return; dragging = action == GLFW_PRESS; if (dragging) { dragging = true; dragX = mouseX; dragY = mouseY; dragOffsetX = offsetX; dragOffsetY = offsetY; } }); glfwSetCursorPosCallback(window.handle, (windowHandle, xpos, ypos) -> { mouseX = xpos; mouseY = wh - ypos; if (dragging) { offsetX = dragOffsetX + transformX(dragX - mouseX); offsetY = dragOffsetY + transformY(dragY - mouseY); } }); glfwSetScrollCallback(window.handle, (windowHandle, xoffset, yoffset) -> { if (yoffset == 0) return; double scrollX = mouseX - ww * 0.5; double scrollY = mouseY - wh * 0.5; double zoomX = transformX(scrollX); double zoomY = transformY(scrollY); zoom *= (1.0 - yoffset * (ctrlDown ? 0.25 : 0.05)); offsetX += zoomX - transformX(scrollX); offsetY += zoomY - transformY(scrollY); }); }
From source file:com.jtransc.media.lwjgl.JTranscLwjgl.java
License:Apache License
static private void init(final Runnable init) { glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err)); // Initialize GLFW. Most GLFW functions will not work before doing this. if (glfwInit() != GLFW_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); // Configure our window glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable int WIDTH = 640; int HEIGHT = 480; // Create the window window = glfwCreateWindow(WIDTH, HEIGHT, "JTransc " + JTranscVersion.getVersion(), NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); // 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, windowSizeCallback = new GLFWWindowSizeCallback() { @Override// w ww . jav a2s .com public void invoke(long window, int width, int height) { updatedScreenSize(); if (JTranscLwjgl.r_render != null) { JTranscLwjgl.r_render.run(); } } }); // Make the OpenGL context current glfwMakeContextCurrent(window); // Enable v-sync glfwSwapInterval(1); // Make the window visible glfwShowWindow(window); GL.createCapabilities(); JTranscRender.impl = new LwjglRenderer(window); JTranscAudio.impl = new LwjglAudio(); LwjglInput.config(window); if (init != null) init.run(); }
From source file:com.kudodev.knimble.demo.utils.RenderLoop.java
License:Apache License
private void init() { GLFWErrorCallback.createPrint(System.err).set(); if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); }/*ww w . j a v a2 s .c o m*/ // Configure GLFW glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Create the window window = glfwCreateWindow(windowWidth, windowHeight, title, NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); } }); try (MemoryStack stack = stackPush()) { IntBuffer pWidth = stack.mallocInt(1); IntBuffer pHeight = stack.mallocInt(1); glfwGetWindowSize(window, pWidth, pHeight); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2); } glfwMakeContextCurrent(window); glfwSwapInterval(GLFW_TRUE); // vsync glfwShowWindow(window); GL.createCapabilities(); }
From source file:com.opengg.module.swt.window.GGCanvas.java
@Override public void setup(WindowInfo window) { GLData data = new GLData(); data.api = API.GL;// w w w . ja v a 2 s . c om data.majorVersion = 4; data.minorVersion = 1; data.samples = 1; data.redSize = window.rbit; data.blueSize = window.bbit; data.greenSize = window.gbit; data.profile = Profile.CORE; data.swapInterval = window.vsync ? 1 : 0; data.forwardCompatible = true; shell.getDisplay().syncExec(() -> { canvas = new GLCanvas(shell, SWT.NO_BACKGROUND | (window.resizable ? SWT.RESIZE : SWT.NO_REDRAW_RESIZE), data); canvas.setSize(window.width, window.height); id = canvas.context; canvas.addKeyListener(keyCallback = new SWTKeyboardHandler()); canvas.addMouseMoveListener(mousePosCallback = new SWTMousePosHandler()); canvas.addMouseListener(mouseCallback = new SWTMouseButtonHandler()); KeyboardController.setHandler(keyCallback); MouseController.setPosHandler(mousePosCallback); MouseController.setButtonHandler(mouseCallback); }); canvas.setCurrent(); GL.createCapabilities(); if (glGetError() == GL_NO_ERROR) { success = true; } else throw new WindowCreationException("OpenGL initialization during window creation failed"); }
From source file:com.opengrave.og.MainThread.java
License:Open Source License
protected void initGL() { if (glfwInit() != GLFW_TRUE) { System.exit(1);//from w ww. java2s. co m } glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(800, 600, "HiddenGrave", NULL, NULL); if (window == NULL) { System.exit(1); } glfwMakeContextCurrent(window); glfwSwapInterval(1); // TODO condig of vsync. Enable vsync GL.createCapabilities(); glfwSetFramebufferSizeCallback(window, (framebufferSizeCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { onResize(width, height); } })); onResize(800, 600); // TODO Check all extensions. TEX 2D ARRAY, GLSL 130 createConfig(); Util.initMatrices(); Renderable.init(); GUIXML.init(); // Prepare Lighting initLighting(); // Default Values GL11.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // sets background to grey Util.checkErr(); GL11.glClearDepth(1.0f); // clear depth buffer Util.checkErr(); GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables depth testing Util.checkErr(); GL11.glDepthFunc(GL11.GL_LEQUAL); // sets the type of test to use for // depth testing GL11.glEnable(GL11.GL_BLEND); Resources.loadTextures(); // Reconsider positioning. Other than GUI // texture we could offset these in another // thread... Possibly? Resources.loadModels(); Resources.loadFonts(); }
From source file:com.repestat.main.HelloWorld.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(2.0f, 0.4f, 0.4f, 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 3D glfwSwapBuffers(window); // swap the color buffers // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents();/*from w w w.ja v a2 s . com*/ } }
From source file:com.samrj.devil.game.Game.java
License:Open Source License
/** * Creates a new game object. Initializes the window with the given config. * //from w w w .j ava 2s. co m * @param title The title of the window. * @param hints The window hints to use. * @param config The configuration to use. */ public Game(String title, HintSet hints, GameConfig config) { if (title == null || config == null) throw new NullPointerException(); if (!initialized) throw new IllegalStateException("Game.init() not called."); ensureMainThread(); // <editor-fold defaultstate="collapsed" desc="Initialize Window"> { GLFW.glfwDefaultWindowHints(); GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, config.borderless ? GL11.GL_FALSE : GL11.GL_TRUE); GLFW.glfwWindowHint(GLFW.GLFW_FLOATING, GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_STENCIL_BITS, 0); if (config.msaa > 0) GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, config.msaa); if (hints != null) hints.glfw(); GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_DEBUG_CONTEXT, GL11.GL_TRUE); monitor = config.fullscreen ? GLFW.glfwGetPrimaryMonitor() : 0; window = GLFW.glfwCreateWindow(config.resolution.x, config.resolution.y, title, monitor, 0); GLFW.glfwMakeContextCurrent(window); GLFW.glfwSwapInterval(config.vsync ? 1 : 0); GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED); } if (!config.fullscreen) //Center window { Vec2i windowSize = GLFWUtil.getWindowSize(window); GLFWVidMode mode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(window, (mode.width() - windowSize.x) / 2, (mode.height() - windowSize.y) / 2); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initialize OpenGL Context"> { capabilities = GL.createCapabilities(); GL11.glViewport(0, 0, config.resolution.x, config.resolution.y); GL11.glDisable(GL13.GL_MULTISAMPLE); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initialize Sync"> { if (!config.vsync && config.fps > 0) { sync = new Sync(config.fps, config.sleeper); frameTime = sync.getFrameTime(); } else { sync = null; GLFWVidMode mode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); frameTime = Math.round(1_000_000_000.0 / mode.refreshRate()); } } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initialize Input"> { mouse = new Mouse(window, this::onMouseMoved, this::onMouseButton, this::onMouseScroll); mouse.setGrabbed(false); keyboard = new Keyboard(this::onKey); eventBuffer = new EventBuffer(window, mouse, keyboard); } // </editor-fold> stepper = config.stepper; }
From source file:com.swinggl.elements.GLFrame.java
License:Open Source License
/** * This method starts the both the render and update loops. The thread that this is called on will become the render loop and occupy that thread entirely. * All glfwWindowHint's must be called before this is called while all other window attributes can be altered while the loop is running including changing * the FPS and UPS.//from w w w.j a va2s .c o m */ public void run() { if (fullscreen) { window = glfwCreateWindow(windowWidth, windowHeight, title, glfwGetPrimaryMonitor(), secondWindowHandle); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); if (!(windowWidth == vidmode.width() && windowHeight == vidmode.height())) { Debug.println("GLFWVidMode [" + windowWidth + ", " + windowHeight + "] not available, switching to GLFWVidMode [" + vidmode.width() + ", " + vidmode.height() + "]", Debug.ANSI_YELLOW); windowWidth = vidmode.width(); windowHeight = vidmode.height(); } } else window = glfwCreateWindow(windowWidth, windowHeight, title, NULL, secondWindowHandle); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); if (windowPosition == WINDOW_POSITION_CUSTOM && !fullscreen) glfwSetWindowPos(window, windowX, windowY); else if (!fullscreen) updateWindowPosition(); glfwSetKeyCallback(window, keyCallback); glfwSetCursorPosCallback(window, cursorPosCallback); glfwSetCursorEnterCallback(window, cursorEnterCallback); glfwSetMouseButtonCallback(window, mouseButtonCallback); glfwSetScrollCallback(window, scrollCallback); glfwSetWindowPosCallback(window, windowPosCallback); glfwSetWindowSizeCallback(window, windowSizeCallback); glfwSetWindowCloseCallback(window, windowCloseCallback); glfwSetWindowRefreshCallback(window, windowRefreshCallback); glfwSetWindowFocusCallback(window, windowFocusCallback); glfwSetWindowIconifyCallback(window, windowIconifyCallback); glfwSetDropCallback(window, dropCallback); if (mouseDisabled) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); else if (mouseHidden) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwMakeContextCurrent(window); glfwSwapInterval(1); GL.createCapabilities(); GLUtil.setupDebugMessageCallback(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, windowWidth, windowHeight, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glClearColor(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, backgroundColor.getAlpha() / 255f); Debug.initialize(); if (visible) glfwShowWindow(window); new Thread(new Update(), "SwingGL | update").start(); long now = System.nanoTime(); long lastTime = now; double deltaR = 0.0; long lastRender = now; running = true; while (running) { if (glfwWindowShouldClose(window) == GL_TRUE) running = false; now = System.nanoTime(); deltaR += (now - lastTime) / renderNS; lastTime = now; if (deltaR >= 1.0) { renderDelta = (now - lastRender) / 1000000000.0f; render(renderDelta); lastRender = now; deltaR--; } } if (currentGameState != null) currentGameState.dispose(); try { glfwDestroyWindow(window); keyCallback.release(); cursorPosCallback.release(); mouseButtonCallback.release(); scrollCallback.release(); } finally { glfwTerminate(); errorCallback.release(); } }
From source file:com.timvisee.voxeltex.engine.render.VoxelTexRenderer.java
License:Open Source License
/** * Initialize the renderer./*from ww w. ja va 2 s . c o m*/ */ public void init() { // Show a status message System.out.println("Initializing " + VoxelTex.ENGINE_NAME + " renderer..."); // Create and configure the error callback, make sure it was created successfully glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err)); if (glfwInit() != GL11.GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); // Set the default window hints this.window.glDefaultWindowHints(); // Set the visibility and resizability of the window this.window.setHintVisible(false); this.window.setHintResizable(true); // Create the window this.window.glCreateWindow(); // Initialize the input manager for this window Input.init(this.window); // Create the framebuffer size callback glfwSetFramebufferSizeCallback(this.window.getWindowId(), fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long windowId, int width, int height) { // Update the window size if (width > 0 && height > 0) window.setSize(width, height); } }); // Center the window this.window.centerWindow(); // Create an int buffer for the window IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(this.window.getWindowId(), memAddress(framebufferSize), memAddress(framebufferSize) + 4); // Set the window size this.window.setSize(framebufferSize.get(0), framebufferSize.get(1)); // Make the window context this.window.glMakeContextCurrent(); // Set the swap interval (V-sync) glfwSwapInterval(0); // Show the window this.window.glShowWindow(); // Center the cursor Input.centerMouseCursor(); // Create the rendering capabilities, required by LWJGL GL.createCapabilities(); // Print the OpenGL version System.out.println("OpenGL " + GL11.glGetString(GL11.GL_VERSION)); // Set the clear color glClearColor(0.9f, 0.9f, 0.9f, 1.0f); // Enable depth testing glEnable(GL_DEPTH_TEST); // Load the engine shaders ShaderManager.load(); // Initialize the Time object Time.init(); // Show a status message System.out.println(VoxelTex.ENGINE_NAME + " renderer initialized successfully!"); }
From source file:com.unascribed.mavkit.Display.java
License:Open Source License
@UIEffect private String getGLVersion(boolean es) { String fullVersion;/*from w ww.j a va2s . com*/ String renderer; if (es) { GLES.createCapabilities(); fullVersion = GLES20.glGetString(GLES20.GL_VERSION); renderer = GLES20.glGetString(GLES20.GL_RENDERER); } else { GL.createCapabilities(); fullVersion = GL11.glGetString(GL11.GL_VERSION); renderer = GL11.glGetString(GL11.GL_RENDERER); } log.info("{}", fullVersion); log.info("{}", renderer); String version = fullVersion.split(" ", 2)[0]; return version; }