Example usage for com.badlogic.gdx.graphics GL20 GL_SCISSOR_TEST

List of usage examples for com.badlogic.gdx.graphics GL20 GL_SCISSOR_TEST

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 GL_SCISSOR_TEST.

Prototype

int GL_SCISSOR_TEST

To view the source code for com.badlogic.gdx.graphics GL20 GL_SCISSOR_TEST.

Click Source Link

Usage

From source file:CB_Locator.Map.MapViewBase.java

License:Open Source License

protected void renderDebugInfo(Batch batch) {

    CB_RectF r = this.thisWorldRec;

    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);

    BitmapFont font = Fonts.getNormal();

    font.setColor(Color.BLACK);//from   ww w  . j a  v a2s .  c om

    Matrix4 def = new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    def.translate(r.getX(), r.getY(), 1);
    batch.setProjectionMatrix(def);

    // str = debugString;
    font.draw(batch, str, 20, 120);

    str = "fps: " + Gdx.graphics.getFramesPerSecond();
    font.draw(batch, str, 20, 100);

    str = String.valueOf(aktZoom) + " - camzoom: " + Math.round(camera.zoom * 100) / 100;
    font.draw(batch, str, 20, 80);

    str = "lTiles: " + mapTileLoader.LoadedTilesSize() + " - qTiles: " + mapTileLoader.QueuedTilesSize();
    font.draw(batch, str, 20, 60);

    str = "lastMove: " + lastMovement.x + " - " + lastMovement.y;
    font.draw(batch, str, 20, 20);
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
}

From source file:CB_UI.GL_UI.Activitys.CreateTrackOverMapActivity.java

License:Open Source License

@Override
public void renderChilds(final Batch batch, ParentInfo parentInfo) {
    super.renderChilds(batch, parentInfo);

    // render WPs
    if (waypoints == null)
        return;//from ww  w  .j av  a 2s .c om
    tmplist.clear();

    for (int i = 0; i < waypoints.size(); i++) {
        Waypoint wp = waypoints.get(i);

        double MapX = 256.0 * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, wp.Pos.getLongitude());
        double MapY = -256.0 * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, wp.Pos.getLatitude());
        if (true)// isVisible(MapX, MapY)
        {
            WaypointRenderInfo wpi = new WaypointRenderInfo();
            wpi.MapX = (float) MapX;
            wpi.MapY = (float) MapY;
            wpi.Icon = Sprites.getSprite("mapTrailhead");
            wpi.Cache = null;
            wpi.Waypoint = wp;
            wpi.UnderlayIcon = null;

            wpi.Selected = false;
            if (selectedWP != null) {
                if (selectedWP.getGcCode().equals(wp.getGcCode())) {
                    wpi.Selected = true;
                    wpi.UnderlayIcon = Sprites.MapOverlay.get(1);
                }
            }
            tmplist.add(wpi);
        }
    }

    batch.setProjectionMatrix(mapView.myParentInfo.Matrix());

    Gdx.gl.glScissor((int) mapView.thisWorldRec.getX(), (int) mapView.thisWorldRec.getY(),
            (int) mapView.thisWorldRec.getWidth() + 1, (int) mapView.thisWorldRec.getHeight() + 1);
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);

    SizeF drawingSize = new SizeF(40, 40);

    for (int i = 0; i < tmplist.size(); i++) {

        mapView.renderWPI(batch, drawingSize, drawingSize, tmplist.get(i));

    }

}

From source file:CB_UI_Base.GL_UI.GL_View_Base.java

License:Open Source License

/**
 * Die renderChilds() Methode wird vom GL_Listener bei jedem Render-Vorgang aufgerufen.
 * Hier wird dann zuerst die render() Methode dieser View aufgerufen.
 * Danach werden alle Childs iteriert und deren renderChilds() Methode aufgerufen, wenn die View sichtbar ist (Visibility).
 *
 * @param batch//from  w  w  w.  ja v a 2s .c  om
 */
public void renderChilds(final Batch batch, ParentInfo parentInfo) {
    if (myParentInfo == null)
        return;

    if (this.isDisposed)
        return;

    if (thisInvalidate) {
        myParentInfo.setParentInfo(parentInfo);
        CalcMyInfoForChild();
    }

    if (!withoutScissor) {
        if (intersectRec == null || intersectRec.getHeight() + 1 < 0 || intersectRec.getWidth() + 1 < 0)
            return; // hier gibt es nichts zu rendern
        if (!disableScissor)
            Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
        Gdx.gl.glScissor((int) intersectRec.getX(), (int) intersectRec.getY(),
                (int) intersectRec.getWidth() + 1, (int) intersectRec.getHeight() + 1);
    }

    float A = 0, R = 0, G = 0, B = 0; // Farbwerte der batch um diese wieder einzustellen, wenn ein ColorFilter angewandt wurde!

    boolean ColorFilterSeted = false; // Wir benutzen hier dieses Boolean um am ende dieser Methode zu entscheiden, ob wir die alte
    // Farbe des Batches wieder herstellen mssen. Wir verlassen uns hier nicht darauf, das
    // mColorFilter!= null ist, da dies in der zwichenzeit passiert sein kann.

    // Set Colorfilter ?
    if (mColorFilter != null) {
        ColorFilterSeted = true;
        // zuerst alte Farbe abspeichern, um sie Wieder Herstellen zu knnen
        // hier muss jeder Wert einzeln abgespeichert werden, da bei getColor()
        // nur eine Referenz zurck gegeben wird
        Color c = batch.getColor();
        A = c.a;
        R = c.r;
        G = c.g;
        B = c.b;

        batch.setColor(mColorFilter);
    }

    // first Draw Background?

    if (drawableBackground != null) {
        drawableBackground.draw(batch, 0, 0, getWidth(), getHeight());
    }

    // set rotation
    boolean isRotated = false;

    if (mRotate != 0 || mScale != 1) {
        isRotated = true;

        rotateMatrix.idt();
        rotateMatrix.translate(mOriginX, mOriginY, 0);
        rotateMatrix.rotate(0, 0, 1, mRotate);
        rotateMatrix.scale(mScale, mScale, 1);
        rotateMatrix.translate(-mOriginX, -mOriginY, 0);

        batch.setTransformMatrix(rotateMatrix);
    }

    try {
        this.render(batch);
    } catch (IllegalStateException e) {
        e.printStackTrace();
        // reset Colorfilter ?
        if (ColorFilterSeted) {
            // alte abgespeicherte Farbe des Batches wieder herstellen!
            batch.setColor(R, G, B, A);
        }
        return;
    }

    // reverse rotation
    if (isRotated) {
        rotateMatrix.idt();
        // rotateMatrix.rotate(0, 0, 1, 0);
        // rotateMatrix.scale(1, 1, 1);

        batch.setTransformMatrix(rotateMatrix);
    }

    if (childs != null && childs.size() > 0) {
        for (int i = 0, n = childs.size(); i < n; i++) {

            if (i >= childs.size()) {
                break; // ConcurrentModificationException
            }

            // alle renderChilds() der in dieser GL_View_Base
            // enthaltenen Childs auf rufen.

            try {
                GL_View_Base view = childs.get(i);
                // hier nicht view.render(batch) aufrufen, da sonnst die in der
                // view enthaldenen Childs nicht aufgerufen werden.
                try {
                    if (view != null && !view.isDisposed() && view.isVisible()) {
                        synchronized (view) {
                            if (childsInvalidate)
                                view.invalidate();

                            getMyInfoForChild().setParentInfo(myParentInfo);
                            getMyInfoForChild().setWorldDrawRec(intersectRec);

                            getMyInfoForChild().add(view.getX(), view.getY());

                            batch.setProjectionMatrix(getMyInfoForChild().Matrix());
                            nDepthCounter++;

                            view.renderChilds(batch, getMyInfoForChild());
                            nDepthCounter--;
                        }
                    } else {
                        if (view != null && view.isDisposed()) {
                            // Remove disposedView from child list
                            this.removeChild(view);
                        }
                    }
                } catch (java.lang.IllegalStateException e) {
                    if (view != null && view.isDisposed()) {
                        // Remove disposedView from child list
                        this.removeChild(view);
                    }
                }

            } catch (java.util.NoSuchElementException e) {
                break; // da die Liste nicht mehr gltig ist, brechen wir hier den Iterator ab
            } catch (java.util.ConcurrentModificationException e) {
                break; // da die Liste nicht mehr gltig ist, brechen wir hier den Iterator ab
            } catch (java.lang.IndexOutOfBoundsException e) {
                break; // da die Liste nicht mehr gltig ist, brechen wir hier den Iterator ab
            }
        }
        childsInvalidate = false;
    }

    // Draw Debug REC
    if (debug) {

        if (DebugSprite != null) {
            batch.flush();
            DebugSprite.draw(batch);

        }

    }

    // reset Colorfilter ?
    if (ColorFilterSeted) {
        // alte abgespeicherte Farbe des Batches wieder herstellen!
        batch.setColor(R, G, B, A);
    }

}

From source file:CB_UI_Base.graphics.Images.VectorDrawable.java

License:Open Source License

private void drawFbo(Batch batch, float x, float y, final float width, final float height,
        final Matrix4 oriMatrix, Matrix4 thisDrawMatrix) {
    final int fboScalerWidth = (int) (this.DEFAULT_WIDTH * FBO_SCALER);
    final int fboScalerHeight = (int) (this.DEFAULT_HEIGHT * FBO_SCALER);
    if (!RunOnGlSetted && m_fboEnabled && m_fboRegion == null) {
        RunOnGlSetted = true;//w w  w  .  j av a  2 s.  c om

        GL.that.RunOnGL(new IRenderFBO() {

            @Override
            public void run() {
                synchronized (isDisposed) {

                    if (isDisposed.get()) {
                        return;
                    }

                    try {
                        Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);

                        long start = System.currentTimeMillis();

                        m_fbo = new FrameBuffer(Format.RGBA8888, fboScalerWidth, fboScalerHeight, false);
                        m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
                        m_fboRegion.flip(flipX, flipY);

                        m_fbo.begin();

                        // clear screen
                        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

                        GL.batch.setColor(new Color(Color.WHITE));

                        GL.batch.begin();

                        Matrix4 matrix = new Matrix4().setToOrtho2D(0, 0, width, height);
                        matrix.scale(FBO_SCALER, FBO_SCALER, 1);
                        GL.batch.setProjectionMatrix(matrix);

                        // draw Background
                        GL.batch.disableBlending();
                        background.draw(GL.batch, 0, 0, fboScalerWidth, fboScalerHeight);
                        GL.batch.enableBlending();
                        int count = 0;

                        for (int i = 0, n = drawableList.size(); i < n; i++) {
                            MatrixDrawable drw = drawableList.get(i);
                            if (count++ > 2500) {
                                GL.batch.flush();
                                count = 0;
                            }
                            matrix = new Matrix4().setToOrtho2D(0, 0, width, height);
                            if (drw.matrix != null) {

                                matrix.mul(drw.matrix.getMatrix4());
                            }

                            GL.batch.setProjectionMatrix(matrix);
                            drw.drawable.draw(GL.batch, 0, 0, width, height, 0);
                        }

                        if (m_fbo != null) {
                            GL.batch.end();
                            m_fbo.end();
                            m_fboEnabled = false;
                        }

                        FBOisDrawed = true;
                        FBO_DrawingTime = System.currentTimeMillis() - start;
                        Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
                        GL.batch.setProjectionMatrix(oriMatrix);

                        m_fboEnabled = false;
                    } catch (Exception e) {
                        e.printStackTrace();

                    }
                }
            }

        });

    }

    if (m_fboRegion != null) {

        // TODO clear and release the drawables that drawed on m_fboRegion
        // if first drawing of m_fboRegion

        batch.draw(m_fboRegion, x, y, width, height);
    } else {

        int count = 0;

        for (int i = 0, n = drawableList.size(); i < n; i++) {
            MatrixDrawable drw = drawableList.get(i);
            if (!drw.reaelDraw)
                continue;
            if (count++ > 2500) {
                GL.batch.flush();
                count = 0;
            }
            Matrix4 matrix = thisDrawMatrix.cpy();
            if (drw.matrix != null)
                matrix.mul(drw.matrix.getMatrix4());

            GL.batch.setProjectionMatrix(matrix);

            drw.drawable.draw(GL.batch, 0, 0, width, height, 0);
        }

    }
}

From source file:com.badlogic.gdx.tests.g3d.shadows.system.FirstPassBaseShadowSystem.java

License:Apache License

protected void beginPass1() {
    allocator.begin();
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
}

From source file:com.badlogic.gdx.tests.g3d.shadows.system.FirstPassBaseShadowSystem.java

License:Apache License

protected void endPass1() {
    allocator.end();
    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
}

From source file:com.bladecoder.engineeditor.ui.SceneList.java

License:Apache License

private TextureRegion createBgIcon(String atlas, String region) {
    TextureAtlas a = new TextureAtlas(Gdx.files
            .absolute(Ctx.project.getProjectPath() + "/" + Project.ATLASES_PATH + "/1/" + atlas + ".atlas"));
    AtlasRegion r = a.findRegion(region);

    if (r == null) {
        a.dispose();/*from  w ww. jav  a2 s . c  om*/
        return null;
    }

    FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, 200,
            (int) (r.getRegionHeight() * 200f / r.getRegionWidth()), false);

    SpriteBatch fboBatch = new SpriteBatch();
    fboBatch.setColor(Color.WHITE);
    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight());
    fboBatch.setProjectionMatrix(camera.combined);

    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
    fbo.begin();
    fboBatch.begin();
    fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight());
    fboBatch.end();

    TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight());
    // tex.flip(false, true);

    fbo.end();
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);

    fbo.dispose();
    a.dispose();
    fboBatch.dispose();

    return tex;
}

From source file:com.gmail.bleedobsidian.logicbuilder.screens.builder.BuilderScreen.java

License:Open Source License

@Override
public void render(float delta) {
    this.update(null, delta);

    Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    this.gallerySpriteBatch.setProjectionMatrix(LogicBuilder.getInstance().getGalleryCamera().combined);
    this.gridSpriteBatch.setProjectionMatrix(LogicBuilder.getInstance().getGridCamera().combined);

    Gdx.gl20.glEnable(GL20.GL_SCISSOR_TEST);
    Gdx.gl20.glScissor(300, 0, 1000, LogicBuilder.TARGET_HEIGHT);
    this.gridSpriteBatch.begin();
    this.gridManager.render(this.gridSpriteBatch);
    this.componentManager.render(this.gridSpriteBatch);
    this.gridSpriteBatch.end();
    Gdx.gl20.glDisable(GL20.GL_SCISSOR_TEST);
    LogicBuilder.getInstance().getGalleryCamera().update();

    Gdx.gl20.glEnable(GL20.GL_SCISSOR_TEST);
    Gdx.gl20.glScissor(0, 0, 300, LogicBuilder.TARGET_HEIGHT);
    this.gallerySpriteBatch.begin();
    this.galleryManager.render(this.gallerySpriteBatch);
    this.gallerySpriteBatch
            .draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Devider.png"), 293, 0);
    this.gallerySpriteBatch.end();
    Gdx.gl20.glDisable(GL20.GL_SCISSOR_TEST);
}

From source file:com.gmail.bleedobsidian.logicbuilder.screens.builder.managers.GalleryManager.java

License:Open Source License

@Override
public void render(SpriteBatch spriteBatch) {

    // Gallery//  www . j  ava  2 s.c  o m
    spriteBatch.draw(
            LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic-Gates-Title.png"), 0,
            680);

    spriteBatch.draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/AND.png"),
            25, 575);
    spriteBatch.draw(
            LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/NAND.png"), 165,
            575);
    spriteBatch.draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/OR.png"),
            25, 475);
    spriteBatch.draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/NOR.png"),
            165, 475);
    spriteBatch.draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/XOR.png"),
            25, 375);
    spriteBatch.draw(
            LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/XNOR.png"), 165,
            375);
    spriteBatch.draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Logic Gates/NOT.png"),
            25, 275);

    spriteBatch.draw(
            LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Input-Output-Title.png"), 0,
            175);
    //

    // Snapping
    if (this.isMouseDown) {
        spriteBatch.draw(
                LogicBuilder.getInstance().getResourceManager()
                        .getTexture(this.componentCurrentlyDragging.getTexturePath()),
                Gdx.input.getX() - 50, (LogicBuilder.TARGET_HEIGHT - Gdx.input.getY()) - 38);
        spriteBatch.end();

        Gdx.gl20.glDisable(GL20.GL_SCISSOR_TEST);

        Gdx.gl20.glEnable(GL20.GL_SCISSOR_TEST);
        Gdx.gl20.glScissor(300, 0, 1000, LogicBuilder.TARGET_HEIGHT);

        Vector3 touchLocation = LogicBuilder.getInstance().getGridCamera()
                .unproject(new Vector3(Gdx.app.getInput().getX(), Gdx.app.getInput().getY(), 0));

        LogicBuilder.getInstance().getBuilderScreen().getGridSpriteBatch().begin();

        Vector3 mouseCoords = LogicBuilder.getInstance().getGridCamera()
                .unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
        int gridX = GridManager.getGridX((int) mouseCoords.x);
        int gridY = GridManager.getGridY((int) mouseCoords.y);

        if (gridX == -1 | gridY == -1) {
            LogicBuilder.getInstance().getBuilderScreen().getGridSpriteBatch()
                    .draw(LogicBuilder.getInstance().getResourceManager()
                            .getTexture(this.componentCurrentlyDragging.getTexturePath()), touchLocation.x - 50,
                            touchLocation.y - 38);
            this.isComponentSnapped = false;
        } else {
            int leftGrid = GridManager.getGridX((int) (mouseCoords.x
                    - ((this.componentCurrentlyDragging.getGridWidth() / 2) * GridManager.GRID_WIDTH)));
            int rightGrid = GridManager.getGridX((int) (mouseCoords.x
                    + ((this.componentCurrentlyDragging.getGridWidth() / 2) * GridManager.GRID_WIDTH)
                    - (GridManager.GRID_WIDTH / 2)));
            int topGrid = GridManager.getGridY((int) (mouseCoords.y
                    + ((this.componentCurrentlyDragging.getGridHeight() / 2) * GridManager.GRID_HEIGHT)
                    + (GridManager.GRID_HEIGHT / 2)));
            int bottomGrid = GridManager.getGridY((int) (mouseCoords.y
                    - ((this.componentCurrentlyDragging.getGridHeight() / 2) * GridManager.GRID_HEIGHT)));

            if (leftGrid == -1 | rightGrid == -1 | topGrid == -1 | bottomGrid == -1) {
                LogicBuilder.getInstance().getBuilderScreen().getGridSpriteBatch()
                        .draw(LogicBuilder.getInstance().getResourceManager()
                                .getTexture(this.componentCurrentlyDragging.getTexturePath()),
                                touchLocation.x - 50, touchLocation.y - 38);
                this.isComponentSnapped = false;
            } else {
                if (!(LogicBuilder.getInstance().getBuilderScreen().getComponentManager()
                        .isIntersecting(leftGrid, bottomGrid)
                        || LogicBuilder.getInstance().getBuilderScreen().getComponentManager()
                                .isIntersecting(leftGrid, topGrid)
                        || LogicBuilder.getInstance().getBuilderScreen().getComponentManager()
                                .isIntersecting(rightGrid, bottomGrid)
                        || LogicBuilder.getInstance().getBuilderScreen().getComponentManager()
                                .isIntersecting(rightGrid, topGrid))) {
                    LogicBuilder.getInstance().getBuilderScreen().getGridSpriteBatch()
                            .draw(LogicBuilder.getInstance().getResourceManager()
                                    .getTexture(this.componentCurrentlyDragging.getTexturePath()),
                                    GridManager.gridXToX(leftGrid), GridManager.gridYToY(bottomGrid));
                    this.isComponentSnapped = true;
                } else {
                    LogicBuilder.getInstance().getBuilderScreen().getGridSpriteBatch()
                            .draw(LogicBuilder.getInstance().getResourceManager()
                                    .getTexture(this.componentCurrentlyDragging.getTexturePath()),
                                    touchLocation.x - 50, touchLocation.y - 38);
                    this.isComponentSnapped = false;
                }
            }
        }

        LogicBuilder.getInstance().getBuilderScreen().getGridSpriteBatch().end();

        Gdx.gl20.glDisable(GL20.GL_SCISSOR_TEST);

        Gdx.gl20.glEnable(GL20.GL_SCISSOR_TEST);
        Gdx.gl20.glScissor(0, 0, 300, LogicBuilder.TARGET_HEIGHT);
        spriteBatch.begin();
    }
    //
}

From source file:com.mygdx.tmxTest.TiledMapTextureBleeding.java

License:Apache License

@Override
public void render() {
    Gdx.gl.glClearColor(1, 0, 0, 1);/*from w w w .j  ava 2  s . co  m*/
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    mapController.update();

    int h = Gdx.graphics.getHeight();
    int halfW = Gdx.graphics.getWidth() / 2;

    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
    Gdx.gl.glScissor(0, 0, halfW - 8, h);

    cameraPadding.update();
    rendererPadding.setView(cameraPadding);
    rendererPadding.render();

    Gdx.gl.glScissor(halfW + 8, 0, halfW, h);

    cameraNoPadding.update();
    rendererNoPadding.setView(cameraNoPadding);
    rendererNoPadding.render();

    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);

    batch.begin();
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    font.draw(batch, "MAP WITH PADDING: ", Gdx.graphics.getWidth() / 6, 20);
    font.draw(batch, "MAP WITHOUT PADDING", Gdx.graphics.getWidth() * 2 / 3, 20);
    batch.end();
}