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:colonialdisplay.AntDisplayGL.java

@Override
protected void initGL() {
    Rectangle bounds = canvas.getClientArea();
    GL11.glViewport(bounds.x, bounds.y, bounds.width, bounds.height);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();/*  w w w . ja v  a 2s  .c o m*/

    GL11.glOrtho(0, bounds.width, bounds.height, 0, 1, -1);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    initTextures();
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    createModel();
}

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;/*  w  w w . ja  v a  2s .  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.ardor3d.renderer.lwjgl.LwjglPbufferTextureRenderer.java

License:Open Source License

private void activate() {
    if (_active == 0) {
        try {// w w w . ja  va 2s. c om
            _oldContext = ContextManager.getCurrentContext();
            _pbuffer.makeCurrent();

            ContextManager.switchContext(_pbuffer);

            ContextManager.getCurrentContext().clearEnforcedStates();
            ContextManager.getCurrentContext().enforceStates(_enforcedStates);

            if (_bgColorDirty) {
                GL11.glClearColor(_backgroundColor.getRed(), _backgroundColor.getGreen(),
                        _backgroundColor.getBlue(), _backgroundColor.getAlpha());
                _bgColorDirty = false;
            }
        } catch (final LWJGLException e) {
            logger.logp(Level.SEVERE, this.getClass().toString(), "activate()", "Exception", e);
            throw new Ardor3dException();
        }
    }
    _active++;
}

From source file:com.ardor3d.renderer.lwjgl.LwjglRenderer.java

License:Open Source License

public void setBackgroundColor(final ReadOnlyColorRGBA color) {
    _backgroundColor.set(color);//w  w  w.j  av a 2  s  . c  o  m
    GL11.glClearColor(_backgroundColor.getRed(), _backgroundColor.getGreen(), _backgroundColor.getBlue(),
            _backgroundColor.getAlpha());
}

From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java

License:Open Source License

@Override
protected void activate() {
    // Lazy init/* ww  w . ja  va2 s .com*/
    if (_fboID == 0) {
        final IntBuffer buffer = BufferUtils.createIntBuffer(1);

        // Create our texture binding FBO
        EXTFramebufferObject.glGenFramebuffersEXT(buffer); // generate id
        _fboID = buffer.get(0);

        // Create a depth renderbuffer to use for RTT use
        EXTFramebufferObject.glGenRenderbuffersEXT(buffer); // generate id
        _depthRBID = buffer.get(0);
        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRBID);
        int format = GL11.GL_DEPTH_COMPONENT;
        if (_supportsDepthTexture && _depthBits > 0) {
            switch (_depthBits) {
            case 16:
                format = ARBDepthTexture.GL_DEPTH_COMPONENT16_ARB;
                break;
            case 24:
                format = ARBDepthTexture.GL_DEPTH_COMPONENT24_ARB;
                break;
            case 32:
                format = ARBDepthTexture.GL_DEPTH_COMPONENT32_ARB;
                break;
            default:
                // stick with the "undefined" GL_DEPTH_COMPONENT
            }
        }
        EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, format, _width,
                _height);

        // unbind...
        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);

        // If we support it, rustle up a multisample framebuffer + renderbuffers
        if (_samples != 0 && _supportsMultisample) {
            // create ms framebuffer object
            EXTFramebufferObject.glGenFramebuffersEXT(buffer);
            _msfboID = buffer.get(0);

            // create ms renderbuffers
            EXTFramebufferObject.glGenRenderbuffersEXT(buffer); // generate id
            _mscolorRBID = buffer.get(0);
            EXTFramebufferObject.glGenRenderbuffersEXT(buffer); // generate id
            _msdepthRBID = buffer.get(0);

            // set up renderbuffer properties
            EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _mscolorRBID);
            EXTFramebufferMultisample.glRenderbufferStorageMultisampleEXT(
                    EXTFramebufferObject.GL_RENDERBUFFER_EXT, _samples, GL11.GL_RGBA, _width, _height);

            EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _msdepthRBID);
            EXTFramebufferMultisample.glRenderbufferStorageMultisampleEXT(
                    EXTFramebufferObject.GL_RENDERBUFFER_EXT, _samples, format, _width, _height);

            EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);

            EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _msfboID);
            EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                    _mscolorRBID);
            EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                    _msdepthRBID);

            // check for errors
            checkFBOComplete(_msfboID);

            // release
            EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
        }

    }

    if (_active == 0) {

        final RenderContext context = ContextManager.getCurrentContext();
        final RendererRecord record = context.getRendererRecord();

        // needed as FBOs do not share this flag it seems
        record.setClippingTestValid(false);

        // push a delimiter onto the clip stack
        _neededClip = _parentRenderer.isClipTestEnabled();
        if (_neededClip) {
            _parentRenderer.pushEmptyClip();
        }

        GL11.glClearColor(_backgroundColor.getRed(), _backgroundColor.getGreen(), _backgroundColor.getBlue(),
                _backgroundColor.getAlpha());
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _fboID);
        ContextManager.getCurrentContext().pushEnforcedStates();
        ContextManager.getCurrentContext().clearEnforcedStates();
        ContextManager.getCurrentContext().enforceStates(_enforcedStates);
    }
    _active++;
}

From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java

License:Open Source License

@Override
protected void deactivate() {
    if (_active == 1) {
        final ReadOnlyColorRGBA bgColor = _parentRenderer.getBackgroundColor();
        GL11.glClearColor(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), bgColor.getAlpha());
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);

        ContextManager.getCurrentContext().popEnforcedStates();

        if (_neededClip) {
            _parentRenderer.popClip();//  ww w .  j a va 2s .  c  o  m
        }
    }
    _active--;
}

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

License:Apache License

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

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

License:Apache License

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

From source file:com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.java

License:Apache License

static long createGlfwWindow(Lwjgl3ApplicationConfiguration config, long sharedContextWindow) {
    GLFW.glfwDefaultWindowHints();//from   ww  w  .j  a  va2  s.c o  m
    GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
    GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, config.windowResizable ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE);

    if (sharedContextWindow == 0) {
        GLFW.glfwWindowHint(GLFW.GLFW_RED_BITS, config.r);
        GLFW.glfwWindowHint(GLFW.GLFW_GREEN_BITS, config.g);
        GLFW.glfwWindowHint(GLFW.GLFW_BLUE_BITS, config.b);
        GLFW.glfwWindowHint(GLFW.GLFW_ALPHA_BITS, config.a);
        GLFW.glfwWindowHint(GLFW.GLFW_STENCIL_BITS, config.stencil);
        GLFW.glfwWindowHint(GLFW.GLFW_DEPTH_BITS, config.depth);
        GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, config.samples);
    }

    if (config.useGL30) {
        //GLFW.glfwWindowHint(GLFW.GLFW_CLIENT_API, GLFW.GLFW_OPENGL_API);
        GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, config.gles30ContextMajorVersion);
        GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, config.gles30ContextMinorVersion);
        GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
        GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
    }

    long windowHandle = 0;

    if (config.fullscreenMode != null) {
        // glfwWindowHint(GLFW.GLFW_REFRESH_RATE, config.fullscreenMode.refreshRate);
        windowHandle = GLFW.glfwCreateWindow(config.fullscreenMode.width, config.fullscreenMode.height,
                config.title, config.fullscreenMode.getMonitor(), sharedContextWindow);
    } else {
        GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, config.windowDecorated ? GLFW.GLFW_TRUE : GLFW.GLFW_FALSE);
        windowHandle = GLFW.glfwCreateWindow(config.windowWidth, config.windowHeight, config.title, 0,
                sharedContextWindow);
    }
    if (windowHandle == 0) {
        throw new GdxRuntimeException("Couldn't create window");
    }
    if (config.fullscreenMode == null) {
        if (config.windowX == -1 && config.windowY == -1) {
            GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
            GLFW.glfwSetWindowPos(windowHandle, vidMode.width() / 2 - config.windowWidth / 2,
                    vidMode.height() / 2 - config.windowHeight / 2);
        } else {
            GLFW.glfwSetWindowPos(windowHandle, config.windowX, config.windowY);
        }
    }
    GLFW.glfwMakeContextCurrent(windowHandle);
    GLFW.glfwSwapInterval(config.vSyncEnabled ? 1 : 0);
    GL.createCapabilities();

    extractVersion();
    if (!isOpenGLOrHigher(2, 0))
        throw new GdxRuntimeException(
                "OpenGL 2.0 or higher with the FBO extension is required. OpenGL version: "
                        + GL11.glGetString(GL11.GL_VERSION) + "\n" + glInfo());

    if (!supportsFBO()) {
        throw new GdxRuntimeException(
                "OpenGL 2.0 or higher with the FBO extension is required. OpenGL version: "
                        + GL11.glGetString(GL11.GL_VERSION) + ", FBO extension: false\n" + glInfo());
    }

    for (int i = 0; i < 2; i++) {
        GL11.glClearColor(config.initialBackgroundColor.r, config.initialBackgroundColor.g,
                config.initialBackgroundColor.b, config.initialBackgroundColor.a);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        GLFW.glfwSwapBuffers(windowHandle);
    }
    return windowHandle;
}

From source file:com.dbi.games.fortress.ui.MainAppWindow.java

License:Open Source License

/**
 * Creates new form MainAppWin/*from w  w  w  .j a  va 2s . c  o  m*/
 */
public MainAppWindow() {
    initComponents();

    glCanvas.addComponentListener(new ComponentListener() {
        public void componentShown(ComponentEvent e) {
            setNeedValidation();
        }

        public void componentResized(ComponentEvent e) {
            setNeedValidation();
        }

        public void componentMoved(ComponentEvent e) {
            setNeedValidation();
        }

        public void componentHidden(ComponentEvent e) {
            setNeedValidation();
        }
    });

    File currentDir = new File("lib/natives");
    if (!currentDir.exists()) {
        //            JOptionPane.showMessageDialog(null, "directory location: "+currentDir.getAbsolutePath()+" does not exist!");
        currentDir = new File("build/libs/natives");
    }
    Logger.getLogger("LWJGLThread").log(Level.INFO, "LWJGL directory is " + currentDir.getAbsolutePath());

    System.setProperty("org.lwjgl.librarypath", currentDir.getAbsolutePath());

    Thread glThread = new Thread("GLThread") {

        @Override
        public void run() {
            long lastFrame = System.nanoTime();
            long currentFrame;
            try {
                Display.setParent(glCanvas);
                Display.create();

                GL11.glEnable(GL11.GL_TEXTURE_2D);
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                GL11.glDisable(GL11.GL_DEPTH_TEST);
                GL11.glClearColor(0f, 0f, 0f, 0f);
                GL11.glMatrixMode(GL11.GL_PROJECTION);
                GL11.glLoadIdentity();
                GL11.glOrtho(0f, (float) glCanvas.getWidth(), (float) glCanvas.getHeight(), 0f, -1, 1);
                GL11.glMatrixMode(GL11.GL_MODELVIEW);
                GL11.glLoadIdentity();
                GL11.glViewport(0, 0, glCanvas.getWidth(), glCanvas.getHeight());

                MainEngine.get().graphicsEngine().buildDefaultRenderers();

                while (MainEngine.get().isRunning()) {
                    try {
                        currentFrame = System.nanoTime();

                        MainEngine.get().renderScene(currentFrame - lastFrame);

                        lastFrame = currentFrame;

                        Display.update();

                        if (needUpdateViewport) {
                            needUpdateViewport = false;

                            GL11.glMatrixMode(GL11.GL_PROJECTION);
                            GL11.glLoadIdentity();
                            GL11.glOrtho(0, glCanvas.getWidth(), glCanvas.getHeight(), 0, -1, 1);
                            GL11.glViewport(0, 0, glCanvas.getWidth(), glCanvas.getHeight());
                        }
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        Logger.getLogger("LWJGLThread").log(Level.SEVERE,
                                "There was a SEROUS uncaught error in the render thread.  Shutting down.  Please restart!",
                                ex);
                        MainEngine.get().shutdown();
                    }
                }
            } catch (Throwable ex) {
                throw new RuntimeException("There was an issue starting LWJGL!", ex);
            }
        }

    };
    glThread.start();
}