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:espresso3d.engine.E3DEngine.java

License:Open Source License

/**
 *  Render the current world at a given position.  This is automatically called by the engine
 *///from  w  w w .  j  a  v a2s.c o m
public void render() {
    //Loop through each viewport
    // rendering the viewport's world at the viewport's cameraActors position/orientation
    Iterator viewPortIterator = window.getViewportMap().entrySet().iterator();
    Map.Entry viewPortEntry = null;

    //Loop through each viewport rendering the scene

    //Be sure to clear the screen only once, and depth buffer for each viewport
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); // Clear Screen
    while (viewPortIterator.hasNext()) {
        viewPortEntry = (Map.Entry) viewPortIterator.next();
        currentViewport = (E3DViewport) viewPortEntry.getValue();

        if (currentViewport == primarySoundViewport)
            soundHandler.setListener(currentViewport.getCameraActor());

        GL11.glPushMatrix();
        //Setup the viewport - switch to this viewport for rendering
        currentViewport.switchToViewport();

        //Render the world which in turn renders all sectors, actors, etc.
        E3DWorld curWorld = currentViewport.getWorld();
        if (curWorld != null) //Viewports don't necessarily have to have worlds, so skip the world rendering things in that case
        {
            GL11.glPushMatrix(); //Each external renderable should be on its own stack so it can make GL calls and not affect other things
            curWorld.render();
            GL11.glPopMatrix();
        }

        //****************External Renderables****************//
        //render the external renderables added by the users
        E3DExternalRenderable renderable = null;
        for (int i = 0; i < externalRenderables.size(); i++) {
            renderable = (E3DExternalRenderable) externalRenderables.get(i);
            if (!renderable.update()) {
                externalRenderables.remove(i);
                i--;
            } else {
                GL11.glPushMatrix(); //Each external renderable should be on its own stack so it can make GL calls and not affect other things
                renderable.getRenderable().render();
                GL11.glPopMatrix();
            }
        }
        //****************2D Text and Image Rendering - Should be last to be on top of everythign else *************//
        //FIXME: TODO: There is a serious bug in projection/unprojection.
        // This fixes fonts by loading the identity matrix, but it doesn't
        // resolve the issue NOR does it resolve the portal projection issue (which is a much bigger deal).
        GL11.glPushMatrix();
        currentViewport.render();
        GL11.glPopMatrix();

        GL11.glPopMatrix();
    } //End viewport list loop

    //Render the windows GUI stuff that is viewport independent
    GL11.glPushMatrix();
    window.getGuiHandler().render();
    GL11.glPopMatrix();

    Display.update();

    //************FPS Timer*********************//
    fpsTimer.update();
    window.update();

    /*** Sound Handler ******/
    soundHandler.discardOldSounds(); //clear out any stopped sound source from memory
}

From source file:espresso3d.engine.window.viewport.E3DViewport.java

License:Open Source License

/**
 * This will automatically be called by the engine.  Users needn't worry about this.
 * Sets the perspective to the values stored in this viewport.  This keeps track of whether
 * the values have changed or not, so it will keep the GL calls to a minimum (only set the perspective
 * if something has actually changed)./*from   ww w. j a  v a  2 s . c o  m*/
 *
 */
private void setPerspective() {
    if (perspectiveChanged) {
        GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
        GL11.glLoadIdentity(); // Reset The Projection Matrix

        if (mode == VIEWPORT_MODE_PERSPECTIVE) {
            // Calculate The Aspect Ratio Of The Window
            GLU.gluPerspective((float) fovY, (float) ((float) width / (float) height), (float) nearClipPlane,
                    (float) farClipPlane);
        } else if (mode == VIEWPORT_MODE_ORTHOGRAPHIC)
            GL11.glOrtho(left * orthoZoom, right * orthoZoom, bottom * orthoZoom, top * orthoZoom,
                    nearClipPlane, farClipPlane); //todo: this needs to center around the camera.  Need to determin whether to use X/Y, Y/Z, or X/Z to center on

        recalcProjectionViewMatrix();

        perspectiveChanged = false;
    }

    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Modelview Matrix

    GL11.glDepthMask(true); //Re-enable this.  IF particles turn this off, it has to be turned on to be able to clear the depth buffer
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

    GLU.gluLookAt((float) cameraActor.getOrientation().getPosition().getX(),
            (float) cameraActor.getOrientation().getPosition().getY(),
            (float) cameraActor.getOrientation().getPosition().getZ(),
            ((float) (cameraActor.getOrientation().getPosition().getX()
                    + cameraActor.getOrientation().getForward().getX())),
            ((float) (cameraActor.getOrientation().getPosition().getY()
                    + cameraActor.getOrientation().getForward().getY())),
            ((float) (cameraActor.getOrientation().getPosition().getZ()
                    + cameraActor.getOrientation().getForward().getZ())),
            (float) cameraActor.getOrientation().getUp().getX(),
            (float) cameraActor.getOrientation().getUp().getY(),
            (float) cameraActor.getOrientation().getUp().getZ());

    //If something has changed camera wise, we need to recalculate the viewport matrix 
    // the next time something asks for a projection or unprojection
    if (!cameraActor.getOrientation().getPosition().equals(lastPosition)
            || !cameraActor.getOrientation().getForward().equals(lastForward)
            || !cameraActor.getOrientation().getUp().equals(lastUp)) {
        lastPosition.set(cameraActor.getOrientation().getPosition());
        lastForward.set(cameraActor.getOrientation().getForward());
        lastUp.set(cameraActor.getOrientation().getUp());
        needViewArrayRecalc = true;
    }
}

From source file:eu.over9000.veya.gui.Gui.java

License:Open Source License

private static void render() {
     GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
     font.drawString(5, 5, renderString.toString() + ' ' + cnt++ + " ", Color.WHITE);
 }

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void preRender() {
    Veya.program_shadow.use(true);/*from w  w w .j  a v a2 s  . c  o  m*/
    updateMatrixLightSpaceMatrixLocation();
    GL11.glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, shadowFBO);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glCullFace(GL11.GL_FRONT);

}

From source file:eu.over9000.veya.Veya.java

License:Open Source License

private static void run() {
    Util.checkGLError();//w  ww.j av a2 s.  c  o  m

    Veya.program_normal.use(true);
    Veya.camera.updateProjectionMatrix(Display.getWidth(), Display.getHeight());
    Veya.camera.updateViewMatrix();
    Veya.scene.init();

    Veya.program_normal.use(false);

    program_normal.use(true);
    GL20.glUniform1i(Veya.program_normal.getUniformLocation("colorSwitch"), Veya.colorSwitch ? 1 : 0);
    program_normal.use(false);

    program_normal.use(true);
    GL20.glUniform1i(Veya.program_normal.getUniformLocation("aoSwitch"), Veya.aoSwitch ? 1 : 0);
    program_normal.use(false);

    Util.checkGLError();

    long start = Sys.getTime();
    long lastTime = start;
    long count = 0;

    while (!Display.isCloseRequested() && !shutdown) {
        final long time = Sys.getTime();
        final float dt = (time - lastTime) / 1000.0f;
        lastTime = time;

        checkResize();

        handleMovementKeys(dt);
        handleOtherKeys();
        handleMouseInput();

        if (gravitySwitch) {
            Veya.camera.applyGravity(dt);
        }

        Veya.camera.performMove();

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        Veya.program_normal.use(true);

        if (ENABLE_DAY_NIGHT) {
            final float posX = (float) Math.sin(System.currentTimeMillis() / 10000.0) * 512;
            final float posY = (float) Math.cos(System.currentTimeMillis() / 10000.0) * 512;
            // final float posZ = (float) Math.cos(System.currentTimeMillis() / 1500.0) * 20f;
            ambient = 0.25f + MathUtil.scale(posY, -1024, 1024, 0, 0.55f);
            diffuse = MathUtil.scale(posY, -1024, 1024, 0, 0.5f);
            specular = MathUtil.scale(posY, -1024, 1024, 0, 0.5f);
            final float kek = (posY / 1024f + 1) / 2;

            GL11.glClearColor(kek * 124f / 255f, kek * 169f / 255f, kek * 255f / 255f, 1.0f);
            Veya.scene.getLight().updateLightPosition(posX + Veya.camera.getPosition().getX(), posY,
                    1 + Veya.camera.getPosition().getZ());
        }

        //Veya.scene.getLight().updateLightPosition(Veya.camera.getPosition().getX() + 1, 500, Veya.camera.getPosition().getZ() + 250);

        Veya.camera.updateViewMatrix();
        Veya.camera.updateCameraPosition();
        Veya.scene.getLight().updateLightFactors(Veya.ambient, Veya.diffuse, Veya.specular);
        Veya.scene.render();

        Util.checkGLError();

        Veya.program_normal.use(false);

        Display.update();
        // Display.sync(60);
        Util.checkGLError();

        final long end = Sys.getTime();
        if (end - start > 1000) {
            start = end;
            frame.setTitle("VEYA | fps: " + count + " | pos: x=" + Veya.camera.getPosition().x + ", y="
                    + Veya.camera.getPosition().y + ", z=" + Veya.camera.getPosition().z
                    + " | #chunks displayed: " + Veya.scene.getChunkCount() + " | lightFactors: A="
                    + Veya.ambient + ", D=" + Veya.diffuse + ", S=" + Veya.specular + " | chunk updates: "
                    + scene.chunkUpdateCounterInRender.get() + "/" + scene.chunkUpdateCounterOffRender.get()
                    + " | selected block: " + scene.placeBlockType);
            count = 0;
            scene.chunkUpdateCounterInRender.set(0);
            scene.chunkUpdateCounterOffRender.set(0);

        } else {
            count++;
        }
    }
}

From source file:fable.framework.ui.views.chiPlotView.java

License:Open Source License

/**
 * Display list (glCallList )created and compiled previously in
 * drawReliefList./*from w ww  .  j  a v a 2s. c  o  m*/
 * 
 */
static void drawRelief() {
    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    if (!freeze)
        grip.adjust();
    if (image != null) {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glDisable(GL11.GL_LIGHTING);
        // Execute a display list here
        GL11.glCallList(reliefList);
        GL11.glEnable(GL11.GL_LIGHTING);
    }
}

From source file:fable.imageviewer.views.ReliefView.java

License:Open Source License

private void drawRelief() {
    canvas.setCurrent();/* w  ww.  jav  a2s .c om*/
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException ex) {
        FableUtils.excMsg(ReliefView.class, "Error in drawRelief using GLContext.useContext", ex);
    }
    // context.makeCurrent();
    // gl = context.getGL ();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    if (!freeze)
        grip.adjust();
    if (image != null) {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glCallList(reliefList);
        GL11.glEnable(GL11.GL_LIGHTING);
    }
}

From source file:fable.imageviewer.views.ReliefView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    thisView = this;
    parent.setLayout(new GridLayout(1, false));
    GridUtils.removeMargins(parent);//from  www  . j a  v a  2  s . c om

    createActions();

    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    canvas = new GLCanvas(comp, SWT.NONE, data);
    canvas.setSize(comp.getSize());
    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException ex) {
        FableUtils.excMsg(ReliefView.class, "Error in createPartControl using GLContext.useContext", ex);
    }
    // context = GLDrawableFactory.getFactory().createExternalGLContext();
    canvas.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            // float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException ex) {
                FableUtils.excMsg(ReliefView.class, "Error in resize listener using GLContext.useContext", ex);
            }
            // context.makeCurrent();
            // GL11 gl = context.getGL ();
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            // GLU glu = new GLU();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
            drawRelief();
            canvas.swapBuffers();
            // context.release();
        }
    });
    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException ex) {
        FableUtils.excMsg(ReliefView.class, "Error in createPartControl using GLContext.useContext", ex);
    }
    // GL11 gl = context.getGL ();
    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    // context.release();
    // create the grip for users to change the orientation, translation and
    // zoom
    grip = new SceneGrip(canvas, this);
    canvas.addMouseListener(grip);
    canvas.addMouseMoveListener(grip);
    canvas.addListener(SWT.MouseWheel, grip);
    canvas.addKeyListener(grip);
    // apparently opengl has to be redrawn constantly (why ?)
    Display.getCurrent().asyncExec(new Runnable() {
        // int rot = 0;
        public void run() {
            if (canvas == null)
                return;
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                Rectangle bounds = canvas.getBounds();
                grip.setBounds(bounds);
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException ex) {
                    FableUtils.excMsg(ReliefView.class,
                            "Error in createPartControl using " + "GLContext.useContext", ex);
                }
                // GL11 gl = context.getGL ();
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.0f, .0f, .0f, 1.0f); // black background
                drawRelief();
                canvas.swapBuffers();
                // context.release();
                Display.getCurrent().timerExec(200, this);
            }
        }
    });

    createImageInformationPanel(parent);
}

From source file:flash.display.Stage.java

License:Open Source License

@Override
protected final void JITB$render() {
    ////from   w w  w.j a  v a  2s .  com
    // Clear the screen when the stage is re-rendered.
    //

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    //
    // Translate corresponding to stage align.
    //

    GL11.glTranslatef(0.0f, 0.0f, 0.0f);

    //
    // Now render all children of the stage.
    //

    JITB$renderChildren();
}

From source file:fr.def.iss.vd2.lib_v3d.V3DCanvas.java

License:Open Source License

/**
 * Sets up the screen.// www .  j a  v a2  s .co m
 *
 * @see javax.media.openGL11.GLEventListener#init(javax.media.openGL11.GLAutoDrawable)
 */
public void init() {
    try {

        frame = new JFrame("Space agencies");
        //frame.setSize(width,height);
        //frame.setUndecorated(true);  //here
        frame.setVisible(true);
        //frame.setAlwaysOnTop(true);
        frame.setLocation(0, 0);
        Canvas canvas = new Canvas();
        canvas.setMinimumSize(new Dimension(800, 600));
        canvas.setPreferredSize(new Dimension(width, height));
        frame.add(canvas);
        frame.pack();
        frame.addWindowListener(generateWindowListener());

        frame.getContentPane().addHierarchyBoundsListener(new HierarchyBoundsListener() {

            @Override
            public void ancestorMoved(HierarchyEvent e) {
            }

            @Override
            public void ancestorResized(HierarchyEvent e) {
                width = frame.getContentPane().getWidth();
                height = frame.getContentPane().getHeight();
                reshape(0, 0, width, height);
            }
        });

        Display.setDisplayMode(new DisplayMode(width, height));
        //Display.setFullscreen(true);
        Display.setVSyncEnabled(false);
        Display.setTitle("Space agencies");
        Display.setParent(canvas);
        Display.create();
        canvas.requestFocus();
    } catch (Exception e) {
        System.out.println("Error setting up display" + e);
        System.exit(0);
    }

    // Enable z- (depth) buffer for hidden surface removal.
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glEnable(GL11.GL_POINT_SMOOTH);

    if (polygonOffset) {
        GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
        GL11.glPolygonOffset(1.0f, 1.0f);
    }
    GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
    GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);

    GL11.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);

    // Enable smooth shading.
    GL11.glShadeModel(GL11.GL_SMOOTH);

    // Define "clear" color.
    GL11.glClearColor(0f, 0f, 0.4f, 0f);

    // We want a nice perspective.
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glFlush();

    TextureManager.clearCache();
    initied = true;

    //        new LWJGLBinding();

}