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:kuake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_SetupFrame//from w w  w  .  j a v a  2  s. co m
 */
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;
        }
    }

    for (int i = 0; i < 4; i++)
        v_blend[i] = r_newrefdef.blend[i];

    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:kuake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_SetPalette//from  w w  w .j av a 2  s . c  om
 */
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) << 0;
            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:kuake2.render.lwjgl.Misc.java

License:Open Source License

void GL_SetDefaultState() {
    GL11.glClearColor(1f, 0f, 0.5f, 0.5f); // original quake2
    //GL11.glClearColor(0, 0, 0, 0); // replaced with black
    GL11.glCullFace(GL11.GL_FRONT);/*from w w w. j  av a2  s .c  o m*/
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.666f);

    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_BLEND);

    GL11.glColor4f(1, 1, 1, 1);

    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GL11.glShadeModel(GL11.GL_FLAT);

    GL_TextureMode(gl_texturemode.string);
    GL_TextureAlphaMode(gl_texturealphamode.string);
    GL_TextureSolidMode(gl_texturesolidmode.string);

    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, gl_filter_min);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, gl_filter_max);

    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

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

    GL_TexEnv(GL11.GL_REPLACE);

    if (qglPointParameterfEXT) {
        // float[] attenuations = { gl_particle_att_a.value, gl_particle_att_b.value, gl_particle_att_c.value };
        FloatBuffer att_buffer = BufferUtils.createFloatBuffer(4);
        att_buffer.put(0, gl_particle_att_a.value);
        att_buffer.put(1, gl_particle_att_b.value);
        att_buffer.put(2, gl_particle_att_c.value);

        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        EXTPointParameters.glPointParameterfEXT(EXTPointParameters.GL_POINT_SIZE_MIN_EXT,
                gl_particle_min_size.value);
        EXTPointParameters.glPointParameterfEXT(EXTPointParameters.GL_POINT_SIZE_MAX_EXT,
                gl_particle_max_size.value);
        EXTPointParameters.glPointParameterEXT(EXTPointParameters.GL_DISTANCE_ATTENUATION_EXT, att_buffer);
    }

    if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f) {
        GL11.glEnable(EXTSharedTexturePalette.GL_SHARED_TEXTURE_PALETTE_EXT);

        GL_SetTexturePalette(d_8to24table);
    }

    GL_UpdateSwapInterval();

    /*
     * vertex array extension
     */
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    ARBMultitexture.glClientActiveTextureARB(GL_TEXTURE0);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
}

From source file:lwjglapp.Renderer.java

private void initGL() {

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();/*from  w  w  w  .  j a  v a 2 s . c  o m*/
    GLU.gluPerspective(45.0f, (float) (width / height), 0.1f, 100.0f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    //      GL11.glLoadIdentity();
    //
    //      GL11.glEnable(GL11.GL_TEXTURE_2D);                                    // Enable Texture Mapping ( NEW )
    //      GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}

From source file:main.java.com.YeAJG.game.Game.java

License:Open Source License

/**
 * Initiates Display and OpenGL, using OpenGL 3.2
 *///from ww  w  .java  2 s.c  o m
private void setupOpenGL() {
    try {
        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes = new ContextAttribs(3, 2).withForwardCompatible(true)
                .withProfileCore(true);

        Display.setDisplayMode(new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT));
        Display.setTitle(Name + " " + ConfigHandler.getVersion());
        Display.create(pixelFormat, contextAtrributes);
    } catch (LWJGLException e) {
        logger.fatal(e.getMessage());
        System.exit(-1);
    }
    //Sets the Background color.
    GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);

    //Creates the Viewport.       
    GL11.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);

    //Enables Depth Testing.
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    //Exit on Setup Error.
    Game.exitOnGLError("setupOpenGL");
}

From source file:main.MasterRenderer.java

public void prepare() {
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glClearColor(0.3f, 0.8f, 0.8f, 1);
}

From source file:map.GameMap.java

License:Open Source License

private void renderMinimap() {
    int size = MINIMAP_SIZE;
    Texture tex = new Texture("ground");
    miniMap = new Material(name + "_minimap");
    int[] viewport = GLUtils.getViewport();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();//from   www. ja  va  2  s.co m
    GL11.glOrtho(0, size, size, 0, -10, 10);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, size, size);

    GL11.glClearColor(0.0f, 0, 0, 1.0f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glScalef(size / tiles.length, size / tiles.length, size / tiles.length);

    GLUtils.glLightPos(1.0f, 1.0f, 1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    draw(null);
    GL11.glEnable(GL11.GL_CULL_FACE);

    IntBuffer addr = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(addr);
    tex.setID(addr.get(0));
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID());

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, size, size, 0);

    miniMap.setTexture(0, tex);
    GL11.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

public void createWindow(int width, int height, String name) {
    this.width = width;
    this.height = height;
    glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
    if (glfwInit() != GL11.GL_TRUE)
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwDefaultWindowHints(); // optional, the current window hints are
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); // the window will stay
    // hidden//from  w  ww.j  a v a 2s  . c o  m
    glfwWindowHint(GLFW_RESIZABLE, GL11.GL_TRUE); // the window will be
    // resizable
    window = glfwCreateWindow(width, height, name, NULL, NULL);
    if (window == NULL)
        throw new RuntimeException("Failed to create the GLFW window");
    // glfwSetKeyCallback(window,this.keyCallback = keyCallback);
    glfwSetWindowSizeCallback(window, resizeCallback());
    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.asIntBuffer().get(0) - width) / 2,
            (vidmode.asIntBuffer().get(1) - height) / 2);
    glfwMakeContextCurrent(window);
    Graphic.instance = this;
    glfwSwapInterval(1);
    GL.createCapabilities();
    setCapabilities();

    glfwShowWindow(window);

    // Setup an XNA like background color
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);

    GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0);
    // Map the internal OpenGL coordinate system to the entire screen
    GL11.glViewport(0, 0, width, height);
    matBuff = BufferUtils.createFloatBuffer(16);
    vaoId = GL30.glGenVertexArrays();
    vboiId = GL15.glGenBuffers();
    vboId = GL15.glGenBuffers();
    tid_charmap = texManager.loadTexture("textures/charmap.png", GL13.GL_TEXTURE0);
    shader.setupShader();
    // testQuad();

}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private synchronized void render() {
    GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL20.glUseProgram(shader.getPID());/*w  w w  . j  a va2s .c  o  m*/
    //

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL30.glBindVertexArray(vaoId);

    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    long offset = 0;
    int shift = 0;
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    for (Drawable object : objects) {
        Matrix4f finalMVP = new Matrix4f(mvpMat);
        Matrix4f modelMat = new Matrix4f();
        Matrix4f scaler = new Matrix4f();
        scaler.scale(object.scale * allScale);
        modelMat.translate(object.translation);
        modelMat.rotateXYZ(object.rotation.x, object.rotation.y, object.rotation.z);
        finalMVP.mul(modelMat);
        finalMVP.mul(scaler);
        finalMVP.get(0, matBuff);
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap));
        }
        GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);
        GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0);
        if (object.isVisible())
            GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE,
                    offset, shift);

        offset += object.getIndices().length;
        shift += object.getVertex().length;
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
        }
    }
    render2d(offset, shift);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
    //
    GL20.glUseProgram(0);
    glfwSwapBuffers(window);
    glfwPollEvents();

}

From source file:me.thehutch.fusion.engine.render.opengl.GLContext.java

License:Open Source License

@Override
public void setClearColour(float r, float g, float b) {
    ensureCreated("Can not set clear colour if the context has not been created");
    GL11.glClearColor(r, g, b, 1.0f);
}