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:org.craftmania.world.characters.Player.java

License:Apache License

@Override
public void render() {

    GL11.glEnable(GL11.GL_DEPTH_TEST);//from w ww . j a  v a 2  s. c  om
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);

    if (_aimedBlockPosition.y() != -1) {
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glDisable(GL11.GL_TEXTURE_2D);

        _aimedBlockAABB.render(0.0f, 0.0f, 0.0f, 0.1f);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    if (_selectedItem != null) {
        GL11.glPushMatrix();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_CULL_FACE);

        _body.transformToRightHand();

        /* Prepare the light buffer */
        Chunk c = Game.getInstance().getWorld().getChunkManager().getChunkContaining(
                MathHelper.floor(_position.x()), MathHelper.floor(_position.y()) + 1,
                MathHelper.floor(_position.z()), false, false, false);
        if (c != null) {
            c.getLightBuffer().setReferencePoint(MathHelper.floor(_position.x()),
                    MathHelper.floor(_position.y()) + 1, MathHelper.floor(_position.z()));

            /* Render the object, with the lightbuffer */
            _selectedItem.renderHoldableObject(c.getLightBuffer());
        }

        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glPopMatrix();
    }
    GL11.glDisable(GL11.GL_DEPTH_TEST);
}

From source file:org.eclipse.swt.opengl.examples.LWJGLExample.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;/*  w ww  .j  a  v a  2s . com*/
    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.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);

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

    display.asyncExec(new Runnable() {
        int rot = 0;

        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                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);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

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

From source file:org.eclipse.swt.snippets.Snippet195.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  ww.  j a  va2s  . c  om*/
    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() {
        @Override
        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.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);

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

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

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                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);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    };
    canvas.addListener(SWT.Paint, new Listener() {
        @Override
        public void handleEvent(Event event) {
            run.run();
        }
    });
    display.asyncExec(run);

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

From source file:org.eclipse.swt.snippets.Snippet341.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;//from  w ww  . ja  v  a2 s. c  om
    final GLCanvas canvas = new GLCanvas(shell, SWT.NONE, data);
    canvas.setLayoutData(new GridData(640, 480));

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

    canvas.addListener(SWT.Resize, new Listener() {
        @Override
        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.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);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            capture(canvas);
        }
    });
    shell.pack();
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                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);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

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

From source file:org.evilco.emulator.core.graphic.matrix.MonochromeMatrixScreen.java

License:Apache License

/**
 * {@inheritDoc}//  w w w .  j  a v  a 2  s  .c o m
 */
@Override
public synchronized void draw() {
    // clear screen
    GL11.glClearColor(0, 0, 0, 1);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glColor3f(1f, 1f, 1f); // TODO: Make color adjustable

    // draw pixels
    for (short y = 0; y < this.height; y++) {
        for (short x = 0; x < this.width; x++) {
            // skip disabled pixels
            if (!this.getPixel(x, y))
                continue;

            // draw
            GL11.glRecti(x, y, (x + 1), (y + 1));
        }
    }
}

From source file:org.fenggui.example.ExampleBasisLWJGL.java

License:Open Source License

/**
 * //from www.j  a v  a  2 s .  c  o  m
 */
private void glRender() {
    GL11.glLoadIdentity();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GLU.gluLookAt(10, 8, 8, 0, 0, 0, 0, 0, 1);

    // GL11.glRotatef(rotAngle, 1f, 1f, 1);
    //  GL11.glColor3f(0.42f, 0.134f, 0.44f);

    // rotAngle += 0.5;

    // draw GUI stuff
    desk.display();

    // hmm, i think we need to query the mouse pointer and
    // keyboard here and call the according
    // desk.mouseMoved, desk.keyPressed, etc.
    // methods...

}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_SetupFrame//from w  w  w . j av a 2 s  .c om
 */
void R_SetupFrame() {
    r_framecount++;

    //   build the transformation matrix for the given view angles
    Math3D.VectorCopy(r_newrefdef.vieworg, r_origin);

    Math3D.AngleVectors(r_newrefdef.viewangles, vpn, vright, vup);

    //   current viewcluster
    mleaf_t leaf;
    if ((r_newrefdef.rdflags & Defines.RDF_NOWORLDMODEL) == 0) {
        r_oldviewcluster = r_viewcluster;
        r_oldviewcluster2 = r_viewcluster2;
        leaf = Mod_PointInLeaf(r_origin, r_worldmodel);
        r_viewcluster = r_viewcluster2 = leaf.cluster;

        // check above and below so crossing solid water doesn't draw wrong
        if (leaf.contents == 0) { // look down a bit
            Math3D.VectorCopy(r_origin, temp);
            temp[2] -= 16;
            leaf = Mod_PointInLeaf(temp, r_worldmodel);
            if ((leaf.contents & Defines.CONTENTS_SOLID) == 0 && (leaf.cluster != r_viewcluster2)) {
                r_viewcluster2 = leaf.cluster;
            }
        } else { // look up a bit
            Math3D.VectorCopy(r_origin, temp);
            temp[2] += 16;
            leaf = Mod_PointInLeaf(temp, r_worldmodel);
            if ((leaf.contents & Defines.CONTENTS_SOLID) == 0 && (leaf.cluster != r_viewcluster2)) {
                r_viewcluster2 = leaf.cluster;
            }
        }
    }
    System.arraycopy(r_newrefdef.blend, 0, v_blend, 0, 4);

    c_brush_polys = 0;
    c_alias_polys = 0;

    // clear out the portion of the screen that the NOWORLDMODEL defines
    if ((r_newrefdef.rdflags & Defines.RDF_NOWORLDMODEL) != 0) {
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        GL11.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
        GL11.glScissor(r_newrefdef.x, vid.height - r_newrefdef.height - r_newrefdef.y, r_newrefdef.width,
                r_newrefdef.height);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glClearColor(1.0f, 0.0f, 0.5f, 0.5f);
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    }
}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_Clear//from   w  w  w  .ja  v  a  2  s.  c  o m
 */
void R_Clear() {
    if (gl_ztrick.value != 0.0f) {

        if (gl_clear.value != 0.0f) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        }

        trickframe++;
        if ((trickframe & 1) != 0) {
            gldepthmin = 0;
            gldepthmax = 0.49999f;
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        } else {
            gldepthmin = 1;
            gldepthmax = 0.5f;
            GL11.glDepthFunc(GL11.GL_GEQUAL);
        }
    } else {
        if (gl_clear.value != 0.0f) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        } else {
            GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        }

        gldepthmin = 0;
        gldepthmax = 1;
        GL11.glDepthFunc(GL11.GL_LEQUAL);
    }
    GL11.glDepthRange(gldepthmin, gldepthmax);
}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_SetPalette//from   w w w  . ja  v a 2 s  .c o m
 */
protected void R_SetPalette(byte[] palette) {
    // 256 RGB values (768 bytes)
    // or null
    int i;
    int color = 0;

    if (palette != null) {
        int j = 0;
        for (i = 0; i < 256; i++) {
            color = (palette[j++] & 0xFF);
            color |= (palette[j++] & 0xFF) << 8;
            color |= (palette[j++] & 0xFF) << 16;
            color |= 0xFF000000;
            r_rawpalette[i] = color;
        }
    } else {
        for (i = 0; i < 256; i++) {
            r_rawpalette[i] = d_8to24table[i] | 0xff000000;
        }
    }
    GL_SetTexturePalette(r_rawpalette);

    GL11.glClearColor(0, 0, 0, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    GL11.glClearColor(1f, 0f, 0.5f, 0.5f);
}

From source file:org.geekygoblin.nedetlesmaki.game.systems.DrawSystem.java

License:Open Source License

@Override
protected void processEntities(ImmutableBag<Entity> entities) {
    GL11.glClearColor(99f / 255f, 201f / 255f, 183f / 255f, 1f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    Sort.instance().sort(sprites, zComparator);

    GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_TRANSFORM_BIT | GL11.GL_HINT_BIT | GL11.GL_COLOR_BUFFER_BIT
            | GL11.GL_SCISSOR_BIT | GL11.GL_LINE_BIT | GL11.GL_TEXTURE_BIT);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();//from w  ww. ja  va  2 s  .  c  o m
    GL11.glLoadIdentity();

    updateViewPort();
    GL11.glViewport(viewPort.x, viewPort.y, viewPort.width, viewPort.height);
    GLU.gluOrtho2D(-VirtualResolution.WIDTH / 2.0f, VirtualResolution.WIDTH / 2.0f,
            VirtualResolution.HEIGHT / 2.0f, -VirtualResolution.HEIGHT / 2.0f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);

    NedGame game = (NedGame) world;
    Entity ned = game.getNed();
    if (null != ned) {
        Sprite nedSprite = spriteMapper.get(ned);
        Vector nedPos = spriteProjector.project(nedSprite.getPosition());
        GL11.glTranslatef(-nedPos.x, -nedPos.y, 0.0f);
    }

    for (Entity e : backgrounds) {
        LevelBackground level = levelBackgroundMapper.getSafe(e);
        if (null != level) {
            drawLevel(level);
        }
    }

    GL11.glPushMatrix();
    GL11.glScalef(spriteGlobalScale, spriteGlobalScale, 1.0f);
    spriteBatcher.begin();
    for (Entity e : sprites) {
        spriteBatcher.draw(spriteMapper.getSafe(e));
    }
    spriteBatcher.end();
    for (Entity e : sprites) {
        drawSpriteLabel(spriteMapper.getSafe(e));
    }
    GL11.glPopMatrix();

    for (Entity e : uis) {
        MainMenu mainMenu = mainMenuMapper.getSafe(e);
        if (null != mainMenu) {
            nuitRenderer.render(mainMenu.getRoot());
        }
        DialogComponent dialog = dialogMapper.getSafe(e);
        if (null != dialog) {
            nuitRenderer.render(dialog.getRoot());
        }
        InGameUI inGameUI = inGameUIMapper.getSafe(e);
        if (null != inGameUI) {
            nuitRenderer.render(inGameUI.getRoot());
        }
    }
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();
    GL11.glPopAttrib();

}