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:net.smert.frameworkgl.opengl.OpenGL1.java

License:Apache License

public OpenGL1 setClearColor(float red, float green, float blue, float alpha) {
    GL11.glClearColor(red, green, blue, alpha);
    return this;
}

From source file:net._5tingr4y.openrpg.lwjgl.OpenGLHandler.java

License:Open Source License

public void setupOpenGL() {
    Log.info(this, "OpenGL setup started");

    glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));

    //initialize GLFW. Most GLFW functions will not work before doing this.
    if (glfwInit() != GLFW_TRUE)
        throw new IllegalStateException("Unable to initialize GLFW");

    //configure window
    glfwDefaultWindowHints(); //make sure we have the default window hints (should already be, just to be sure)
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); //window will stay hidden after creation
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); //window will not be resizable

    long monitor = fullscreen ? glfwGetPrimaryMonitor() : NULL;
    window = glfwCreateWindow(width, height, "OpenRPG", monitor, NULL);

    if (window == NULL)
        throw new RuntimeException("Failed to create the GLFW window");

    //get the resolution of the primary monitor
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());

    if (!fullscreen) {
        glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    }/* w  w w  .ja va  2  s . c  o  m*/

    //make the OpenGL context current
    glfwMakeContextCurrent(window);

    //enable v-sync
    glfwSwapInterval(1);

    //make the window visible
    glfwShowWindow(window);

    // This line is critical for LWJGL's interoperation with GLFW's
    // OpenGL context, or any context that is managed externally.
    // LWJGL detects the context that is current in the current thread,
    // creates the GLCapabilities instance and makes the OpenGL
    // bindings available for use.
    GL.createCapabilities();

    //set the clear color
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    initialized = true;
    Log.info(this, "OpenGL setup finished");
}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void startDrawing3D(int x, int y, int width, int height, float fov, float zNear, float zFar) {
    if (worldObj.isRemote) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glViewport(0, 0, width, height);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();//  w  w  w  .  ja  v a2 s. c  o  m
        GL11.glLoadIdentity();
        GLU.gluPerspective(fov, (float) width / (float) height, zNear, zFar);

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

        GL11.glClearColor(cr, cg, cb, ca);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void startDrawing2D(int x, int y, int width, int height) {
    if (worldObj.isRemote) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glViewport(x, y, width, height);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();/*from   ww w .ja  v  a2 s. c om*/
        GL11.glLoadIdentity();
        GL11.glOrtho(0, width, height, 0, 1, -1);

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

        GL11.glClearColor(cr, cg, cb, ca);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

From source file:org.bonsaimind.badgersvoyage.tools.planetstudio.Studio.java

License:Open Source License

public void run() {
    GL11.glClearColor(0.2f, 0.5f, 1f, 0f);
    GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());

    //GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);

    while (!Display.isCloseRequested() && !closeRequested) {
        processKeyboard();/* w  w w  .  j  a  v  a 2  s. c o  m*/
        ErrorChecker.exitOnOpenGlError("After processKeyboard.");

        camera.startTranslate();
        sphere.translate();
        camera.endTranslate();
        ErrorChecker.exitOnOpenGlError("End of Translate.");

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

        GL20.glUseProgram(programId);
        sphere.render();

        GL20.glDisableVertexAttribArray(0);
        GL30.glDeleteVertexArrays(0);

        GL20.glUseProgram(0);

        Display.sync(60);
        Display.update();

        ErrorChecker.exitOnOpenGlError("End of main loop.");

    }

    Display.destroy();

}

From source file:org.cogaen.lwjgl.scene.SceneService.java

License:Open Source License

public void setBackgroundColor(ReadableColor color) {
    GL11.glClearColor((float) color.getRed(), (float) color.getGreen(), (float) color.getBlue(),
            (float) color.getAlpha());
}

From source file:org.craftmania.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);// www .ja  v  a 2s . 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 (int i = 0; i < _visibleChunks.size(); ++i) {
        _visibleChunks.get(i).render(MeshType.OPAQUE);
    }
    PerformanceMonitor.getInstance().stop(Operation.RENDER_OPAQUE);
    PerformanceMonitor.getInstance().start(Operation.RENDER_TRANSLUCENT);
    for (int i = 0; i < _visibleChunks.size(); ++i) {
        _visibleChunks.get(i).render(MeshType.TRANSLUCENT);
    }
    PerformanceMonitor.getInstance().stop(Operation.RENDER_TRANSLUCENT);
    PerformanceMonitor.getInstance().start(Operation.RENDER_MANUAL);
    for (int i = 0; i < _visibleChunks.size(); ++i) {
        _visibleChunks.get(i).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();
}

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;//from   w  w w. j  ava 2  s.co m
    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   ww  w. j  av a2 s  .  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() {
        @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   www. j  av a2  s  . com*/
    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();
}