Example usage for org.lwjgl.opengl GL11 glGetInteger

List of usage examples for org.lwjgl.opengl GL11 glGetInteger

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glGetInteger.

Prototype

@NativeType("void")
public static int glGetInteger(@NativeType("GLenum") int pname) 

Source Link

Document

Returns the current integer value of the specified state variable.

Usage

From source file:itdelatrisu.opsu.render.CurveRenderState.java

License:Open Source License

/**
 * Draw a curve to the screen that's tinted with `color`. The first time
 * this is called this caches the image result of the curve and on subsequent
 * runs it just draws the cached copy to the screen.
 * @param color tint of the curve//w  ww .ja  va 2  s. c o m
 * @param borderColor the curve border color
 * @param curve the points along the curve to be drawn
 */
public void draw(Color color, Color borderColor, Vec2f[] curve) {
    float alpha = color.a;

    // if this curve hasn't been drawn, draw it and cache the result
    if (fbo == null) {
        FrameBufferCache cache = FrameBufferCache.getInstance();
        Rendertarget mapping = cache.get(hitObject);
        if (mapping == null)
            mapping = cache.insert(hitObject);
        fbo = mapping;

        int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
        int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

        //glGetInteger requires a buffer of size 16, even though just 4
        //values are returned in this specific case
        IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
        GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
        GL11.glViewport(0, 0, fbo.width, fbo.height);
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        Colors.WHITE_FADE.a = 1.0f;
        this.draw_curve(color, borderColor, curve);
        color.a = 1f;

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
        GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
        Colors.WHITE_FADE.a = alpha;
    }

    // draw a fullscreen quad with the texture that contains the curve
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_TEXTURE_1D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex2i(fbo.width, 0);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex2i(0, 0);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex2i(0, fbo.height);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex2i(fbo.width, fbo.height);
    GL11.glEnd();
}

From source file:itdelatrisu.opsu.render.CurveRenderState.java

License:Open Source License

/**
 * Backup the current state of the relevant OpenGL state and change it to
 * what's needed to draw the curve./* ww w  .j  a v  a 2 s.  c om*/
 */
private RenderState startRender() {
    RenderState state = new RenderState();
    state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
    state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND);
    state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
    state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
    state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
    state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
    state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
    state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    GL14.glBlendEquation(GL14.GL_FUNC_ADD);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(true);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_TEXTURE_1D);
    GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);

    GL20.glUseProgram(0);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    return state;
}

From source file:itdelatrisu.opsu.render.Rendertarget.java

License:Open Source License

/**
 * Creates a Rendertarget with a Texture that it renders the color buffer in
 * and a renderbuffer that it renders the depth to.
 * @param width the width//from w  w  w  . jav a  2  s  . com
 * @param height the height
*/
public static Rendertarget createRTTFramebuffer(int width, int height) {
    int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
    int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    Rendertarget buffer = new Rendertarget(width, height);
    buffer.bind();

    int fboTexture = buffer.textureID;
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT,
            (ByteBuffer) null);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);
    EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT, width, height);
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            buffer.depthBufferID);

    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture);
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer);

    return buffer;
}

From source file:itemrender.client.rendering.FBOHelper.java

License:MIT License

public void begin() {
    checkGlErrors("FBO Begin Init");

    // Remember current framebuffer.
    lastFramebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);

    // Render to our texture
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebufferID);

    // Remember viewport info.
    lastViewport = GLAllocation.createDirectIntBuffer(16);
    GL11.glGetInteger(GL11.GL_VIEWPORT, lastViewport);
    GL11.glViewport(0, 0, renderTextureSize, renderTextureSize);

    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.pushMatrix();//from w w w  . j av a  2  s.  c o m
    GlStateManager.loadIdentity();

    // Remember current texture.
    lastTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

    GlStateManager.clearColor(0, 0, 0, 0);
    GlStateManager.clear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GlStateManager.cullFace(GL11.GL_FRONT);
    GlStateManager.enableDepth();
    GlStateManager.enableLighting();
    GlStateManager.enableRescaleNormal();

    checkGlErrors("FBO Begin Final");
}

From source file:itemrender.client.rendering.FBOHelper.java

License:MIT License

private void createFramebuffer() {
    framebufferID = EXTFramebufferObject.glGenFramebuffersEXT();
    textureID = GL11.glGenTextures();/*from  w w  w.  ja  v  a  2s . c o m*/
    int currentFramebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
    int currentTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebufferID);

    // Set our texture up, empty.
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, renderTextureSize, renderTextureSize, 0,
            GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);

    // Restore old texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTexture);

    // Create depth buffer
    depthbufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
    EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthbufferID);
    EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT, renderTextureSize, renderTextureSize);

    // Bind depth buffer to the framebuffer
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            depthbufferID);

    // Bind our texture to the framebuffer
    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, textureID, 0);

    // Revert to default framebuffer
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, currentFramebuffer);
}

From source file:itemrender.client.RenderTickHandler.java

License:MIT License

@SubscribeEvent
public void tick(TickEvent.RenderTickEvent event) {
    if (event.phase == TickEvent.Phase.END)
        if (keybindToRender != null && renderPreview) {
            int originalTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

            // Bind framebuffer texture
            keybindToRender.fbo.bind();/*w  w  w  . j  av  a2s.  co m*/
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(0, 0);
            GL11.glVertex2i(0, 0);
            GL11.glTexCoord2f(0, 1);
            GL11.glVertex2i(0, 128);
            GL11.glTexCoord2f(1, 1);
            GL11.glVertex2i(128, 128);
            GL11.glTexCoord2f(1, 0);
            GL11.glVertex2i(128, 0);
            GL11.glEnd();

            // Restore old texture
            GlStateManager.bindTexture(originalTexture);
        }
}

From source file:ivorius.ivtoolkit.rendering.IvShaderInstance.java

License:Apache License

public static void outputShaderInfo(Logger logger) {
    String renderer = GL11.glGetString(GL11.GL_RENDERER);
    String vendor = GL11.glGetString(GL11.GL_VENDOR);
    String version = GL11.glGetString(GL11.GL_VERSION);
    boolean fboSupported = OpenGlHelper.framebufferSupported;

    String majorVersion;/*w ww  .  ja va  2 s  .  co  m*/
    String minorVersion;

    String glslVersion;

    try {
        glslVersion = GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION);
    } catch (Exception ex) {
        glslVersion = "? (No GL20)";
    }

    try {
        minorVersion = "" + GL11.glGetInteger(GL30.GL_MINOR_VERSION);
        majorVersion = "" + GL11.glGetInteger(GL30.GL_MAJOR_VERSION);
    } catch (Exception ex) {
        minorVersion = "?";
        majorVersion = "? (No GL 30)";
    }

    printAlignedInfo("Vendor", vendor, logger);
    printAlignedInfo("Renderer", renderer, logger);
    printAlignedInfo("Version", version, logger);
    printAlignedInfo("Versions", getGLVersions(GLContext.getCapabilities()), logger);
    printAlignedInfo("Version Range", String.format("%s - %s", minorVersion, majorVersion), logger);
    printAlignedInfo("GLSL Version", glslVersion, logger);
    printAlignedInfo("Frame buffer object", fboSupported ? "Supported" : "Unsupported", logger);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

protected void init() {
    String openGLVersion = GL11.glGetString(GL11.GL_VERSION);
    String openGLVendor = GL11.glGetString(GL11.GL_VENDOR);
    String openGLRenderer = GL11.glGetString(GL11.GL_RENDERER);
    log.info(String.format("OpenGL version: %s, vender: %s, renderer: %s", openGLVersion, openGLVendor,
            openGLRenderer));//from w w  w .ja  v a 2 s . c o m

    vendorIntel = "Intel".equalsIgnoreCase(openGLVendor);
    hasOpenGL30 = GLContext.getCapabilities().OpenGL30;

    if (GLContext.getCapabilities().OpenGL20) {
        String shadingLanguageVersion = GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION);
        log.info("Shading Language version: " + shadingLanguageVersion);
    }

    if (GLContext.getCapabilities().OpenGL30) {
        int contextFlags = GL11.glGetInteger(GL30.GL_CONTEXT_FLAGS);
        String s = String.format("GL_CONTEXT_FLAGS: 0x%X", contextFlags);
        if ((contextFlags & GL30.GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) != 0) {
            s += " (GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)";
        }
        log.info(s);
    }

    if (GLContext.getCapabilities().OpenGL32) {
        int contextProfileMask = GL11.glGetInteger(GL32.GL_CONTEXT_PROFILE_MASK);
        String s = String.format("GL_CONTEXT_PROFILE_MASK: 0x%X", contextProfileMask);
        if ((contextProfileMask & GL32.GL_CONTEXT_CORE_PROFILE_BIT) != 0) {
            s += " (GL_CONTEXT_CORE_PROFILE_BIT)";
        }
        if ((contextProfileMask & GL32.GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0) {
            s += " (GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)";
        }
        log.info(s);
    }
}

From source file:kubex.KubexGame.java

License:Creative Commons License

public KubexGame(KubexSettings settings) throws LWJGLException, KubexException {
    this.settings = settings;
    LIQUID_LAYERS = this.settings.WATER_LAYERS;

    if (settings.FULLSCREEN_ENABLED) { //If fullscreen is enabled, sets it on on the desktop resolution and adapts X_RES and Y_RES
        DisplayMode dm = Display.getDesktopDisplayMode();
        X_RES = dm.getWidth();/*from w w  w. j a  v a 2 s.  c  o  m*/
        Y_RES = dm.getHeight();
        IvEngine.configDisplay(dm, "Monecruft", true, false, true);
    } else { //Windowed mode
        this.X_RES = settings.WINDOW_XRES;
        this.Y_RES = settings.WINDOW_YRES;
        IvEngine.configDisplay(X_RES, Y_RES, "Monecruft", true, false, false);
    }

    //"GPU not supported" error handling
    if (!GLContext.getCapabilities().OpenGL32)
        throw new KubexGPUException("Your GPU doesn't support OpenGL 3.2");
    else if (GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS) < 8)
        throw new KubexGPUException(
                "Your GPU doesn't support 8 texture units, and Kubex needs them to run correctly");

    Thread.currentThread().setPriority(Thread.currentThread().getPriority() + 1); //Faster than the others -> game experience > loading

    //Sets the camera far distance in function of the maximum render distance (Considering height is fixed as 8x32 m)
    CAMERA_FAR = (float) Math
            .sqrt(World.HEIGHT * World.HEIGHT + settings.RENDER_DISTANCE * settings.RENDER_DISTANCE)
            * Chunk.CHUNK_DIMENSION;
    float[] ssplits = ShadowsManager.calculateSplits(1f, CAMERA_FAR, SHADOW_LAYERS, 0.3f);
    ssplits[0] = CAMERA_NEAR;
    ssplits[1] = ssplits[1] / 4;
    ssplits[2] = ssplits[2] / 2.5f;
    ssplits[3] = ssplits[3] / 1.5f;

    SHADOW_SPLITS = ssplits;

    try {
        initResources(); //Inits the textures, shaders, objects, etc
    } catch (IOException e) {
        throw new KubexIOException("Error reading/storing files in disk");
    } catch (KubexIOException e) {
        throw e;
    }

    //Main loop
    boolean running = true;
    Mouse.setGrabbed(true); //Grabs the mouse

    shutdownHook = new Thread() { //If the app is closed unusually, safelly terminates it anyways (Saving chunks in disk)
        @Override
        public void run() {
            closeApp();
        }
    };
    Runtime.getRuntime().addShutdownHook(shutdownHook);

    TM.getDeltaTime();
    try {
        while (running && !Display.isCloseRequested()) { //Game loop
            Display.isActive();
            while (Keyboard.next()) {
                handleKeyboardInput();
            }
            while (Mouse.next()) {
                handleMouseInput();
            }
            int wheel = Mouse.getDWheel();
            if (wheel != 0) {
                wheel = wheel > 0 ? 1 : -1;
                InputHandler.addWheel(wheel);
            }
            if (InputHandler.isESCPressed()) {
                running = false;
                InputHandler.setESC(false);
            }
            update(TM.getDeltaTime());
            render();
            if (Display.isActive() && !hasFocus) {
                hasFocus = true;
                Mouse.setGrabbed(true);
            } else if (!Display.isActive() && hasFocus) //If window loses focus, ungrab the mouse
            {
                hasFocus = false;
                Mouse.setGrabbed(false);
            }
            // Flip the buffers and sync to 60 FPS
            Display.update();
            Display.sync(60);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    closeApp();
}

From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java

License:Open Source License

@Override
public void addAttribute(int index, int size, TFloatList data) {
    ensureCreated("VertexArray must be created to add an attribute.");

    if (index > GL11.glGetInteger(GL_MAX_VERTEX_ATTRIBS)) {
        throw new IllegalArgumentException("Vertex attribute index exceeds maximum vertex attribute index.");
    }/*from www. jav a 2 s . com*/
    // Put the indices into an FloatBuffer
    final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size());
    data.forEach((float f) -> {
        buffer.put(f);
        return true;
    });
    buffer.flip();

    // Bind the VAO
    GL30.glBindVertexArray(vao);
    // Generate and bind the attribute buffer
    final int id = GL15.glGenBuffers();
    GL15.glBindBuffer(GL_ARRAY_BUFFER, id);
    // Set the attribute data
    GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
    // Enable the vertex attribute
    GL20.glEnableVertexAttribArray(index);
    // Set the vertex attribute settings
    GL20.glVertexAttribPointer(index, size, DataType.FLOAT.getGLConstant(), false, 0, 0L);
    // Disable the vertex attribute
    GL20.glDisableVertexAttribArray(index);
    // Unbind the attribute buffer
    GL15.glBindBuffer(GL_ARRAY_BUFFER, 0);
    // Unbind the VAO
    GL30.glBindVertexArray(vao);

    // Add the buffer id to the attributes list
    this.attributes.insert(index, id);

    // Check for errors
    RenderUtil.checkGLError();
}