Example usage for org.lwjgl.opengl GL11 glClearColor

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

Introduction

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

Prototype

public static void glClearColor(@NativeType("GLfloat") float red, @NativeType("GLfloat") float green,
        @NativeType("GLfloat") float blue, @NativeType("GLfloat") float alpha) 

Source Link

Document

Sets the clear value for fixed-point and floating-point color buffers in RGBA mode.

Usage

From source file:org.lwjgl.info.LWJGLTestView.java

License:Open Source License

/** 
 * {@inheritDoc}/*from  w w  w.j  a v  a2s  .c  o  m*/
 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createPartControl(Composite parent) {

    String strVersion = getFeatureVersion("org.lwjgl");
    this.setPartName("org.lwjgl " + strVersion);

    IStatusLineManager statusLine = this.getViewSite().getActionBars().getStatusLineManager();

    fpsstatuslineitem = new FpsStatusLineItem();
    statusLine.add(fpsstatuslineitem);

    GLData data = new GLData();
    data.doubleBuffer = true;
    canvas = new GLCanvas(parent, 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);

    Display.getCurrent().asyncExec(initRunnable());

}

From source file:org.lwjgl.info.LWJGLTestView.java

License:Open Source License

Runnable initRunnable() {
    return new Runnable() {
        int rot = 0;

        public void run() {
            if (!canvas.isDisposed() && canvas.isVisible()) {

                fpsstatuslineitem.renderPassStarted();

                canvas.setCurrent();//from w w w  .ja  v a 2s .  c  o  m
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.2f, .7f, .2f, 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();

                fpsstatuslineitem.renderPassFinished();
                Display.getCurrent().asyncExec(this);

            }
        }
    };
}

From source file:org.minetweak.world.World.java

License:Apache License

public void render() {
    /* Prepare Matrixes */
    Game.getInstance().initSceneRendering();
    Configuration configuration = Game.getInstance().getConfiguration();

    /* Look through the camera with high viewing distance to render the sky */
    _player.getFirstPersonCamera().lookThrough(512.0f);

    /* Set the fog color based on time */
    _fogColor.set(Game.getInstance().getConfiguration().getFogColor());
    _fogColor.scale(_sunlight - 0.05f);//from w  w w  . j a  v a 2 s  . c o  m
    GL11.glFog(GL11.GL_FOG_COLOR, GLUtils.wrapDirect(_fogColor.x(), _fogColor.y(), _fogColor.z(), 1.0f));
    GL11.glClearColor(_fogColor.x(), _fogColor.y(), _fogColor.z(), 1.0f);

    /* Render the sky */
    GL11.glFogf(GL11.GL_FOG_START, 200);
    GL11.glFogf(GL11.GL_FOG_END, 400);
    _sky.renderSky();

    /* Restore the fog distance */
    GL11.glFogf(GL11.GL_FOG_START, configuration.getViewingDistance() * 0.55f);
    GL11.glFogf(GL11.GL_FOG_END, configuration.getViewingDistance());

    /* Select the visible blocks */
    selectVisibleChunks(_player.getFirstPersonCamera().getViewFrustum());

    /* Bind the terrain texture */
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    TextureStorage.getTexture("terrain").bind();

    PerformanceMonitor.getInstance().start(Operation.RENDER_OPAQUE);
    for (Chunk _visibleChunk : _visibleChunks) {
        _visibleChunk.render(MeshType.OPAQUE);
    }
    PerformanceMonitor.getInstance().stop(Operation.RENDER_OPAQUE);
    PerformanceMonitor.getInstance().start(Operation.RENDER_TRANSLUCENT);
    for (Chunk _visibleChunk : _visibleChunks) {
        _visibleChunk.render(MeshType.TRANSLUCENT);
    }
    PerformanceMonitor.getInstance().stop(Operation.RENDER_TRANSLUCENT);
    PerformanceMonitor.getInstance().start(Operation.RENDER_MANUAL);
    for (Chunk _visibleChunk : _visibleChunks) {
        _visibleChunk.renderManualBlocks();
    }
    PerformanceMonitor.getInstance().stop(Operation.RENDER_MANUAL);

    /* Render the clouds */
    GL11.glFogf(GL11.GL_FOG_START, 200);
    GL11.glFogf(GL11.GL_FOG_END, 400);
    _sky.renderClouds();

    _player.render();

    renderOverlay();
    if (currentGui != null) {
        currentGui.render();
    }
}

From source file:org.mkdev.ai.langton3d.core.App.java

License:GNU General Public License

private void drawBackground() {
    GL11.glDisable(GL11.GL_DEPTH_TEST);//from www  . j  a va  2 s . co  m
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    GL11.glClearColor(Settings.BKG_COLOR_RED, Settings.BKG_COLOR_GREEN, Settings.BKG_COLOR_BLUE,
            Settings.BKG_COLOR_ALPHA);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glDisable(GL_LIGHTING);

    GL11.glBegin(GL11.GL_QUADS);

    GL11.glColor4f(Settings.BKG_COLOR_RED, Settings.BKG_COLOR_GREEN, Settings.BKG_COLOR_BLUE,
            Settings.BKG_COLOR_ALPHA);
    GL11.glVertex2f(-1.0f, -1.0f);
    GL11.glVertex2f(1.0f, -1.0f);

    GL11.glColor4f(Settings.BKG_COLOR_RED / 2, Settings.BKG_COLOR_GREEN / 2, Settings.BKG_COLOR_BLUE / 2,
            Settings.BKG_COLOR_ALPHA);
    GL11.glVertex2f(1.0f, 1.0f);
    GL11.glVertex2f(-1.0f, 1.0f);

    GL11.glEnd();

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

@Override
//   void dsDrawFrame (int width, int height, dsFunctions *fn, int pause)
void dsDrawFrame(int width, int height, dsFunctions fn, boolean pause) {
    if (current_state < 1)
        dsDebug("internal error");
    current_state = 2;//  w ww .  j ava2  s  .  co  m

    // setup stuff
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_LIGHT0);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glCullFace(GL11.GL_BACK);
    GL11.glFrontFace(GL11.GL_CCW);

    // setup viewport
    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    final float vnear = 0.1f;
    final float vfar = 100.0f;
    final float k = 0.8f; // view scale, 1 = +/- 45 degrees
    if (width >= height) {
        float k2 = (float) height / (float) width;
        GL11.glFrustum(-vnear * k, vnear * k, -vnear * k * k2, vnear * k * k2, vnear, vfar);
    } else {
        float k2 = (float) width / (float) height;
        GL11.glFrustum(-vnear * k * k2, vnear * k * k2, -vnear * k, vnear * k, vnear, vfar);
    }

    // setup lights. it makes a difference whether this is done in the
    // GL_PROJECTION matrix mode (lights are scene relative) or the
    // GL_MODELVIEW matrix mode (lights are camera relative, bad!).
    //      static GLfloat light_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
    //      static GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    //      static GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, light_ambient);
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, light_diffuse);
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, light_specular);
    GL11.glColor3f(1.0f, 1.0f, 1.0f);

    // clear the window
    GL11.glClearColor(0.5f, 0.5f, 0.5f, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    // snapshot camera position (in MS Windows it is changed by the GUI thread)
    float[] view2_xyz = view_xyz.clone();
    float[] view2_rxyz = view_rxyz.clone();
    //      memcpy (view2_xyz,view_xyz);//,sizeof(float)*3);
    //      memcpy (view2_hpr,view_hpr);//,sizeof(float)*3);

    // go to GL_MODELVIEW matrix mode and set the camera
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    setCamera(view2_xyz[0], view2_xyz[1], view2_xyz[2], view2_rxyz[0], view2_rxyz[1], view2_rxyz[2]);

    // set the light position (for some reason we have to do this in model view.
    //      static GLfloat light_position[] = { LIGHTX, LIGHTY, 1.0, 0.0 };
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, light_position);

    // draw the background (ground, sky etc)
    drawSky(view2_xyz);
    drawGround();

    // draw the little markers on the ground
    drawPyramidGrid();

    // leave openGL in a known state - flat shaded white, no textures
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glColor3f(1, 1, 1);
    setColor(1, 1, 1, 1);

    // draw the rest of the objects. set drawing state first.
    color[0] = 1;
    color[1] = 1;
    color[2] = 1;
    color[3] = 1;
    tnum = DS_TEXTURE_NUMBER.DS_NONE;
    //if (fn.step) 
    fn.step(pause);
}

From source file:org.oscim.gdx.LwjglGL20.java

License:Apache License

public void clearColor(float red, float green, float blue, float alpha) {
    GL11.glClearColor(red, green, blue, alpha);
}

From source file:org.spout.engine.SpoutClient.java

License:Open Source License

public void initRenderer() {
    createWindow();//w w w. java  2 s  .co m

    //Mouse.setGrabbed(true);

    getLogger().info("SpoutClient Information");
    getLogger().info("Operating System: " + System.getProperty("os.name"));
    getLogger().info("Renderer Mode: " + this.getRenderMode().toString());
    getLogger().info("OpenGL Information");
    getLogger().info("Vendor: " + GL11.glGetString(GL11.GL_VENDOR));
    getLogger().info("OpenGL Version: " + GL11.glGetString(GL11.GL_VERSION));
    getLogger().info("GLSL Version: " + GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
    getLogger().info("Max Textures: " + GL11.glGetString(GL20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS));
    String extensions = "Extensions Supported: ";
    if (getArguments().renderMode == RenderMode.GL30) {
        for (int i = 0; i < GL11.glGetInteger(GL30.GL_NUM_EXTENSIONS); i++) {
            extensions += GL30.glGetStringi(GL11.GL_EXTENSIONS, i) + " ";
        }
    } else {
        extensions += GL11.glGetString(GL11.GL_EXTENSIONS);
    }
    getLogger().info(extensions);
    soundManager.init();
    Spout.getFilesystem().postStartup();

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glClearColor((135.f / 255.0f), 206.f / 255.f, 250.f / 255.f, 0);

    worldRenderer = new WorldRenderer(this);
    worldRenderer.setup();

    renderer = new PrimitiveBatch();
    mat = (RenderMaterial) this.getFilesystem()
            .getResource("material://Spout/resources/resources/materials/BasicMaterial.smt");
    renderer.begin();
    renderer.addCube(new Vector3(-0.5, -0.5, -0.5), Vector3.ONE, Color.RED, sides);
    renderer.end();

    gui = new SpriteBatch();
}

From source file:org.spout.engine.SpoutRenderer.java

License:Open Source License

public void initRenderer(Canvas parent) {
    createWindow(parent);//from  w  ww.  ja  v a2 s.  co  m

    if (Spout.debugMode()) {
        client.getLogger().info("SpoutClient Information");
        client.getLogger().info("Operating System: " + System.getProperty("os.name"));
        client.getLogger().info("Renderer Mode: " + client.getRenderMode().toString());
        client.getLogger().info("GL21: " + GLContext.getCapabilities().OpenGL21 + " GL32: "
                + GLContext.getCapabilities().OpenGL32);
        client.getLogger().info("Resolution: " + Display.getWidth() + "x" + Display.getHeight());
        client.getLogger().info("OpenGL Information");
        client.getLogger().info("Vendor: " + GL11.glGetString(GL11.GL_VENDOR));
        client.getLogger().info("OpenGL Version: " + GL11.glGetString(GL11.GL_VERSION));
        client.getLogger().info("GLSL Version: " + GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
        client.getLogger().info("Max Textures: " + GL11.glGetInteger(GL20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS));
        String extensions = "Extensions Supported: ";
        if (client.getRenderMode() == RenderMode.GL30 || client.getRenderMode() == RenderMode.GL40) {
            for (int i = 0; i < GL11.glGetInteger(GL30.GL_NUM_EXTENSIONS); i++) {
                extensions += GL30.glGetStringi(GL11.GL_EXTENSIONS, i) + " ";
            }
        } else {
            extensions += GL11.glGetString(GL11.GL_EXTENSIONS);
        }
        client.getLogger().info(extensions);
    }

    SpoutRenderer.checkGLError();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glFrontFace(GL11.GL_CW);
    GL11.glCullFace(GL11.GL_BACK);
    SpoutRenderer.checkGLError();

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glClearColor((135.f / 255.0f), 206.f / 255.f, 250.f / 255.f, 1);
    SpoutRenderer.checkGLError();

    //Init pool of BatchVertexRenderer
    BatchVertexRenderer.initPool(GL11.GL_TRIANGLES, 500);

    if (useReflexion) {
        reflected = new ClientRenderTexture(true, false, true);
        reflected.writeGPU();
        // Test
        reflectedDebugBatch = new SpriteBatch();
        Shader s1 = client.getFileSystem().getResource("shader://Spout/shaders/diffuse.ssf");
        HashMap<String, Object> map1 = new HashMap<>();
        map1.put("Diffuse", reflected);
        reflectedDebugMat = new ClientRenderMaterial(s1, map1);
        RenderPart screenPart1 = new RenderPart();
        screenPart1.setSprite(new Rectangle(-1, -1, 0.5f, 0.5f));
        screenPart1.setSource(new Rectangle(0, 1, 1, -1));
        RenderPartPack pack1 = new RenderPartPack(reflectedDebugMat);
        pack1.add(screenPart1);
        reflectedDebugBatch.flush(pack1);
        // Test end
    }

    screenBatcher = new SpriteBatch();
    t = new ClientRenderTexture(true, false, true);
    t.writeGPU();
    Shader s = client.getFileSystem().getResource("shader://Spout/shaders/diffuse.ssf");
    HashMap<String, Object> map = new HashMap<>();
    map.put("Diffuse", t);
    mat = new ClientRenderMaterial(s, map);
    RenderPart screenPart = new RenderPart();
    screenPart.setSprite(new Rectangle(-1, -1, 2, 2));
    screenPart.setSource(new Rectangle(0, 1, 1, -1));
    RenderPartPack pack = new RenderPartPack(mat);
    pack.add(screenPart);
    screenBatcher.flush(pack);
}

From source file:org.spoutcraft.api.gui.renderer.GuiRendererFBO.java

License:MIT License

@Override
public void drawScreen(Gui gui, RootContainer root, int mouseX, int mouseY, float partialTick) {
    GL11.glPushAttrib(GL11.GL_STENCIL_BUFFER_BIT);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
    GL11.glClearColor(0, 0, 0, 0F);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    GL11.glEnable(GL11.GL_BLEND);// w  ww . ja v a 2s  .  c  o  m
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_STENCIL_TEST);
    root.render();

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

    TextureUtil.bind(guiTex);

    GL11.glDisable(GL11.GL_BLEND);
    Tessellator tes = Tessellator.instance;
    tes.startDrawingQuads();
    tes.addVertexWithUV(0, 0, 0, 0, 1);
    tes.addVertexWithUV(0, gui.height, 0, 0, 0);
    tes.addVertexWithUV(gui.width, gui.height, 0, 1, 0);
    tes.addVertexWithUV(gui.width, 0, 0, 1, 1);
    tes.draw();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glPopAttrib();
}

From source file:org.voxels.platform.LWJGLOpenGLAdapter.java

License:Open Source License

@Override
public void glClearColor(final float r, final float g, final float b, final float a) {
    GL11.glClearColor(r, g, b, a);
}