Example usage for org.lwjgl.opengl GL11 GL_CURRENT_COLOR

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

Introduction

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

Prototype

int GL_CURRENT_COLOR

To view the source code for org.lwjgl.opengl GL11 GL_CURRENT_COLOR.

Click Source Link

Document

GetTarget

Usage

From source file:blusunrize.lib.manual.ManualUtils.java

/**
 * Custom implementation of drawing a split string because Mojang's doesn't reset text colour between lines >___>
 *//*  w w w .  j  av  a 2 s .  c om*/
public static void drawSplitString(FontRenderer fontRenderer, String string, int x, int y, int width,
        int colour) {
    fontRenderer.resetStyles();
    fontRenderer.textColor = colour;
    List<String> list = fontRenderer.listFormattedStringToWidth(string, width);
    FloatBuffer currentGLColor = BufferUtils.createFloatBuffer(16);
    int line = 0;
    for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); y += fontRenderer.FONT_HEIGHT) {
        String next = iterator.next();
        if (line > 0) {
            int currentColour = fontRenderer.textColor;
            GL11.glGetFloat(GL11.GL_CURRENT_COLOR, currentGLColor);
            //Resetting colour if GL colour differs from textColor
            //that case happens because the formatting reset does not reset textColor
            int glColourRGBA = ((int) (currentGLColor.get(0) * 255) << 16)
                    + ((int) (currentGLColor.get(1) * 255) << 8) + ((int) (currentGLColor.get(2) * 255));
            if (glColourRGBA != currentColour) {
                int j = 0;
                for (; j < fontRenderer.colorCode.length; j++)
                    if (fontRenderer.colorCode[j] == glColourRGBA) {
                        String code = Integer.toHexString(j % 16);
                        next = '\u00a7' + code + next;
                        break;
                    }
            }
        }
        fontRenderer.drawString(next, x, y, colour, false);
    }
}

From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

private int getAttrib(Attribute attrib) {
    switch (attrib) {
    case CURRENT_COLOR:
        return GL11.GL_CURRENT_COLOR;
    case LINE_WIDTH:
        return GL11.GL_LINE_WIDTH;
    case POINT_SIZE:
        return GL11.GL_POINT_SIZE;
    default://from ww  w  . j a va  2 s  .  co  m
        return 0;
    }
}

From source file:org.interreg.docexplore.reader.DebugGraphics.java

License:Open Source License

public void addImage(BufferedImage image, double x, double y, double w, double h) {
    synchronized (overlays) {
        ImageOverlay overlay = overlays.remove(image);
        if (overlay == null)
            overlay = new ImageOverlay();
        Gdx.gl11.glGetFloatv(GL11.GL_CURRENT_COLOR, currentColor);
        currentColor.position(0).limit(currentColor.capacity());
        overlay.set(x, y, w, h, currentColor.get(0), currentColor.get(1), currentColor.get(2),
                currentColor.get(3));/*  w w w  .  j av a2 s  .  co  m*/
        overlays.put(image, overlay);
    }
}

From source file:zildo.fwk.gfx.engine.SpriteEngine.java

License:Open Source License

public void render(boolean backGround) {

    // Display every sprites
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);//from w  w w .j av  a  2 s  .  c  om
    float[] color = ZUtils.getFloat(GL11.GL_CURRENT_COLOR, 4);

    Vector3f ambient = ClientEngineZildo.ortho.getAmbientColor();
    if (ambient != null) {
        color[0] = ambient.x;
        color[1] = ambient.y;
        color[2] = ambient.z;
    }
    // Respect order from bankOrder
    boolean endSequence = false;
    int posBankOrder = 0;

    // Retrieve the sprite's order
    int[][] bankOrder = ClientEngineZildo.spriteDisplay.getBankOrder();

    int phase = (backGround) ? 0 : 1;
    while (!endSequence) {
        int numBank = bankOrder[phase][posBankOrder * 4];
        if (numBank == -1) {
            endSequence = true;
        } else {
            // Render the n sprites from this bank
            int nbQuads = bankOrder[phase][posBankOrder * 4 + 1];
            int iCurrentFX = bankOrder[phase][posBankOrder * 4 + 2];
            int alpha = bankOrder[phase][posBankOrder * 4 + 3];
            EngineFX currentFX = EngineFX.values()[iCurrentFX];
            int texId = textureTab[numBank];
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

            // Select the right pixel shader (if needed)
            if (pixelShaderSupported) {
                switch (currentFX) {
                case NO_EFFECT:
                    ARBShaderObjects.glUseProgramObjectARB(0);
                    break;
                case PERSO_HURT:
                    // A sprite has been hurt
                    ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(1));
                    ClientEngineZildo.pixelShaders.setParameter(1, "randomColor", new Vector4f(
                            (float) Math.random(), (float) Math.random(), (float) Math.random(), 1));
                    break;
                default:
                    if (currentFX.needPixelShader()) {
                        // This is a color replacement, so get the right ones
                        Vector4f[] tabColors = ClientEngineZildo.pixelShaders
                                .getConstantsForSpecialEffect(currentFX);

                        // And enable the 'color replacement' pixel shader
                        ARBShaderObjects
                                .glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(0));
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color1", tabColors[2]);
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color2", tabColors[3]);
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color3",
                                (Vector4f) new Vector4f(tabColors[0]).scale(color[0]));
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color4",
                                (Vector4f) new Vector4f(tabColors[1]).scale(color[0]));
                    } else {
                        ARBShaderObjects.glUseProgramObjectARB(0);
                    }
                }
            }
            switch (currentFX) {
            case SHINY:
                GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); // _MINUS_SRC_ALPHA);
                GL11.glColor4f(1, (float) Math.random(), 0, (float) Math.random());
                break;
            case QUAD:
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                GL11.glColor4f(0.5f + 0.5f * (float) Math.random(), 0.5f * (float) Math.random(), 0, 1);
                break;
            case FOCUSED:
                GL11.glColor3f(1.0f, 1.0f, 1.0f);
                break;
            default:
                color[3] = alpha / 255.0f;
                ZUtils.setCurrentColor(color);
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            }
            meshSprites[numBank].render(nbQuads);
            posBankOrder++;
        }
    }

    // Deactivate pixel shader
    if (pixelShaderSupported) {
        ARBShaderObjects.glUseProgramObjectARB(0);
    }
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:zildo.platform.engine.LwjglSpriteEngine.java

License:Open Source License

@Override
public void render(int floor, boolean backGround) {

    // Display every sprites
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);//from w  w w. ja  v  a  2s .  c om
    float[] color = textureEngine.graphicStuff.getFloat(GL11.GL_CURRENT_COLOR, 4);

    Vector3f ambient = ClientEngineZildo.ortho.getAmbientColor();
    Vector4f ambient4f = new Vector4f(1, 1, 1, 1);
    if (ambient != null) {
        color[0] = ambient.x;
        color[1] = ambient.y;
        color[2] = ambient.z;
        ambient4f = new Vector4f(color[0], color[1], color[2], 1);
    }
    // Respect order from bankOrder
    boolean endSequence = false;
    int posBankOrder = 0;

    // Retrieve the sprite's order
    int[][][] bankOrder = ClientEngineZildo.spriteDisplay.getBankOrder();

    int phase = (backGround) ? 0 : 1;
    while (!endSequence) {
        int numBank = bankOrder[floor][phase][posBankOrder * 4];
        if (numBank == -1) {
            endSequence = true;
        } else {
            // Render the n sprites from this bank
            int nbQuads = bankOrder[floor][phase][posBankOrder * 4 + 1];
            int iCurrentFX = bankOrder[floor][phase][posBankOrder * 4 + 2];
            int alpha = bankOrder[floor][phase][posBankOrder * 4 + 3];
            EngineFX currentFX = EngineFX.values()[iCurrentFX];
            int texId = textureEngine.getNthTexture(numBank);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

            // Select the right pixel shader (if needed)
            if (pixelShaderSupported) {
                switch (currentFX) {
                case NO_EFFECT:
                    ARBShaderObjects.glUseProgramObjectARB(0);
                    break;
                case PERSO_HURT:
                    // A sprite has been hurt
                    ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(1));
                    ClientEngineZildo.pixelShaders.setParameter(1, "randomColor", new Vector4f(
                            (float) Math.random(), (float) Math.random(), (float) Math.random(), 1));
                    break;
                case YELLOW_HALO:
                    ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(2));
                    ClientEngineZildo.pixelShaders.setParameter(2, "factor",
                            new Vector4f((float) (0.6 + 0.4 * Math.cos(3 * gamma)), 0, 0, 1));
                    break;
                case STAR:
                    ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(3));
                    ClientEngineZildo.pixelShaders.setParameter(3, "noise",
                            new Vector4f(gamma, (float) Math.random(), 0, 1));
                    break;
                case FIRE:
                    ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(4));
                    //ClientEngineZildo.pixelShaders.setParameter(4, "iResolution", new Vector4f(Zildo.viewPortX, Zildo.viewPortY, 0, 0));
                    ClientEngineZildo.pixelShaders.setParameter(4, "iGlobalTime", new Vector4f(gamma, 0, 0, 0));
                    break;
                default:
                    if (currentFX.needPixelShader()) {
                        // This is a color replacement, so get the right ones
                        Vector4f[] tabColors = ClientEngineZildo.pixelShaders
                                .getConstantsForSpecialEffect(currentFX);

                        // And enable the 'color replacement' pixel shader
                        ARBShaderObjects
                                .glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(0));
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color1", tabColors[2]); //.scale(color[0]));
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color2", tabColors[3]); //.scale(color[0]));
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color3", tabColors[0]);
                        ClientEngineZildo.pixelShaders.setParameter(0, "Color4", tabColors[1]);
                        ClientEngineZildo.pixelShaders.setParameter(0, "curColor", ambient4f);
                    } else {
                        ARBShaderObjects.glUseProgramObjectARB(0);
                    }
                }
            }
            switch (currentFX) {
            case SHINY:
                GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); // _MINUS_SRC_ALPHA);
                GL11.glColor4f(1, (float) Math.random(), 0, (float) Math.random());
                break;
            case QUAD:
                //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                //GL11.glColor4f(0.5f + 0.5f * (float) Math.random(), 0.5f * (float) Math.random(), 0, 1);
                GL11.glColor4f(0.7f, 0.6f, 0.8f, 1);
                break;
            /*
            case WHITE_HALO:
            float r = (float) (0.6 + 0.4 * Math.random());
            GL11.glColor4f(r, 0, 0, 1);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);
            break;
            */
            case FOCUSED:
                GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha / 255.0f);
                break;
            case FONT_PEOPLENAME:
                GL11.glColor4f(0.9f, 0.5f, 0.2f, alpha / 255.0f);
                break;
            case INFO:
                GL11.glColor4f(0.9f, 0.8f, 0.72f, alpha / 255.0f);
                break;
            default:
                color[3] = alpha / 255.0f;
                textureEngine.graphicStuff.setCurrentColor(color);
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            }
            meshSprites[numBank].render(nbQuads);
            posBankOrder++;
        }
    }

    // Deactivate pixel shader
    if (pixelShaderSupported) {
        ARBShaderObjects.glUseProgramObjectARB(0);
    }
    GL11.glDisable(GL11.GL_BLEND);

    gamma += 0.01f;
}