List of usage examples for org.lwjgl.opengl GL createCapabilities
public static GLCapabilities createCapabilities()
From source file:bug1167.lwjgl.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(); for (int i = 0; i < SQRT_BUILDING_COUNT; i++) { for (int k = 0; k < SQRT_BUILDING_COUNT; k++) { int index = (i * SQRT_BUILDING_COUNT + k) * Integer.BYTES; vertexBuffer.position(index); GL45.glCreateBuffers(1, vertexBuffer); indexBuffer.position(index); GL45.glCreateBuffers(1, indexBuffer); // Stick the data for the vertices and indices in their respective buffers ByteBuffer verticesBuffer = BufferUtils.createByteBuffer(512 * Byte.BYTES); GL45.glNamedBufferData(vertexBuffer.getInt(index), verticesBuffer.capacity() * Byte.BYTES, verticesBuffer, GL_STATIC_DRAW); ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(6 * Short.BYTES); GL45.glNamedBufferData(indexBuffer.getInt(index), indicesBuffer.capacity() * Byte.BYTES, indicesBuffer, GL_STATIC_DRAW); // *** INTERESTING *** // get the GPU pointer for the vertex buffer and make the vertex buffer resident on the GPU GL15.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.getInt(index)); NVShaderBufferLoad.glGetBufferParameterui64vNV(GL_ARRAY_BUFFER, GL_BUFFER_GPU_ADDRESS_NV, vertexBufferGPUPtr); GL15.glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, vertexBufferSize); NVShaderBufferLoad.glMakeBufferResidentNV(GL_ARRAY_BUFFER, GL_READ_ONLY); GL15.glBindBuffer(GL_ARRAY_BUFFER, 0); // *** INTERESTING *** // get the GPU pointer for the index buffer and make the index buffer resident on the GPU GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.getInt(index)); NVShaderBufferLoad.glGetBufferParameterui64vNV(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_GPU_ADDRESS_NV, indexBufferGPUPtr);// www . j a v a 2 s.c o m GL15.glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, indexBufferSize); NVShaderBufferLoad.glMakeBufferResidentNV(GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY); GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } } // for (int i = 0; i < SQRT_BUILDING_COUNT*SQRT_BUILDING_COUNT; i++) { // System.out.println(""+vertexBuffer.getInt(i*Integer.BYTES)); // } clearColor.rewind(); // Run the rendering loop until the user has attempted to close // the window or has pressed the ESCAPE key. while (glfwWindowShouldClose(window) == GLFW_FALSE) { glClearColor(1.0f, 0.5f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer GL30.glClearBufferfv(GL_COLOR, 0, clearColor); glfwSwapBuffers(window); // swap the color buffers // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents(); updateFPS(); } }
From source file:ch.render.OGLrenderer.java
private void init() { //init Gameboy gb = new GB(); gb.loadRom("roms/Big Scroller Demo (PD).gb"); //gb.loadRom("roms/Pokemon - Red Version (USA, Europe).gb"); //init GLFW//w w w . j a va 2 s. com glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err)); if (glfwInit() != GL11.GL_TRUE) { throw new IllegalStateException("Unable initialize GLFW"); } //open a window with GLFW 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, 2); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); window = glfwCreateWindow(160 * 2, 144 * 2, "R_GB Gameboy Color Emulator", NULL, NULL); if (window == NULL) { throw new RuntimeException("glfwCreateWindow failed. OpenGL 3.2 supported?"); } glfwSetKeyCallback(window, keyCallback = new GLFWInput().register(gb.comps.joypad)); //hook this IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(2); glfwGetFramebufferSize(window, w, h); //System.out.println(w.get()); //System.out.println(h.get()); //GLFW settings glfwMakeContextCurrent(window); GL.createCapabilities(); //init GLEW //lwjgl has no GLEW //TODO: output graphics card capabilities //openGL settings //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glDisable(GL_LIGHTING); loadShaders(); loadTexture(); loadRectangle(); }
From source file:cn.org.vbn.Texture2DArrayMipmapping.java
License:Open Source License
private void init() throws IOException { glfwSetErrorCallback(errCallback = new GLFWErrorCallback() { private GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err); @Override//from w w w. j a v a2s . 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 release() { delegate.release(); super.release(); } }); if (glfwInit() != GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_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, GL_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:com.acornui.jvm.LwjglHelloWorld.java
License:Apache License
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. initMatrices();// w ww . ja v a 2 s. co m while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer draw(); glfwSwapBuffers(window); // swap the color buffers // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents(); } }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGraphics.java
License:Apache License
public JglfwGraphics(JglfwApplicationConfiguration config) { // Store values from config. bufferFormat = new BufferFormat(config.r, config.g, config.b, config.a, config.depth, config.stencil, config.samples, false);//from w w w .j a v a 2 s.c o m title = config.title; resizable = config.resizable; undecorated = config.undecorated; x = config.x; y = config.y; vSync = config.vSync; // FIXME: This needs smarts usingGL30 = config.useGL30; initialBackgroundColor = config.initialBackgroundColor; if (config.fullscreenMonitorIndex != -1) { // Use monitor specified in config if it is valid. PointerBuffer monitors = glfwGetMonitors(); long count = monitors.get(); if (config.fullscreenMonitorIndex < count) fullscreenMonitor = monitors.get(config.fullscreenMonitorIndex + 1); } // Create window. if (!createWindow(config.width, config.height, config.fullscreen)) { throw new GdxRuntimeException("Unable to create window: " + config.width + "x" + config.height + ", fullscreen: " + config.fullscreen); } GL.createCapabilities(); // Create GL. String version = GL11.glGetString(GL20.GL_VERSION); glMajorVersion = Integer.parseInt("" + version.charAt(0)); glMinorVersion = Integer.parseInt("" + version.charAt(2)); if (glMajorVersion <= 1) throw new GdxRuntimeException( "OpenGL 2.0 or higher with the FBO extension is required. OpenGL version: " + version); if (glMajorVersion == 2 || version.contains("2.1")) { if (!supportsExtension("GL_EXT_framebuffer_object") && !supportsExtension("GL_ARB_framebuffer_object")) { throw new GdxRuntimeException( "OpenGL 2.0 or higher with the FBO extension is required. OpenGL version: " + version + ", FBO extension: false"); } } if (usingGL30) { gl30 = new JglfwGL30(); gl20 = gl30; } else { gl20 = new JglfwGL20(); } Gdx.gl = gl20; Gdx.gl20 = gl20; Gdx.gl30 = gl30; if (!config.hidden) show(); }
From source file:com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.java
License:Apache License
static long createGlfwWindow(Lwjgl3ApplicationConfiguration config, long sharedContextWindow) { GLFW.glfwDefaultWindowHints();// www. ja v a 2 s .c o m GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, config.windowResizable ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE); if (sharedContextWindow == 0) { GLFW.glfwWindowHint(GLFW.GLFW_RED_BITS, config.r); GLFW.glfwWindowHint(GLFW.GLFW_GREEN_BITS, config.g); GLFW.glfwWindowHint(GLFW.GLFW_BLUE_BITS, config.b); GLFW.glfwWindowHint(GLFW.GLFW_ALPHA_BITS, config.a); GLFW.glfwWindowHint(GLFW.GLFW_STENCIL_BITS, config.stencil); GLFW.glfwWindowHint(GLFW.GLFW_DEPTH_BITS, config.depth); GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, config.samples); } if (config.useGL30) { //GLFW.glfwWindowHint(GLFW.GLFW_CLIENT_API, GLFW.GLFW_OPENGL_API); GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, config.gles30ContextMajorVersion); GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, config.gles30ContextMinorVersion); GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE); GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE); } long windowHandle = 0; if (config.fullscreenMode != null) { // glfwWindowHint(GLFW.GLFW_REFRESH_RATE, config.fullscreenMode.refreshRate); windowHandle = GLFW.glfwCreateWindow(config.fullscreenMode.width, config.fullscreenMode.height, config.title, config.fullscreenMode.getMonitor(), sharedContextWindow); } else { GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, config.windowDecorated ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE); windowHandle = GLFW.glfwCreateWindow(config.windowWidth, config.windowHeight, config.title, 0, sharedContextWindow); } if (windowHandle == 0) { throw new GdxRuntimeException("Couldn't create window"); } if (config.fullscreenMode == null) { if (config.windowX == -1 && config.windowY == -1) { GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(windowHandle, vidMode.width() / 2 - config.windowWidth / 2, vidMode.height() / 2 - config.windowHeight / 2); } else { GLFW.glfwSetWindowPos(windowHandle, config.windowX, config.windowY); } } GLFW.glfwMakeContextCurrent(windowHandle); GLFW.glfwSwapInterval(config.vSyncEnabled ? 1 : 0); GL.createCapabilities(); extractVersion(); if (!isOpenGLOrHigher(2, 0)) throw new GdxRuntimeException( "OpenGL 2.0 or higher with the FBO extension is required. OpenGL version: " + GL11.glGetString(GL11.GL_VERSION) + "\n" + glInfo()); if (!supportsFBO()) { throw new GdxRuntimeException( "OpenGL 2.0 or higher with the FBO extension is required. OpenGL version: " + GL11.glGetString(GL11.GL_VERSION) + ", FBO extension: false\n" + glInfo()); } for (int i = 0; i < 2; i++) { GL11.glClearColor(config.initialBackgroundColor.r, config.initialBackgroundColor.g, config.initialBackgroundColor.b, config.initialBackgroundColor.a); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GLFW.glfwSwapBuffers(windowHandle); } return windowHandle; }
From source file:com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowController.java
License:Apache License
void initContext(Lwjgl3Application app) { if (app.init == false) { glfwMakeContextCurrent(app.graphics.window); GL.createCapabilities(); app.graphics.initGL();//from w ww . ja v a 2 s. co m app.graphics.show(); app.init = true; } }
From source file:com.bossletsplays.borage.engine.core.Display.java
License:Apache License
/** * Creates the window and enables the OpenGL context. * * @param title The title of the window//w ww . j a va 2 s. c o m * @param width The width of the window * @param height The height of the window * @author Matthew Rogers * @since @VERSION@ */ public static void create(String title, int width, int height) { Display.title = title; Display.width = width; Display.height = height; // Callback to catch and print GLFW errors glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err)); // Initialize GLFW, exit the game if it fails if (glfwInit() == GLFW_FALSE) { System.err.println("GLFW failed to initialize"); destroy(); System.exit(1); } glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // This needs to be false so we can move and center the window glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Create the window with the desired dimensions and height. // The first 0 parameter will be taken care of when we implement fullscreen window = glfwCreateWindow(width, height, title, 0, 0); // Center the window GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); // Set the OpenGL context created with the window to be the context used by the current (main) thread glfwMakeContextCurrent(window); glfwShowWindow(window); // Make the window visible GL.createCapabilities(); // LWJGL needs to find the OpenGL context created by GLFW and enable the OpenGL bindings so we can use them }
From source file:com.google.gapid.widgets.GlComposite.java
License:Apache License
public GlComposite(Composite parent) { super(parent, SWT.NO_BACKGROUND); setLayout(new FillLayout(SWT.VERTICAL)); canvas = new GlCanvas(this, SWT.NO_BACKGROUND); canvas.setCurrent();/*ww w . ja v a2 s . com*/ caps = GL.createCapabilities(); }
From source file:com.google.gapid.widgets.ScenePanel.java
License:Apache License
public ScenePanel(Composite parent, Scene<T> scene) { super(parent, SWT.NO_BACKGROUND); setLayout(new FillLayout(SWT.VERTICAL)); this.scene = scene; renderer = new Renderer(); setCurrent();//from w ww. ja v a 2 s.c o m caps = GL.createCapabilities(); initialize(); addListener(SWT.Resize, e -> { /* register to handle resizes in dispatchEvents */ }); addListener(SWT.Paint, e -> update(true)); }