Example usage for org.lwjgl.opengl GL11 glScissor

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

Introduction

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

Prototype

public static void glScissor(@NativeType("GLint") int x, @NativeType("GLint") int y,
        @NativeType("GLsizei") int width, @NativeType("GLsizei") int height) 

Source Link

Document

Defines the scissor rectangle for all viewports.

Usage

From source file:com.golden.gamedev.engine.lwjgl.LWJGLGraphics.java

License:Open Source License

public void setClip(int x, int y, int width, int height) {
    GL11.glGetInteger(GL11.GL_VIEWPORT, LWJGLGraphics.display);

    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor(x, LWJGLGraphics.display.get(3) - y - height, width, height);

    if (this.clipArea == null) {
        this.clipArea = LWJGLGraphics.NULL_RECTANGLE;
    }/*from  www  .  j a v a 2 s.c  o m*/

    this.clipArea.setBounds(x, y, width, height);
}

From source file:com.jmex.bui.BComponent.java

License:Open Source License

/**
 * Activates scissoring and sets the scissor region to the intersection of the current region
 * (if any) and the specified rectangle.  After rendering the scissored region, call
 * {@link #restoreScissorState} to restore the previous state.
 *
 * @param store a rectangle to hold the previous scissor region for later restoration
 * @return <code>true</code> if scissoring was already enabled, false if it was not.
 *//*  www  .j  a  v  a  2 s  . co  m*/
protected static boolean intersectScissorBox(Rectangle store, int x, int y, int width, int height) {
    boolean enabled = GL11.glIsEnabled(GL11.GL_SCISSOR_TEST);
    if (enabled) {
        GL11.glGetInteger(GL11.GL_SCISSOR_BOX, _bbuf);
        store.set(_bbuf.get(0), _bbuf.get(1), _bbuf.get(2), _bbuf.get(3));
        int x1 = Math.max(x, store.x), y1 = Math.max(y, store.y),
                x2 = Math.min(x + width, store.x + store.width),
                y2 = Math.min(y + height, store.y + store.height);
        GL11.glScissor(x, y, Math.max(0, x2 - x1), Math.max(0, y2 - y1));
    } else {
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        GL11.glScissor(x, y, width, height);
    }
    return enabled;
}

From source file:com.jmex.bui.BComponent.java

License:Open Source License

/**
 * Restores the previous scissor state after a call to {@link #intersectScissorBox}.
 *
 * @param enabled the value returned by {@link #intersectScissorBox}, indicating whether or not
 *                scissoring was enabled
 * @param rect    the scissor box to restore
 *//*from  ww w.ja  v a  2s  .com*/
protected static void restoreScissorState(boolean enabled, Rectangle rect) {
    if (enabled) {
        GL11.glScissor(rect.x, rect.y, rect.width, rect.height);
    } else {
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    }
}

From source file:com.mtbs3d.minecrift.VRRenderer.java

License:LGPL

private void setupEyeViewport(int renderSceneNumber) {
    this.mc.mcProfiler.endStartSection("clear");

    if (renderSceneNumber == 0) {
        // Left eye
        GL11.glViewport((int) ceil(eyeRenderParams._leftViewPortX * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._leftViewPortY * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._leftViewPortW * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._leftViewPortH * eyeRenderParams._renderScale));

        GL11.glScissor((int) ceil(eyeRenderParams._leftViewPortX * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._leftViewPortY * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._leftViewPortW * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._leftViewPortH * eyeRenderParams._renderScale));
    } else {/* w w w. j av  a2 s  .  c om*/
        // Right eye
        GL11.glViewport((int) ceil(eyeRenderParams._rightViewPortX * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._rightViewPortY * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._rightViewPortW * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._rightViewPortH * eyeRenderParams._renderScale));

        GL11.glScissor((int) ceil(eyeRenderParams._rightViewPortX * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._rightViewPortY * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._rightViewPortW * eyeRenderParams._renderScale),
                (int) ceil(eyeRenderParams._rightViewPortH * eyeRenderParams._renderScale));
    }

    //mc.checkGLError("FBO viewport / scissor setup");
}

From source file:com.opengrave.og.engine.RenderView.java

License:Open Source License

public void render(int totalx, int totaly, int width, int height) {
    this.totalx = totalx;
    this.totaly = totaly;
    this.width = width;
    this.height = height;
    if (sceneNode == null) {
        System.out.println("No scene node to render");
        return;// www  .ja v  a2 s  .  co  m
    }
    if (cam == null) {
        System.out.println("No camera to render from");
        return;
    }
    Shadow2D skyLight = sceneNode.getSkyLight();
    if (shadows && hasshadows) {
        // For each light source we map out a texture using a quick
        // render.
        prepare3DShadow();

        skyLight.getFramebuffer().bindDraw();
        // GL11.glEnable(GL32.GL_DEPTH_CLAMP); // TODO Simu;ate depth clamp in shadow shader when z < 0. This way we force distanced objects to still cast a shadow.
        sceneNode.renderShadows(ident, skyLight);
        skyLight.getFramebuffer().unbindDraw();
        int count = 0;
        ArrayList<PointLightNode> lightList = new ArrayList<PointLightNode>();
        sceneNode.getAllLights(lightList, ident, cam.getLocation().toVector4());
        Collections.sort(lightList, new PointLightSorter());
        for (PointLightNode light : lightList) {
            if (light.getColour().x > 0 || light.getColour().y > 0 || light.getColour().z > 0) {
                // Render each face
                if (lightShadows.size() == count) {
                    ShadowCube shadow = new ShadowCube(MainThread.config.getInteger("shadowSize", 1024));
                    lightShadows.add(shadow);
                }
                ShadowCube shadow = lightShadows.get(count);
                shadow.setLight(light);
                for (int i = 0; i < 6; i++) {
                    shadow.getFramebuffer().bindDraw(i);
                    Util.checkErr();
                    shadow.setFace(i);
                    Util.checkErr();
                    sceneNode.renderShadows(ident, shadow);
                    Util.checkErr();
                    shadow.getFramebuffer().unbindDraw();
                    Util.checkErr();
                }

                count++;
            }
            if (count == 16) {
                break;
            }
        }
        GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);

    }
    GL11.glViewport(totalx, totaly, width, height);
    GL11.glScissor(totalx, totaly, width, height);
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glClearColor(clearCol.x, clearCol.y, clearCol.z, clearCol.w);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | (clear ? GL11.GL_COLOR_BUFFER_BIT : 0));
    Util.checkErr();

    prepare3DOpaque();
    sceneNode.render(ident);
    Util.checkErr();
    prepare3DTransparent();
    sceneNode.renderSemiTransparent(ident);
    MouseRenderableHoverEvent lF = MainThread.main.input.getLastHovered();
    if (lF != null) {
        if (lF.getRenderable() instanceof BaseObject) {
            /*
             * GL11.glDepthFunc(GL11.GL_LESS);
             * GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
             * GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_LINE);
             * 
             * GL11.glLineWidth(10f);
             * GL11.glCullFace(GL11.GL_FRONT);
             * GL11.glEnable(GL11.GL_CULL_FACE);
             * GL11.glDisable(GL11.GL_BLEND);
             * BaseObject bo = (BaseObject) lF.getRenderable();
             * RenderStyle rs = bo.getRenderStyle();
             * bo.setRenderStyle(RenderStyle.HALO);
             * sceneNode.renderOne(ident, bo, ident);
             * 
             * GL11.glDisable(GL11.GL_BLEND);
             * 
             * bo.setRenderStyle(rs);
             * GL11.glCullFace(GL11.GL_BACK);
             * GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
             * GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_FILL);
             * 
             * GL11.glLineWidth(1f);
             * sceneNode.renderOne(ident, bo, ident);
             */

        }
    }

    revertSettings();
    GL11.glDisable(GL11.GL_SCISSOR_TEST);

}

From source file:com.opengrave.og.gui.ScrollBox.java

License:Open Source License

/**
 * Special cases Ho!//ww  w  .j  ava2 s.  c  om
 */
@Override
public void render(int totalx, int totaly) {
    synchronized (children) {
        UIElement e = children.get(0);

        // GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        // GL11.glEnable(GL11.GL_DEPTH_TEST);
        // GL11.glDepthFunc(GL11.GL_LESS);
        // Render box at location
        // location2d = new Vector3f(totalx, totaly, 0);
        // render(null, RenderStyle.NORMAL);
        // GL11.glDepthFunc(GL11.GL_EQUAL);
        // Render contents minus scroll ammount
        if (width < 0 || height < 0) {
            return;
        }
        GL11.glScissor(totalx, MainThread.lastH - (totaly + height), width, height);
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        e.render(totalx, (int) (totaly - scrolly));
        // GL11.glDepthFunc(GL11.GL_LESS);
        GL11.glDisable(GL11.GL_SCISSOR_TEST);

    }
}

From source file:com.opengrave.og.gui.ScrollBox.java

License:Open Source License

public void renderForPicking(int totalx, int totaly) {
    synchronized (children) {
        UIElement e = children.get(0);/*w  w  w.j a v  a  2  s. c o m*/

        // GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        // GL11.glEnable(GL11.GL_DEPTH_TEST);
        // GL11.glDepthFunc(GL11.GL_LESS);
        // Render box at location
        // location2d = new Vector3f(totalx, totaly, 0);
        // render(null, RenderStyle.NORMAL);
        // GL11.glDepthFunc(GL11.GL_EQUAL);
        // Render contents minus scroll ammount
        if (width < 0 || height < 0) {
            return;
        }
        GL11.glScissor(x, MainThread.lastH - (totaly + height), width, height);
        GL11.glEnable(GL11.GL_SCISSOR_TEST);

        e.renderForPicking(totalx, (int) (totaly - scrolly));
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    }
}

From source file:com.smithsmodding.smithscore.util.client.gui.GuiHelper.java

/**
 * Enables the scissor box for a given Plan in the UI.
 * Keep the weird drawing origin for the Scissor box in mind.
 *
 * @param pTargetPlane The plane that should be scissored.
 *//*from  ww w  .jav a 2s  .com*/
public static void enableScissor(Plane pTargetPlane) {

    calcScaleFactor();

    GL11.glPushAttrib(GL11.GL_SCISSOR_BIT);
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor(pTargetPlane.TopLeftCoord().getXComponent() * GUISCALE,
            ((DISPLAYHEIGHT - pTargetPlane.LowerRightCoord().getYComponent()) * GUISCALE),
            (pTargetPlane.getWidth()) * GUISCALE, (pTargetPlane.getHeigth()) * GUISCALE);

}

From source file:com.xrbpowered.gl.scene.ActorPicker.java

License:Open Source License

public void startPicking(int x, int y, RenderTarget pickTarget) {
    this.x = x;/* w w  w .j  av a 2  s .  c o m*/
    this.y = y;
    pickTarget.use();
    GL11.glScissor(x, y, 1, 1);
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glClearColor(0f, 0f, 0f, 0f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    ActorPickerShader.getInstance().use();
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void scissorTest(boolean enable, int x, int y, int w, int h) {
    if (enable) {
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        GL11.glScissor(x, y, w, h);
    } else {//from  w w  w .  ja v a 2s . co  m
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    }
}