Example usage for org.lwjgl.opengl GL11 glClearDepth

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

Introduction

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

Prototype

public static void glClearDepth(@NativeType("GLdouble") double depth) 

Source Link

Document

Sets the depth value used when clearing the depth buffer.

Usage

From source file:akarnokd.opengl.experiment.FontExample.java

License:Apache License

/**
 * Initialise the GL display/* ww w  .ja v a2 s .co m*/
 * 
 * @param width The width of the display
 * @param height The height of the display
 */
private void initGL(int width, int height) {
    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.create();
        Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

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

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.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, width, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, height, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:cellularautomata.CellularAutomata.java

public static void renderGL() {
    try { //Trys to create a game window size 500x700.
        Display.setDisplayMode(new org.lwjgl.opengl.DisplayMode(800, 600));
        Display.create();/* w  w  w . j av  a 2 s .c  o m*/
    } catch (LWJGLException e) { //Catches exception if game window is not created.
        e.printStackTrace();
        System.exit(0);
    }

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

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Sets colour to white.
    GL11.glClearDepth(1);

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

    GL11.glViewport(0, 0, 800, 600);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 800, 600, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    Display.setVSyncEnabled(vsync);
}

From source file:com.aelitis.azureus.plugins.view3d.ViewTest2.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;/*from w w w . ja v  a2s  .  com*/
    data.accumAlphaSize = 8;
    data.accumBlueSize = 8;
    data.accumGreenSize = 8;
    data.accumRedSize = 8;

    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    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 e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    GL11.glLineWidth(1);
    GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    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);

    GL11.glShadeModel(GL11.GL_FLAT);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearAccum(0.0f, 0.0f, 0.0f, 0.0f);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    final Runnable run = new Runnable() {
        float rot = 0;

        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }

                int ACSIZE = 8;

                int[] viewport = getViewport();

                GL11.glClear(GL11.GL_ACCUM_BUFFER_BIT);

                for (int jitter = 0; jitter < ACSIZE; jitter++) {
                    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

                    double jit_x = jits[jitter][0];
                    double jit_y = jits[jitter][1];

                    accPerspective(50.0, (double) viewport[2] / (double) viewport[3], 1.0, 15.0, jit_x, jit_y,
                            0.0, 0.0, 1.0);

                    {

                        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                        GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                        GL11.glLoadIdentity();
                        GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                        float frot = rot;
                        GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                        GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
                        GL11.glColor3f(0.9f, 0.9f, 0.9f);
                        drawCylinder(2, 3, 50, 0);
                        drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                    }

                    GL11.glAccum(GL11.GL_ACCUM, 1.0f / ACSIZE);
                }

                GL11.glAccum(GL11.GL_RETURN, 1.0f);
                GL11.glFlush();

                rot += 0.1;

                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    };
    canvas.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            run.run();
        }
    });
    display.asyncExec(run);

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.badlogic.gdx.backends.jglfw.JglfwGL20.java

License:Apache License

public void glClearDepthf(float depth) {
    GL11.glClearDepth(depth);
}

From source file:com.badlogic.gdx.backends.lwjgl.LwjglGL10.java

License:Apache License

public final void glClearDepthf(float depth) {
    GL11.glClearDepth(depth);
}

From source file:com.gameminers.ethereal.architect.ModelCanvas.java

License:Open Source License

@Override
protected void paintGL() {
    try {//w  ww  .j  a  va2  s  .c o  m
        if (getWidth() != current_width || getHeight() != current_height) {
            current_width = getWidth();
            current_height = getHeight();
            GL11.glViewport(0, 0, current_width, current_height);
        }
        GL11.glClearColor(0.0f, 0.6f, 0.5f, 1.0f);
        GL11.glClearDepth(1.0);
        GL11.glColor3f(1, 1, 1);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDepthFunc(GL11.GL_LEQUAL);
        GL11.glLoadIdentity();
        GLU.gluPerspective(45.0f, (float) getWidth() / (float) getHeight(), 0.1f, 1000.0f);
        GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glTranslatef(0, 0, zoom);
        GL11.glRotatef(angle, 0f, 1f, 0f);
        GL11.glRotatef(tilt, 1f, 0f, 0f);
        GL11.glTranslatef(-16, -16, -16);
        if (lit) {
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_LIGHT0);
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, lightPosition);
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, lightAmbient);
        } else {
            GL11.glDisable(GL11.GL_LIGHTING);
        }
        if (textured) {
            GL11.glEnable(GL11.GL_TEXTURE_2D);
        } else {
            GL11.glDisable(GL11.GL_TEXTURE_2D);
        }
        if (model != null) {
            if (model.isAmbientOcclusionEnabled()) {
                GL11.glShadeModel(GL11.GL_SMOOTH);
            } else {
                GL11.glShadeModel(GL11.GL_FLAT);
            }
            for (ModelElement ele : model.getElements()) {
                GL11.glPushMatrix();
                if (ele.isShade()) {
                    GL11.glEnable(GL11.GL_LIGHTING);
                } else {
                    GL11.glDisable(GL11.GL_LIGHTING);
                }
                float fromX = ele.getFrom()[0];
                float fromY = ele.getFrom()[1];
                float fromZ = ele.getFrom()[2];
                float toX = ele.getTo()[0];
                float toY = ele.getTo()[1];
                float toZ = ele.getTo()[2];

                float fX = (fromX > toX ? fromX : toX);
                float fY = (fromY > toY ? fromY : toY);
                float fZ = (fromZ > toZ ? fromZ : toZ);
                float tX = (fromX > toX ? toX : fromX);
                float tY = (fromY > toY ? toY : fromY);
                float tZ = (fromZ > toZ ? toZ : fromZ);

                GL11.glTranslatef(fX, fY, fZ);
                float scaleX = tX - fX;
                float scaleY = tY - fY;
                float scaleZ = tZ - fZ;
                GL11.glBegin(GL11.GL_QUADS);
                GL11.glNormal3f(0, 0, -1f);
                for (int i = 0; i < vertices.length / 3; i++) {
                    int faceIdx = i / 4;
                    ModelFace face;
                    switch (faceIdx) {
                    case 0:
                        face = ele.getFaces().getNorth();
                        break;
                    case 1:
                        face = ele.getFaces().getSouth();
                        break;
                    case 2:
                        face = ele.getFaces().getUp();
                        break;
                    case 3:
                        face = ele.getFaces().getDown();
                        break;
                    case 4:
                        face = ele.getFaces().getWest();
                        break;
                    case 5:
                        face = ele.getFaces().getEast();
                        break;
                    default:
                        face = null;
                        break;
                    }
                    int idx = i * 3;
                    float vX = vertices[idx] * scaleX;
                    float vY = vertices[idx + 1] * scaleY;
                    float vZ = vertices[idx + 2] * scaleZ;
                    /*float u;
                    float v;
                    GL11.glTexCoord2f(u, v);*/
                    GL11.glVertex3f(vX, vY, vZ);
                }
                GL11.glEnd();
                GL11.glPopMatrix();
            }
        }
        GL11.glPopMatrix();
        swapBuffers();
        repaint();
    } catch (LWJGLException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.gameminers.mav.render.Rendering.java

License:Open Source License

public static void setUpGL() {
    GL11.glEnable(GL11.GL_TEXTURE_2D);//from ww  w . j  a  v  a  2  s.c  om
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearDepth(1);

    GL11.glShadeModel(GL11.GL_FLAT);

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

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

License:LGPL

public void endFrame() {
    GL11.glDisable(GL11.GL_CULL_FACE); // Oculus wants CW orientations, avoid the problem by turning off culling...
    GL11.glDisable(GL11.GL_DEPTH_TEST); // Nothing is drawn with depth test on...

    // End the frame
    super.endFrame();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind GL_ARRAY_BUFFER for my own vertex arrays to work...
    GL11.glEnable(GL11.GL_CULL_FACE); // Turn back on...
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Turn back on...
    GL11.glClearDepth(1); // Oculus set this to 0 (the near plane), return to normal...
    ARBShaderObjects.glUseProgramObjectARB(0); // Oculus shader is still active, turn it off...

    Display.processMessages();//  w ww.j a v a2  s .  c  o  m
}

From source file:com.mtbs3d.minecrift.provider.MCOculus.java

License:LGPL

public void endFrame() {
    GL11.glDisable(GL11.GL_CULL_FACE); // Oculus wants CW orientations, avoid the problem by turning off culling...
    GL11.glDisable(GL11.GL_DEPTH_TEST); // Nothing is drawn with depth test on...
    //GL30.glBindVertexArray(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Unbind GL_ARRAY_BUFFER for my own vertex arrays to work...
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    // End the frame
    super.endFrame();

    GL11.glFrontFace(GL11.GL_CCW); // Needed for OVR SDK 0.4.0
    GL11.glEnable(GL11.GL_CULL_FACE); // Turn back on...
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Turn back on...
    GL11.glClearDepth(1); // Oculus set this to 0 (the near plane), return to normal...
    ARBShaderObjects.glUseProgramObjectARB(0); // Oculus shader is still active, turn it off...

    Display.processMessages();//w w  w . j  a v a  2  s.  co  m
}

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

License:LGPL

private void doDistortionAndSuperSample() {
    int FBWidth = this.mc.displayFBWidth;
    int FBHeight = this.mc.displayFBHeight;

    if (this.mc.vrSettings.useDistortion || this.mc.vrSettings.useSupersample || this.mc.vrSettings.useFXAA) {
        // Setup ortho projection
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();//from w  w  w. j a va2s . c o  m
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();

        GL11.glTranslatef(0.0f, 0.0f, -0.7f);
    }

    if (this.mc.vrSettings.useSupersample) {
        FBWidth = (int) ceil(this.mc.displayFBWidth * this.mc.vrSettings.superSampleScaleFactor);
        FBHeight = (int) ceil(this.mc.displayFBHeight * this.mc.vrSettings.superSampleScaleFactor);
    }

    if (mc.vrSettings.useDistortion) {
        //mc.checkGLError("Before distortion");

        preDistortionFBO.bindTexture();

        if (this.mc.vrSettings.useFXAA) {
            //chain into the FXAA FBO
            fxaaFBO.bindRenderTarget();
        } else if (this.mc.vrSettings.useSupersample) {
            //chain into the superSample FBO
            postDistortionFBO.bindRenderTarget();
        } else {
            unbindFBORenderTarget();
        }

        GL11.glClearColor(1.0f, 1.0f, 1.0f, 0.5f);
        GL11.glClearDepth(1.0D);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black

        // Render onto the entire screen framebuffer
        GL11.glViewport(0, 0, FBWidth, FBHeight);

        // Set the distortion shader as in use
        ARBShaderObjects.glUseProgramObjectARB(_Distortion_shaderProgramId);

        // Set up the fragment shader uniforms
        ARBShaderObjects.glUniform1iARB(_DistortionShader_RenderTextureUniform, 0);

        if (this.mc.vrSettings.useDistortionTextureLookupOptimisation) {
            distortParams.bindTexture_Unit1();
            ARBShaderObjects.glUniform1iARB(_DistortionShader_DistortionMapUniform, 1);
        }

        ARBShaderObjects.glUniform1iARB(_DistortionShader_half_screenWidthUniform,
                distortParams.half_screenWidth);
        ARBShaderObjects.glUniform2fARB(_DistortionShader_LeftLensCenterUniform, distortParams.leftLensCenterX,
                distortParams.leftLensCenterY);
        ARBShaderObjects.glUniform2fARB(_DistortionShader_RightLensCenterUniform,
                distortParams.rightLensCenterX, distortParams.rightLensCenterY);
        ARBShaderObjects.glUniform2fARB(_DistortionShader_LeftScreenCenterUniform,
                distortParams.leftScreenCenterX, distortParams.leftScreenCenterY);
        ARBShaderObjects.glUniform2fARB(_DistortionShader_RightScreenCenterUniform,
                distortParams.rightScreenCenterX, distortParams.rightScreenCenterY);
        ARBShaderObjects.glUniform2fARB(_DistortionShader_ScaleUniform, distortParams.scaleX,
                distortParams.scaleY);
        ARBShaderObjects.glUniform2fARB(_DistortionShader_ScaleInUniform, distortParams.scaleInX,
                distortParams.scaleInY);
        ARBShaderObjects.glUniform4fARB(_DistortionShader_HmdWarpParamUniform, distortParams.DistortionK[0],
                distortParams.DistortionK[1], distortParams.DistortionK[2], distortParams.DistortionK[3]);
        ARBShaderObjects.glUniform4fARB(_DistortionShader_ChromAbParamUniform, distortParams.ChromaticAb[0],
                distortParams.ChromaticAb[1], distortParams.ChromaticAb[2], distortParams.ChromaticAb[3]);

        drawQuad();

        // Stop shader use
        ARBShaderObjects.glUseProgramObjectARB(0);

        OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
        //mc.checkGLError("After distortion");
    }

    if (this.mc.vrSettings.useFXAA) {
        fxaaFBO.bindTexture();

        if (this.mc.vrSettings.useSupersample) {
            //chain into the superSample FBO
            postDistortionFBO.bindRenderTarget();
        } else {
            unbindFBORenderTarget();
        }

        GL11.glClearColor(1.0f, 1.0f, 1.0f, 0.5f);
        GL11.glClearDepth(1.0D);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black

        // Render onto the entire screen framebuffer
        GL11.glViewport(0, 0, FBWidth, FBHeight);

        // Set the distortion shader as in use
        ARBShaderObjects.glUseProgramObjectARB(_FXAA_shaderProgramId);

        // Set up the fragment shader uniforms
        ARBShaderObjects.glUniform1iARB(_FXAA_RenderTextureUniform, 0);
        ARBShaderObjects.glUniform2fARB(_FXAA_RenderedTextureSizeUniform, (float) FBWidth, (float) FBHeight);

        drawQuad();

        // Stop shader use
        ARBShaderObjects.glUseProgramObjectARB(0);

        OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
        //ShaderHelper.checkGLError("After fxaa");
    }

    if (this.mc.vrSettings.useSupersample) {
        // Now switch to 1st pass target framebuffer
        postSuperSampleFBO.bindRenderTarget();

        // Bind the FBO
        postDistortionFBO.bindTexture();

        GL11.glClearColor(0.0f, 0.0f, 1.0f, 0.5f);
        GL11.glClearDepth(1.0D);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the framebuffer to black

        // Render onto the entire screen framebuffer
        GL11.glViewport(0, 0, this.mc.displayFBWidth, FBHeight);

        // Set the downsampling shader as in use
        ARBShaderObjects.glUseProgramObjectARB(_Lanczos_shaderProgramId);

        // Set up the fragment shader uniforms
        ARBShaderObjects.glUniform1fARB(_LanczosShader_texelWidthOffsetUniform,
                1.0f / (3.0f * (float) this.mc.displayFBWidth));
        ARBShaderObjects.glUniform1fARB(_LanczosShader_texelHeightOffsetUniform, 0.0f);
        ARBShaderObjects.glUniform1iARB(_LanczosShader_inputImageTextureUniform, 0);

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

        // Pass 1
        drawQuad();

        // mc.checkGLError("After Lanczos Pass1");

        // Pass 2
        // Now switch to 2nd pass screen framebuffer
        unbindFBORenderTarget();
        postSuperSampleFBO.bindTexture();

        GL11.glViewport(0, 0, this.mc.displayFBWidth, this.mc.displayFBHeight);
        GL11.glClearColor(0.0f, 0.0f, 1.0f, 0.5f);
        GL11.glClearDepth(1.0D);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        // Bind the texture
        GL13.glActiveTexture(GL13.GL_TEXTURE0);

        // Set up the fragment shader uniforms for pass 2
        ARBShaderObjects.glUniform1fARB(_LanczosShader_texelWidthOffsetUniform, 0.0f);
        ARBShaderObjects.glUniform1fARB(_LanczosShader_texelHeightOffsetUniform,
                1.0f / (3.0f * (float) this.mc.displayFBHeight));
        ARBShaderObjects.glUniform1iARB(_LanczosShader_inputImageTextureUniform, 0);

        drawQuad();

        // Stop shader use
        ARBShaderObjects.glUseProgramObjectARB(0);
        // mc.checkGLError("After Lanczos Pass2");
    }
}