Example usage for org.lwjgl.opengl GL11 glClear

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

Introduction

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

Prototype

public static void glClear(@NativeType("GLbitfield") int mask) 

Source Link

Document

Sets portions of every pixel in a particular buffer to the same value.

Usage

From source file:com.runescape.client.revised.client.lwjgl.RenderUtilities.java

License:Open Source License

public static void clearScreen() {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
}

From source file:com.runescape.client.revised.editor.modelviewer.Main.java

License:Open Source License

public static void main(final String[] args) {
    Main.setMain(new Main());
    try {//from  w w w  .j a va 2 s. c o  m
        Main.getMain().setCanvas(Main.getMain().setup("RuneScape Model Viewer", 1024, 768, true));
    } catch (final Exception e) {
        e.printStackTrace();
    }
    final Canvas canvas = Main.getMain().getCanvas();
    final Frame frame = (Frame) canvas.getParent();
    if (frame == null) {
        return;
    }
    try {
        Main.initialize(canvas);
        Main.getMain().setViewport(new Viewport(canvas));
        final long[] timerCache = new long[10];
        long timerCur = 0L;
        long timerDst = 0L;
        long timerLast = 0L;
        final long timerRate = (1000000L * 1000L) / 60L;
        int timerCacheIndex = 0;
        int timerCacheSize = 0;
        final boolean minSleep = Runtime.getRuntime().availableProcessors() <= 1;
        final long[] clockCache = new long[32];
        int clockIndex = 0;
        while (frame.isVisible()) {
            final long clock = System.nanoTime();
            final long lastClock = clockCache[clockIndex];
            clockCache[clockIndex] = clock;
            if (++clockIndex == 32) {
                clockIndex = 0;
            }

            if ((lastClock != 0L) && (clock > lastClock)) {
                if (frame != null) {
                    // frame.setTitle("" + fps);
                }
            }
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
            GL11.glClearColor(.5F, .6F, .9F, 1F);
            Main.getMain().viewport.render();
            if (minSleep) {
                try {
                    Thread.sleep(1L);
                } catch (final Exception ex) {
                }
            }

            timerCache[timerCacheIndex++] = System.nanoTime();
            if (timerCacheSize < timerCacheIndex) {
                timerCacheSize = timerCacheIndex;
            }

            if (timerCacheIndex == 10) {
                timerCacheIndex = 0;
            }

            long time = 0L;
            for (int i = 0; i != timerCacheSize; time += timerCache[i++]) {
                ;
            }

            time /= timerCacheSize;
            if (timerCacheSize == 1) {
                timerLast = time;
            }

            timerCur += time - timerLast;
            timerLast = time;
            timerDst += timerRate;
            if (timerDst > timerCur) {
                final long sleep = timerDst - timerCur;
                try {
                    Thread.sleep(sleep / 1000000L, (int) (sleep % 1000000L));
                } catch (final Exception ex) {
                }
                timerCur = timerDst;
                for (int i = 0; i != timerCacheSize; ++i) {
                    timerCache[i] += sleep;
                }

                timerLast += sleep;
            }
        }
    } catch (final LWJGLException e) {
        e.printStackTrace();
    } finally {
        Main.dispose(frame);
    }
}

From source file:com.rvantwisk.cnctools.controls.opengl.OpenGLRenderer.java

License:Open Source License

protected void loop() {
    final ReadonlyCamera localCam;
    synchronized (this) {
        localCam = this.camera;
        if (actors.size() > 0) {
            for (AbstractActor actor : actors) {
                // CHeck if a existing axctor already exists, if so destroy it
                if (activeActors.containsKey(actor.getName())) {
                    final AbstractActor existingActor = activeActors.get(actor.getName());
                    existingActor.destroy();
                }// www.j  a v a 2 s. c  o  m
                // Add a new actor
                actor.initialize();
                activeActors.put(actor.getName(), actor);
            }
            actors.clear();
        }
    }

    viewAxis.setCamera(localCam);
    viewModel.setCamera(localCam);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glCullFace(GL11.GL_BACK);
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);

    // Draw axis in lower left corner
    viewAxis.begin();
    drawAxis(25f);
    viewAxis.end();

    // Prepare actors for next drawing sequence
    for (final AbstractActor actor : activeActors.values()) {
        actor.prepare();
    }

    viewModel.begin();
    viewModel.display_transform();

    // Draw the actor
    for (final AbstractActor actor : activeActors.values()) {
        actor.draw();
    }

    viewModel.end();
}

From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java

License:Mozilla Public License

private void doPaint() {
    if (isDisposed() || mNode == null) {
        return;/*from  w  w w  .j a  v  a  2 s.  co m*/
    }

    setCurrent();

    // Clear the color, depth and stencil buffers.
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

    GL11.glLoadIdentity();

    GLU.gluLookAt(0.0f, 0.0f, mCamera.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    // Transformations happen in the reverse.
    if (mIsOrtho) {
        // User's translation.
        GL11.glTranslatef(mOrthoTranslate.x, mOrthoTranslate.y, 0.0f);

        // Rotate 180 degrees.
        GL11.glRotatef(180.0f, 1.0f, 0.0f, 0.0f);

        // Center the nodes.
        final Rectangle bounds = getBounds();
        final float scaledWidth = mNode.bounds.width * mOrthoScale;
        final float scaledHeight = mNode.bounds.height * mOrthoScale;
        GL11.glTranslatef((bounds.width - scaledWidth) / 2, 0.0f, 0.0f);

        // Scale based on viewport size.
        GL11.glTranslatef(scaledWidth / 2, -scaledHeight / 2, 0.0f);
        GL11.glScalef(mOrthoScale, mOrthoScale, 0.0f);
        GL11.glTranslatef(-scaledWidth / 2, scaledHeight / 2, 0.0f);

    } else {
        // Translate all the nodes.
        GL11.glTranslatef(mTranslate.x, mTranslate.y, 0.0f);

        // Rotate.
        GL11.glRotatef(mRotate.x, 1.0f, 0.0f, 0.0f);
        GL11.glRotatef(mRotate.y, 0.0f, 1.0f, 0.0f);

        // Center the nodes.
        GL11.glTranslatef(-mNode.bounds.width / 2, mNode.bounds.height / 2, 0.0f);
    }

    final float absX = Math.abs(mRotate.x);
    final float absY = Math.abs(mRotate.y);
    mDepth = Math.max(absX, absY) * 5 / 9.0f;

    drawHierarchy(mNode);

    if (!mIsPicking && mIsOrtho && mShowOverdraw) {
        for (int i = 2; i <= 5; i++) {
            drawOverdraw(i);
        }
    }

    GL11.glFlush();

    if (!mIsPicking) {
        swapBuffers();
    }
}

From source file:com.telinc1.rpjg.Game.java

License:Apache License

public void start() {
    // Start logging.
    Configurator.defaultConfig().writer(new ConsoleWriter())
            .formatPattern("[{date:yyyy-MM-dd HH:mm:ss}] [{level}] [{class_name}] {message}").activate();
    Logger.info("Creating and initializing game.");

    // Create the display.
    try {/*from   w ww  .jav a  2  s  . co  m*/
        Display.setTitle(GameOptions.GAME_NAME);
        Display.setResizable(false);
        Display.setDisplayMode(new DisplayMode(640, 360));
        Display.setVSyncEnabled(true);
        Display.setFullscreen(false);

        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(ExitCodes.INIT_DISPLAY);
    } finally {
        this.isRunning = true;
        Logger.info("Finished display creation.");
    }

    // Initialize OpenGL.
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0f, 0f, 0f, 0f);
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    // Load all textures.
    TextureLoader.initialize();

    // Initialize the game.
    this.initialize();

    // Load the default map.
    this.loadMap("dungeon");
    ModuleManager.getInstance().openModule(new ModuleMap());

    // Main game loop
    while (this.isRunning() && !Display.isCloseRequested()) {
        // Clear the screen from the previous frame.
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

        this.loop();
        this.draw();
        this.collectInput();

        // Sync and update the display.
        Display.update();
        Display.sync(GameOptions.FRAME_RATE);
    }

    // Free up all resources and exit.
    Logger.info("Close requested!");

    TextureLoader.destroy();
    Display.destroy();

    Logger.info("Resources destroyed - exiting.");
    System.exit(ExitCodes.CLOSE_REQUESTED);
}

From source file:com.voxelplugineering.voxelsniper.render.RenderMain.java

License:Open Source License

public void tick() {
    if (!setup) {
        return;//  w w w. jav a 2  s.  c o  m
    }
    Camera camera = Standalone.system().getMainCamera();

    // reset view matrix
    viewMatrix.setIdentity();

    // Translate camera
    Vector3f rot = camera.getCameraRot();
    Matrix4f.rotate(rot.x, new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate(rot.y, new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate(rot.z, new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
    Matrix4f.translate(camera.getCameraPos(), viewMatrix, viewMatrix);

    GL20.glUseProgram(pId);

    // push matrices
    viewMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
    modelMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
    projectionMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    // bind textures
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.textures.get("block"));

    // render all buffer sections
    buffer.renderSections();

    GL20.glUseProgram(0);

    OpenGLUtilities.checkGLError("render main");

    Display.update();
}

From source file:com.xrbpowered.gl.examples.ExampleClient.java

License:Open Source License

@Override
public void redraw(RenderTarget target) {
    if (uiGraphPane.isVisible())
        uiGraphPane.repaint();//from   w w  w.  j  ava 2 s  .  c  o  m

    RenderTarget drawTarget = target;
    if (offscreenBuffers != null) {
        offscreenBuffers.use();
        drawTarget = offscreenBuffers;
    }

    GL11.glClearColor(CLEAR_COLOR.getRed() / 255f, CLEAR_COLOR.getGreen() / 255f, CLEAR_COLOR.getBlue() / 255f,
            0f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    if (wireframe)
        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
    drawObjects(drawTarget);
    if (wireframe)
        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);

    if (offscreenBuffers != null) {
        offscreenBuffers.resolve();
        target.use();
        drawOffscreenBuffers(offscreenBuffers, target);
    }
}

From source file:com.xrbpowered.gl.res.shaders.PostProcessRenderer.java

License:Open Source License

@Override
public void redraw(RenderTarget target) {
    if (requestUpdate || updatePerFrame) {
        redrawBackgroundBuffer(); //updatePerFrame ? dt : 0f);
    }/*ww  w. j av  a  2s . co m*/

    if (bgBuffer != null) {
        if (postProc == null)
            blit(bgBuffer, target);
        else {
            GL11.glDisable(GL11.GL_CULL_FACE);
            interBuffer.use();
            postProc.draw(bgBuffer);
            blit(interBuffer, target);
        }
        target.use();
    } else {
        target.use();
        GL11.glClearColor(clearColor.getRed() / 255f, clearColor.getGreen() / 255f, clearColor.getBlue() / 255f,
                0f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

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;//from   w w  w  . j  a  va  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:com.xrbpowered.gl.ui.AbstractLoadScreen.java

License:Open Source License

private void display() {
    GL11.glClearColor(clearColor.getRed() / 255f, clearColor.getGreen() / 255f, clearColor.getBlue() / 255f,
            0f);//w w w .  j a va  2 s  .c  o m
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    uiPane.x = Display.getWidth() / 2 - uiPane.getWidth() / 2;
    uiPane.y = Display.getHeight() / 2 - uiPane.getHeight() / 2;
    ui.draw(Display.getWidth(), Display.getHeight());
    Display.update();
}