Example usage for org.lwjgl.opengl GL11 glBlendFunc

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

Introduction

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

Prototype

public static void glBlendFunc(@NativeType("GLenum") int sfactor, @NativeType("GLenum") int dfactor) 

Source Link

Document

Specifies the weighting factors used by the blend equation, for both RGB and alpha functions and for all draw buffers.

Usage

From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Context.java

License:MIT License

@Override
public void setBlendingFunctions(int bufferIndex, BlendFunction source, BlendFunction destination) {
    checkCreated();/*from  www . j  av  a 2 s . co  m*/
    GL11.glBlendFunc(source.getGLConstant(), destination.getGLConstant());
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.gameminers.mav.render.Rendering.java

License:Open Source License

public static void setUpGL() {
    GL11.glEnable(GL11.GL_TEXTURE_2D);/*from  w  ww.  j  av  a  2s. c o  m*/
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearDepth(1);

    GL11.glShadeModel(GL11.GL_FLAT);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}

From source file:com.golden.gamedev.engine.lwjgl.LWJGLMode.java

License:Open Source License

private void initGL() {
    // init GL// ww w.j  ava  2s.co  m
    // enable textures since we're going to use these for our sprites
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // disable the OpenGL depth test since we're rendering 2D graphics
    GL11.glDisable(GL11.GL_DEPTH_TEST);

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

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

    // enable transparency
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}

From source file:com.grillecube.client.renderer.gui.font.FontModel.java

/** render this font model */
public void render() {

    if (this.hasState(FontModel.STATE_TEXT_UP_TO_DATE) == false) {
        this.updateText();
    }//w w  w. j ava  2  s . c  o m

    if (this.vertexCount == 0 || this.font == null) {
        return;
    }

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

    this.vao.bind();

    this.font.getTexture().bind(GL13.GL_TEXTURE0, GL11.GL_TEXTURE_2D);
    this.vao.draw(GL11.GL_TRIANGLES, 0, this.vertexCount);
}

From source file:com.grillecube.client.renderer.gui.GuiRenderer.java

@Override
public void render() {

    GL11.glDisable(GL11.GL_DEPTH_TEST);/*from   w w  w.j  ava 2s. c  o m*/
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // render them in the correct order
    for (Gui gui : this.renderingList) {
        gui.render(this);
    }

    GL11.glDisable(GL11.GL_BLEND);
}

From source file:com.grillecube.client.renderer.model.ModelRenderer.java

/** render world terrains */
public void render(CameraProjective camera, HashMap<Model, ArrayList<ModelInstance>> renderingList) {

    if (this.getMainRenderer().getGLFWWindow().isKeyPressed(GLFW.GLFW_KEY_F)) {
        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
    }//from   w  ww  .  jav  a2s.  c o m

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    // enable model program
    this.programModel.useStart();
    {
        // load global uniforms
        this.programModel.loadCamera(camera);

        // for each entity to render
        for (ArrayList<ModelInstance> models : renderingList.values()) {
            if (models.size() > 0) {
                Model model = models.get(0).getModel();
                model.bind();
                this.programModel.loadModel(model);
                for (ModelInstance instance : models) {
                    this.programModel.loadModelInstance(instance);
                    model.draw();
                }
            }
        }
    }
    this.programModel.useStop();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}

From source file:com.grillecube.client.renderer.particles.ParticleRenderer.java

/**
 * render every given billoaded particles with the given camera (billboarded
 * = textured quad facing the camera)/*from ww  w.j a  v  a  2 s  .  c o  m*/
 */
public final void renderBillboardedParticles(CameraProjective camera,
        ArrayList<ParticleBillboarded> particles) {
    if (particles.size() == 0) {
        return;
    }
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0); // Texture unit 0

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    this.programBillboardedParticles.useStart();
    this.getMainRenderer().getDefaultVAO().bind();

    this.programBillboardedParticles.loadGlobalUniforms(camera);

    HashMap<ParticleBillboarded, Double> distances = new HashMap<ParticleBillboarded, Double>(
            particles.size() * 4);
    for (ParticleBillboarded particle : particles) {
        distances.put(particle, Vector3f.distanceSquare(particle.getPosition(), camera.getPosition()));
    }
    particles.sort(new Comparator<ParticleBillboarded>() {
        @Override
        public int compare(ParticleBillboarded a, ParticleBillboarded b) {
            double da = distances.get(a);
            double db = distances.get(b);
            if (da < db) {
                return (1);
            } else if (da > db) {
                return (-1);
            }
            return (0);
        }
    });

    int i = 0;
    while (i < particles.size()) {
        ParticleBillboarded particle = particles.get(i);
        float radius = Maths.max(Maths.max(particle.getSizeX(), particle.getSizeY()), particle.getSizeZ());
        if (particle != null && distances.get(particle) < camera.getSquaredRenderDistance()
                && camera.isSphereInFrustum(particle.getPosition(), radius)) {
            this.programBillboardedParticles.loadInstanceUniforms(particle);
            this.getMainRenderer().getDefaultVAO().draw(GL11.GL_POINTS, 0, 1);
        }
        ++i;
    }
}

From source file:com.grillecube.client.renderer.particles.ParticleRenderer.java

/** render every cube particles */
public final void renderCubeParticles(CameraProjective camera, ArrayList<ParticleCube> particles) {
    if (particles.size() == 0) {
        return;//from   www  .j a v a  2 s  .  c  o m
    }

    // get the number of cube particle alive
    int cube_count = Maths.min(particles.size(), ParticleRenderer.MAX_CUBE_PARTICLES);

    if (cube_count == ParticleRenderer.MAX_CUBE_PARTICLES) {
        Logger.get().log(Logger.Level.WARNING, "Max number of cube particle reached! " + particles.size() + "/"
                + ParticleRenderer.MAX_CUBE_PARTICLES);
    }

    // create a buffer to hold them all
    ByteBuffer floats = BufferUtils.createByteBuffer(cube_count * CubeMesh.FLOATS_PER_CUBE_INSTANCE * 4);
    int cubesInBuffer = 0;
    for (int i = 0; i < cube_count; i++) {
        ParticleCube particle = particles.get(i);

        // if not in frustum, do not render it
        if (!camera.isBoxInFrustum(particle, particle)) {
            continue;
        }

        Matrix4f mat = particle.getTransfMatrix();
        Vector4f color = particle.getColor();
        float health = particle.getHealthRatio();

        floats.putFloat(mat.m00);
        floats.putFloat(mat.m01);
        floats.putFloat(mat.m02);
        floats.putFloat(mat.m03);

        floats.putFloat(mat.m10);
        floats.putFloat(mat.m11);
        floats.putFloat(mat.m12);
        floats.putFloat(mat.m13);

        floats.putFloat(mat.m20);
        floats.putFloat(mat.m21);
        floats.putFloat(mat.m22);
        floats.putFloat(mat.m23);

        floats.putFloat(mat.m30);
        floats.putFloat(mat.m31);
        floats.putFloat(mat.m32);
        floats.putFloat(mat.m33);

        floats.putFloat(color.x);
        floats.putFloat(color.y);
        floats.putFloat(color.z);
        floats.putFloat(color.w);

        floats.putFloat(health);

        ++cubesInBuffer;
    }
    floats.flip();
    this.cubeInstancesVBO.bind(GL15.GL_ARRAY_BUFFER);
    int buffersize = cubesInBuffer * CubeMesh.FLOATS_PER_CUBE_INSTANCE * 4;
    this.cubeInstancesVBO.bufferDataUpdate(GL15.GL_ARRAY_BUFFER, floats, buffersize);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    this.programCube.useStart();
    this.programCube.loadGlobalUniforms(camera);

    this.cubeMesh.bind();
    this.cubeMesh.drawInstanced(cubesInBuffer);

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

From source file:com.grillecube.client.renderer.particles.ProgramParticleBillboarded.java

/** load particle instance uniforms */
public void loadInstanceUniforms(ParticleBillboarded particle) {
    particle.getSprite().getTexture().bind(GL13.GL_TEXTURE0, GL11.GL_TEXTURE_2D);
    if (particle.isGlowing()) {
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    } else {//from  w ww  .jav a 2 s .c o  m
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    }
    super.loadUniformInteger(this._lines, particle.getSprite().getLines());
    super.loadUniformInteger(this._cols, particle.getSprite().getCols());
    super.loadUniformInteger(this._maxhealth, particle.getMaxHealth());
    super.loadUniformInteger(this._health, particle.getHealth());

    super.loadUniformVec(this._color, particle.getColor());
    super.loadUniformVec(this._position, particle.getPosition());
    super.loadUniformVec(this._scale, particle.getSize());
}

From source file:com.grillecube.client.renderer.world.TerrainRenderer.java

public void render(CameraProjective camera, WorldFlat world, ArrayList<TerrainMesh> opaqueMeshes,
        ArrayList<TerrainMesh> transparentMeshes) {

    GL11.glEnable(GL11.GL_DEPTH_TEST);/* w ww. j ava2s . c o m*/

    if (this.getMainRenderer().getGLFWWindow().isKeyPressed(GLFW.GLFW_KEY_F)) {
        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
    }

    this.terrainProgram.useStart();
    this.terrainProgram.loadUniforms(camera, world);

    if (opaqueMeshes != null && opaqueMeshes.size() > 0) {
        this.drawMeshes(camera, opaqueMeshes, ProgramTerrain.MESH_TYPE_OPAQUE);
    }

    if (transparentMeshes != null && transparentMeshes.size() > 0) {
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        // bind textures
        this.drawMeshes(camera, transparentMeshes, ProgramTerrain.MESH_TYPE_TRANSPARENT);
        GL11.glDisable(GL11.GL_BLEND);
    }

    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}