Example usage for org.lwjgl.opengl GL11 glColor3f

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

Introduction

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

Prototype

public static native void glColor3f(@NativeType("GLfloat") float red, @NativeType("GLfloat") float green,
        @NativeType("GLfloat") float blue);

Source Link

Document

Float version of #glColor3b Color3b

Usage

From source file:org.craftmania.blocks.BlockType.java

License:Apache License

@Override
public void renderHoldableObject(LightBuffer lightBuffer) {

    /* Smoothen the light buffer */

    // int avg = 0;
    // for (int i0 = 0; i0 < lightBuffer.length; ++i0)
    // {/*  w w w . j  a  v  a2s  .c o m*/
    // for (int i1 = 0; i1 < lightBuffer[i0].length; ++i1)
    // {
    // for (int i2 = 0; i2 < lightBuffer[i0][i1].length; ++i2)
    // {
    // avg += lightBuffer[i0][i1][i2];
    // }
    // }
    // }
    // avg /= 27.0f;
    // for (int i0 = 0; i0 < lightBuffer.length; ++i0)
    // {
    // for (int i1 = 0; i1 < lightBuffer[i0].length; ++i1)
    // {
    // for (int i2 = 0; i2 < lightBuffer[i0][i1].length; ++i2)
    // {
    // lightBuffer[i0][i1][i2] = (byte) avg;
    // }
    // }
    // }

    if (customInventoryImage != null) {
        GL11.glPushMatrix();
        float scale = 0.1f / 16.0f;
        float light = lightBuffer.get(1, 1, 1) / 30.001f;
        GL11.glScalef(scale, scale, scale);
        GL11.glColor3f(0.5f * light, 0.5f * light, 0.5f * light);
        /* Render the texture */
        for (float i = 0.0f; i < 0.02f; i += 0.002f) {
            if (i > 0.016f) {
                GL11.glColor3f(1.0f * light, 1.0f * light, 1.0f * light);
            }
            renderInventoryItem();
            GL11.glTranslatef(0, 0, 0.002f / scale);
        }
        GL11.glPopMatrix();
    } else {
        if (brush != null) {
            float scale = 0.1f;
            glScalef(scale, scale, scale);
            glRotatef(-40, 0, 0, 1);
            brush.setPosition(0, 0, 0);
            brush.render(lightBuffer);
        }
    }
}

From source file:org.craftmania.blocks.CrossedBlockBrush.java

License:Apache License

@Override
public void render(LightBuffer lightBuffer) {
    if (_callList != 0) {
        _terrain.bind();/*from   w ww .j a va  2 s.  c om*/

        float light = lightBuffer.get(1, 1, 1) / 30.001f;

        /* Texture 11,10 -> 11,15 */
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_BLEND);
        // GL11.glDepthFunc(GL11.GL_ALWAYS);
        GL11.glPushMatrix();
        GL11.glTranslatef(_position.x() + 0.5f, _position.y() + 0.5f, _position.z() + 0.5f);
        GL11.glColor3f(light, light, light);

        GL11.glCallList(_callList);

        GL11.glPopMatrix();
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_BLEND);
    }
}

From source file:org.craftmania.inventory.InventoryItem.java

License:Apache License

public void renderHoldableObject(LightBuffer lightBuffer) {
    GL11.glPushMatrix();/*from  w  w w  .j  a v a2 s  .  c o  m*/
    float scale = 0.1f / 16.0f;
    float light = lightBuffer.get(1, 1, 1) / 30.001f;
    GL11.glScalef(scale, scale, scale);
    GL11.glColor3f(0.5f * light, 0.5f * light, 0.5f * light);
    /* Render the texture */
    for (float i = 0.0f; i < 0.02f; i += 0.002f) {
        if (i > 0.016f) {
            GL11.glColor3f(1.0f * light, 1.0f * light, 1.0f * light);
        }
        renderInventoryItem();
        GL11.glTranslatef(0, 0, 0.002f / scale);
    }
    GL11.glPopMatrix();
}

From source file:org.craftmania.world.Sky.java

License:Apache License

private void drawShpere(float x, float y, float z) {
    GL11.glPushMatrix();/*from  w  w  w.j ava2 s.com*/
    GL11.glTranslatef(x, y, z);
    GL11.glColor3f(_color.x(), _color.y(), _color.z());
    if (_sphereCallList == 0) {
        _sphereCallList = GL11.glGenLists(1);
        GL11.glNewList(_sphereCallList, GL11.GL_COMPILE_AND_EXECUTE);
        GL11.glBegin(GL11.GL_TRIANGLE_FAN);
        GL11.glVertex3f(0, 0, 0);
        for (int i = 0; i <= _vertices; ++i) {
            float angle = MathHelper.f_2PI / _vertices * i;
            float xx = MathHelper.cos(angle) * _radius;
            float zz = MathHelper.sin(angle) * _radius;
            GL11.glVertex3f(xx, -_bend, zz);
        }
        GL11.glEnd();
        GL11.glEndList();
    } else {
        GL11.glCallList(_sphereCallList);
    }
    GL11.glPopMatrix();
}

From source file:org.craftmania.world.World.java

License:Apache License

private void renderOverlay() {
    Configuration conf = Game.getInstance().getConfiguration();

    Game.getInstance().initOverlayRendering();

    GL11.glColor3f(1, 1, 1);

    if (Game.RENDER_INFORMATION_OVERLAY) {
        GLFont infoFont = FontStorage.getFont("Monospaced_20");

        /* Down Left Info */
        infoFont.print(4, 4, "CraftMania");
        infoFont.print(4, 30, _player.coordinatesToString());
        infoFont.print(4, 45, "Visible Chunks:      " + _visibleChunks.size());
        infoFont.print(4, 60, "Updading Blocks:     " + _updatingBlocks);
        infoFont.print(4, 75, "Total Chunks in RAM: " + _chunkManager.getTotalChunkCount());
        infoFont.print(4, 90, "Local Chunks:        " + _localChunks.size());
        infoFont.print(4, 105, "Total Local Blocks:  " + _localBlockCount);
        infoFont.print(4, 120, "Time:  " + _time);
        infoFont.print(4, 135, "Sunlight:  " + _sunlight);

    }/*from   w  ww .  ja  v  a2 s.  co m*/
    /** RENDER **/
    if (_activatedInventory != null) {
        Game.getInstance().renderTransculentOverlayLayer();
        _activatedInventory.renderInventory();
    } else {
        int width = conf.getWidth();
        int height = conf.getHeight();
        // Center Cross
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        if (CENTER_CROSS_CALL_LIST == 0) {
            CENTER_CROSS_CALL_LIST = GL11.glGenLists(1);
            GL11.glNewList(CENTER_CROSS_CALL_LIST, GL11.GL_COMPILE_AND_EXECUTE);

            int crossSize = 10;
            int crossHole = 5;

            GL11.glLineWidth(2.5f);

            GL11.glColor3f(0, 0, 0);
            GL11.glBegin(GL11.GL_LINES);
            GL11.glVertex3f(width / 2f - crossSize - crossHole, height / 2f, 0);
            GL11.glVertex3f(width / 2f - crossHole, height / 2f, 0);

            GL11.glVertex3f(width / 2f + crossSize + crossHole, height / 2f, 0);
            GL11.glVertex3f(width / 2f + crossHole, height / 2f, 0);

            GL11.glVertex3f(width / 2f, height / 2f - crossSize - crossHole, 0);
            GL11.glVertex3f(width / 2f, height / 2f - crossHole, 0);

            GL11.glVertex3f(width / 2f, height / 2f + crossSize + crossHole, 0);
            GL11.glVertex3f(width / 2f, height / 2f + crossHole, 0);

            GL11.glEnd();
            GL11.glEndList();
        } else {
            GL11.glCallList(CENTER_CROSS_CALL_LIST);
        }
        GL11.glEnable(GL11.GL_TEXTURE_2D);

        // Inventory bar
        GL11.glPushMatrix();
        Texture texGui = TextureStorage.getTexture("gui.gui");
        texGui.bind();
        float tileSize = 20.0f / texGui.getImageWidth();
        if (INVENTORY_BAR_CALL_LIST == 0) {
            INVENTORY_BAR_CALL_LIST = GL11.glGenLists(2);

            /* Bar */
            GL11.glNewList(INVENTORY_BAR_CALL_LIST, GL11.GL_COMPILE_AND_EXECUTE);

            GL11.glTranslatef(width / 2.0f - 9 * 20, 10, 0);
            GL11.glColor3f(1.0f, 1.0f, 1.0f);
            GL11.glBegin(GL11.GL_QUADS);

            GL11.glTexCoord2f(0, 0);
            GL11.glVertex2f(0, 40);

            GL11.glTexCoord2f(tileSize * 9, 0);
            GL11.glVertex2f(9 * 40, 40);

            GL11.glTexCoord2f(tileSize * 9, tileSize);
            GL11.glVertex2f(9 * 40, 0);

            GL11.glTexCoord2f(0, tileSize);
            GL11.glVertex2f(0, 0);

            GL11.glEnd();
            GL11.glEndList();

            /* Little frame around selected item */
            float frameTileSize = 24.0f / texGui.getImageWidth();
            float frameTileY = 22.0f / texGui.getImageHeight();

            GL11.glNewList(INVENTORY_BAR_CALL_LIST + 1, GL11.GL_COMPILE);
            GL11.glBegin(GL11.GL_QUADS);

            GL11.glTexCoord2f(0, frameTileY);
            GL11.glVertex2f(0, 48);

            GL11.glTexCoord2f(frameTileSize, frameTileY);
            GL11.glVertex2f(48, 48);

            GL11.glTexCoord2f(frameTileSize, frameTileY + frameTileSize);
            GL11.glVertex2f(48, 0);

            GL11.glTexCoord2f(0, frameTileY + frameTileSize);
            GL11.glVertex2f(0, 0);

            GL11.glEnd();
            GL11.glEndList();
        } else {
            GL11.glCallList(INVENTORY_BAR_CALL_LIST);
        }

        /* Content */
        GL11.glPushMatrix();
        GL11.glTranslatef(20, 20, 0);
        for (int i = 0; i < 9; ++i) {
            InventoryPlace place = getActivePlayer().getInventory().getInventoryPlace(i);
            if (place != null)
                place.render();
            GL11.glTranslatef(40, 0, 0);
        }
        texGui.bind();
        GL11.glPopMatrix();
        GL11.glTranslatef(getActivePlayer().getSelectedInventoryItemIndex() * 40.0f - 4, -4, 0);
        GL11.glCallList(INVENTORY_BAR_CALL_LIST + 1);

        GL11.glPopMatrix();
    }
}

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 .ja va2s .  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  w w  w  .j  ava  2s  . c om*/
    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 w  w w.  j  ava2  s  .c o  m*/
    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();
}

From source file:org.evilco.emulator.core.graphic.matrix.MonochromeMatrixScreen.java

License:Apache License

/**
 * {@inheritDoc}//from   w  w  w  .j a  v a  2 s  . c o  m
 */
@Override
public synchronized void draw() {
    // clear screen
    GL11.glClearColor(0, 0, 0, 1);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glColor3f(1f, 1f, 1f); // TODO: Make color adjustable

    // draw pixels
    for (short y = 0; y < this.height; y++) {
        for (short x = 0; x < this.width; x++) {
            // skip disabled pixels
            if (!this.getPixel(x, y))
                continue;

            // draw
            GL11.glRecti(x, y, (x + 1), (y + 1));
        }
    }
}

From source file:org.free.jake2.render.lwjgl.Draw.java

License:Open Source License

protected void Draw_Fill(int x, int y, int w, int h, int colorIndex) {

    if (colorIndex > 255) {
        Com.Error(Defines.ERR_FATAL, "Draw_Fill: bad color");
    }//  w  w  w  . ja  v  a  2  s .  c  o  m

    GL11.glDisable(GL11.GL_TEXTURE_2D);

    int color = d_8to24table[colorIndex];

    GL11.glColor3ub((byte) ((color) & 0xff), // r
            (byte) ((color >> 8) & 0xff), // g
            (byte) ((color >> 16) & 0xff) // b
    );

    GL11.glBegin(GL11.GL_QUADS);

    GL11.glVertex2f(x, y);
    GL11.glVertex2f(x + w, y);
    GL11.glVertex2f(x + w, y + h);
    GL11.glVertex2f(x, y + h);

    GL11.glEnd();
    GL11.glColor3f(1, 1, 1);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}