Example usage for org.lwjgl.opengl GL11 glEnd

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

Introduction

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

Prototype

public static native void glEnd();

Source Link

Document

Ends the definition of vertex attributes of a sequence of primitives to be transferred to the GL.

Usage

From source file:fr.ign.cogit.geoxygene.appli.render.RenderGL11Util.java

License:Open Source License

/**
 * Draw a shape polygon using open GL. It displays only the shape edges with
 * colors depending on segment types./*from   www.ja  v a 2s  . c o m*/
 * This method has been implemented for debug purpose in order to display
 * different colors
 * for the different shape's parts. Colors are not customizable
 * 
 * @param shape
 *            Java2D shape to paint
 */
public static void glDrawRawShapeColoredSegment(final Shape shape) {

    Color closeColor = Color.blue;
    Color moveColor = Color.red;
    Color lineColor = Color.black;
    Color quadColor = Color.yellow;
    Color cubicColor = Color.pink;

    boolean polygonStarted = false;
    float startX = 0, startY = 0;
    float prevX = 0, prevY = 0;

    GL11.glBegin(GL_LINES); // start a new polygon if not already done
    PathIterator pathIterator = shape.getPathIterator(null);
    // System.err.print("polygon ");
    int nPoint = 0;
    while (!pathIterator.isDone()) {
        float[] coords = new float[6];

        int segmentType = pathIterator.currentSegment(coords);
        switch (segmentType) {
        case PathIterator.SEG_CLOSE:

            if (polygonStarted) {
                glColor(closeColor);
                GL11.glVertex2f(prevX, prevY);
                GL11.glVertex2f(startX, startY);
                polygonStarted = false;
            } else {
                logger.error("Close a non open segment");
            }
        case PathIterator.SEG_MOVETO:
            if (polygonStarted) {
                glColor(moveColor);
                GL11.glVertex2f(prevX, prevY);
                GL11.glVertex2f(coords[0], coords[1]);
                startX = prevX = coords[0];
                startY = prevY = coords[1];
                //          polygonStarted = true;
            } else {
                polygonStarted = true;
                startX = prevX = coords[0];
                startY = prevY = coords[1];
                //          logger.warn("move to " + startX + "x" + startY + " but polygon not started n = " + nPoint);
            }
            break;
        case PathIterator.SEG_CUBICTO:

            if (polygonStarted) {
                glColor(cubicColor);
                GL11.glVertex2f(prevX, prevY);
                GL11.glVertex2f(coords[4], coords[5]);
                prevX = coords[4];
                prevY = coords[5];
            } else {
                polygonStarted = true;
                startX = prevX = coords[4];
                startY = prevY = coords[5];
            }
            break;
        case PathIterator.SEG_QUADTO:

            if (polygonStarted) {
                glColor(quadColor);
                GL11.glVertex2f(prevX, prevY);
                GL11.glVertex2f(coords[2], coords[3]);
                prevX = coords[2];
                prevY = coords[3];
            } else {
                polygonStarted = true;
                startX = prevX = coords[2];
                startY = prevY = coords[3];
            }
            break;

        case PathIterator.SEG_LINETO:

            if (polygonStarted) {
                glColor(lineColor);
                GL11.glVertex2f(prevX, prevY);
                GL11.glVertex2f(coords[0], coords[1]);
                prevX = coords[0];
                prevY = coords[1];
                if (nPoint == 1) {
                    logger.debug("First line point = " + prevX + "x" + prevY);
                }
            } else {
                polygonStarted = true;
                startX = prevX = coords[0];
                startY = prevY = coords[1];
            }
            break;
        default:
            logger.warn("Draw GL shape do not know how to handle segment type " + segmentType);
        }
        //      if (coords[0] != 0. || coords[1] != 0.)
        // System.err.print("  -  " + coords[0] + "x" + coords[1]);
        pathIterator.next();
    }
    GL11.glEnd();
}

From source file:fr.ign.cogit.geoxygene.util.gl.GLTools.java

License:Open Source License

public static void glDrawString(final String s, double x, double y) {
    double startX = x;
    GL11.glBegin(GL11.GL_POINTS);/*from  ww w .j a  v  a 2  s  . c  o  m*/
    for (char c : s.toLowerCase().toCharArray()) {
        if (c == 'a') {
            for (int i = 0; i < 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - 4);
            }
            x += 8;
        } else if (c == 'b') {
            for (int i = 0; i < 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + i, y);
                GL11.glVertex2d(x + i, y - 4);
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 7, y - 5);
            GL11.glVertex2d(x + 7, y - 7);
            GL11.glVertex2d(x + 7, y - 6);

            GL11.glVertex2d(x + 7, y - 1);
            GL11.glVertex2d(x + 7, y - 2);
            GL11.glVertex2d(x + 7, y - 3);
            x += 8;
        } else if (c == 'c') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y);
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 6, y - 1);
            GL11.glVertex2d(x + 6, y - 2);

            GL11.glVertex2d(x + 6, y - 6);
            GL11.glVertex2d(x + 6, y - 7);

            x += 8;
        } else if (c == 'd') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y);
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 6, y - 1);
            GL11.glVertex2d(x + 6, y - 2);
            GL11.glVertex2d(x + 6, y - 3);
            GL11.glVertex2d(x + 6, y - 4);
            GL11.glVertex2d(x + 6, y - 5);
            GL11.glVertex2d(x + 6, y - 6);
            GL11.glVertex2d(x + 6, y - 7);

            x += 8;
        } else if (c == 'e') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 0);
                GL11.glVertex2d(x + i, y - 8);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 4);
            }
            x += 8;
        } else if (c == 'f') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 8);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 4);
            }
            x += 8;
        } else if (c == 'g') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y);
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 6, y - 1);
            GL11.glVertex2d(x + 6, y - 2);
            GL11.glVertex2d(x + 6, y - 3);
            GL11.glVertex2d(x + 5, y - 3);
            GL11.glVertex2d(x + 7, y - 3);

            GL11.glVertex2d(x + 6, y - 6);
            GL11.glVertex2d(x + 6, y - 7);

            x += 8;
        } else if (c == 'h') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 4);
            }
            x += 8;
        } else if (c == 'i') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 3, y - i);
            }
            for (int i = 1; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 0);
                GL11.glVertex2d(x + i, y - 8);
            }
            x += 7;
        } else if (c == 'j') {
            for (int i = 1; i <= 8; i++) {
                GL11.glVertex2d(x + 6, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 0);
            }
            GL11.glVertex2d(x + 1, y - 3);
            GL11.glVertex2d(x + 1, y - 2);
            GL11.glVertex2d(x + 1, y - 1);
            x += 8;
        } else if (c == 'k') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            GL11.glVertex2d(x + 6, y - 8);
            GL11.glVertex2d(x + 5, y - 7);
            GL11.glVertex2d(x + 4, y - 6);
            GL11.glVertex2d(x + 3, y - 5);
            GL11.glVertex2d(x + 2, y - 4);
            GL11.glVertex2d(x + 2, y - 3);
            GL11.glVertex2d(x + 3, y - 4);
            GL11.glVertex2d(x + 4, y - 3);
            GL11.glVertex2d(x + 5, y - 2);
            GL11.glVertex2d(x + 6, y - 1);
            GL11.glVertex2d(x + 7, y);
            x += 8;
        } else if (c == 'l') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + i, y);
            }
            x += 7;
        } else if (c == 'm') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            GL11.glVertex2d(x + 3, y - 6);
            GL11.glVertex2d(x + 2, y - 7);
            GL11.glVertex2d(x + 4, y - 5);

            GL11.glVertex2d(x + 5, y - 6);
            GL11.glVertex2d(x + 6, y - 7);
            GL11.glVertex2d(x + 4, y - 5);
            x += 8;
        } else if (c == 'n') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            GL11.glVertex2d(x + 2, y - 7);
            GL11.glVertex2d(x + 2, y - 6);
            GL11.glVertex2d(x + 3, y - 5);
            GL11.glVertex2d(x + 4, y - 4);
            GL11.glVertex2d(x + 5, y - 3);
            GL11.glVertex2d(x + 6, y - 2);
            GL11.glVertex2d(x + 6, y - 1);
            x += 8;
        } else if (c == 'o' || c == '0') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - 0);
            }
            x += 8;
        } else if (c == 'p') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - 4);
            }
            GL11.glVertex2d(x + 6, y - 7);
            GL11.glVertex2d(x + 6, y - 5);
            GL11.glVertex2d(x + 6, y - 6);
            x += 8;
        } else if (c == 'q') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
                if (i != 1) {
                    GL11.glVertex2d(x + 7, y - i);
                }
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 8);
                if (i != 6) {
                    GL11.glVertex2d(x + i, y - 0);
                }
            }
            GL11.glVertex2d(x + 4, y - 3);
            GL11.glVertex2d(x + 5, y - 2);
            GL11.glVertex2d(x + 6, y - 1);
            GL11.glVertex2d(x + 7, y);
            x += 8;
        } else if (c == 'r') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - 4);
            }
            GL11.glVertex2d(x + 6, y - 7);
            GL11.glVertex2d(x + 6, y - 5);
            GL11.glVertex2d(x + 6, y - 6);

            GL11.glVertex2d(x + 4, y - 3);
            GL11.glVertex2d(x + 5, y - 2);
            GL11.glVertex2d(x + 6, y - 1);
            GL11.glVertex2d(x + 7, y);
            x += 8;
        } else if (c == 's') {
            for (int i = 2; i <= 7; i++) {
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 1, y - 7);
            GL11.glVertex2d(x + 1, y - 6);
            GL11.glVertex2d(x + 1, y - 5);
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 4);
                GL11.glVertex2d(x + i, y);
            }
            GL11.glVertex2d(x + 7, y - 3);
            GL11.glVertex2d(x + 7, y - 2);
            GL11.glVertex2d(x + 7, y - 1);
            GL11.glVertex2d(x + 1, y - 1);
            GL11.glVertex2d(x + 1, y - 2);
            x += 8;
        } else if (c == 't') {
            for (int i = 0; i <= 8; i++) {
                GL11.glVertex2d(x + 4, y - i);
            }
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + i, y - 8);
            }
            x += 7;
        } else if (c == 'u') {
            for (int i = 1; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 0);
            }
            x += 8;
        } else if (c == 'v') {
            for (int i = 2; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 6, y - i);
            }
            GL11.glVertex2d(x + 2, y - 1);
            GL11.glVertex2d(x + 5, y - 1);
            GL11.glVertex2d(x + 3, y);
            GL11.glVertex2d(x + 4, y);
            x += 7;
        } else if (c == 'w') {
            for (int i = 1; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            GL11.glVertex2d(x + 2, y);
            GL11.glVertex2d(x + 3, y);
            GL11.glVertex2d(x + 5, y);
            GL11.glVertex2d(x + 6, y);
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + 4, y - i);
            }
            x += 8;
        } else if (c == 'x') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + i, y - i);
            }
            for (int i = 7; i >= 1; i--) {
                GL11.glVertex2d(x + i, y - 8 + i);
            }
            x += 8;
        } else if (c == 'y') {
            GL11.glVertex2d(x + 4, y);
            GL11.glVertex2d(x + 4, y - 1);
            GL11.glVertex2d(x + 4, y - 2);
            GL11.glVertex2d(x + 4, y - 3);
            GL11.glVertex2d(x + 4, y - 4);

            GL11.glVertex2d(x + 3, y - 5);
            GL11.glVertex2d(x + 2, y - 6);
            GL11.glVertex2d(x + 1, y - 7);
            GL11.glVertex2d(x + 1, y - 8);

            GL11.glVertex2d(x + 5, y - 5);
            GL11.glVertex2d(x + 6, y - 6);
            GL11.glVertex2d(x + 7, y - 7);
            GL11.glVertex2d(x + 7, y - 8);
            x += 8;
        } else if (c == 'z') {
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + i, y);
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - i);
            }
            GL11.glVertex2d(x + 6, y - 7);
            x += 8;
        } else if (c == '1') {
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y);
            }
            for (int i = 1; i <= 8; i++) {
                GL11.glVertex2d(x + 4, y - i);
            }
            GL11.glVertex2d(x + 3, y - 7);
            x += 8;
        } else if (c == '2') {
            for (int i = 1; i <= 6; i++) {
                GL11.glVertex2d(x + i, y);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 1, y - 7);
            GL11.glVertex2d(x + 1, y - 6);

            GL11.glVertex2d(x + 6, y - 7);
            GL11.glVertex2d(x + 6, y - 6);
            GL11.glVertex2d(x + 6, y - 5);
            GL11.glVertex2d(x + 5, y - 4);
            GL11.glVertex2d(x + 4, y - 3);
            GL11.glVertex2d(x + 3, y - 2);
            GL11.glVertex2d(x + 2, y - 1);
            x += 8;
        } else if (c == '3') {
            for (int i = 1; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y);
            }
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 6, y - i);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 4);
            }
            x += 8;
        } else if (c == '4') {
            for (int i = 2; i <= 8; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 7; i++) {
                GL11.glVertex2d(x + i, y - 1);
            }
            for (int i = 0; i <= 4; i++) {
                GL11.glVertex2d(x + 4, y - i);
            }
            x += 8;
        } else if (c == '5') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + i, y - 8);
            }
            for (int i = 4; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            GL11.glVertex2d(x + 1, y - 1);
            GL11.glVertex2d(x + 2, y);
            GL11.glVertex2d(x + 3, y);
            GL11.glVertex2d(x + 4, y);
            GL11.glVertex2d(x + 5, y);
            GL11.glVertex2d(x + 6, y);

            GL11.glVertex2d(x + 7, y - 1);
            GL11.glVertex2d(x + 7, y - 2);
            GL11.glVertex2d(x + 7, y - 3);

            GL11.glVertex2d(x + 6, y - 4);
            GL11.glVertex2d(x + 5, y - 4);
            GL11.glVertex2d(x + 4, y - 4);
            GL11.glVertex2d(x + 3, y - 4);
            GL11.glVertex2d(x + 2, y - 4);
            x += 8;
        } else if (c == '6') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y);
            }
            for (int i = 2; i <= 5; i++) {
                GL11.glVertex2d(x + i, y - 4);
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 7, y - 1);
            GL11.glVertex2d(x + 7, y - 2);
            GL11.glVertex2d(x + 7, y - 3);
            GL11.glVertex2d(x + 6, y - 4);
            x += 8;
        } else if (c == '7') {
            for (int i = 0; i <= 7; i++) {
                GL11.glVertex2d(x + i, y - 8);
            }
            GL11.glVertex2d(x + 7, y - 7);
            GL11.glVertex2d(x + 7, y - 6);

            GL11.glVertex2d(x + 6, y - 5);
            GL11.glVertex2d(x + 5, y - 4);
            GL11.glVertex2d(x + 4, y - 3);
            GL11.glVertex2d(x + 3, y - 2);
            GL11.glVertex2d(x + 2, y - 1);
            GL11.glVertex2d(x + 1, y);
            x += 8;
        } else if (c == '8') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
                GL11.glVertex2d(x + 7, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - 0);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 4);
            }
            x += 8;
        } else if (c == '9') {
            for (int i = 1; i <= 7; i++) {
                GL11.glVertex2d(x + 7, y - i);
            }
            for (int i = 5; i <= 7; i++) {
                GL11.glVertex2d(x + 1, y - i);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 8);
                GL11.glVertex2d(x + i, y - 0);
            }
            for (int i = 2; i <= 6; i++) {
                GL11.glVertex2d(x + i, y - 4);
            }
            GL11.glVertex2d(x + 1, y - 0);
            x += 8;
        } else if (c == '.') {
            GL11.glVertex2d(x + 1, y);
            x += 2;
        } else if (c == ',') {
            GL11.glVertex2d(x + 1, y);
            GL11.glVertex2d(x + 1, y - 1);
            x += 2;
        } else if (c == '\n') {
            y -= 10;
            x = startX;
        } else if (c == ' ') {
            x += 8;
        }
    }
    GL11.glEnd();
}

From source file:fr.theshark34.sharkengine.ui.components.Button.java

License:Apache License

/**
 * Draw the button//from  w ww  .j a v  a 2 s . com
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Check if the mouse is on the button
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + this.width
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height) {

        // Changing button color to colorHover
        GL11.glColor4f((float) colorHover.getRed() / 255, (float) colorHover.getGreen() / 255,
                (float) colorHover.getBlue() / 255, (float) colorHover.getAlpha() / 255);

        // If the mouse clicked and clicked is false, executing action
        // and setting clicked to true, then the action will not be
        // repeated
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                action.buttonClicked();
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;
    } else
        // Else, setting the color to the base color
        GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255,
                (float) color.getBlue() / 255, (float) color.getAlpha() / 255);

    // Drawing the button base (a rectangle)
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Drawing the text
    this.font.drawString(x + (this.width - this.font.getWidth(text)) / 2,
            y + (this.height - this.font.getHeight(text)) / 2, text);

    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.Checkbox.java

License:Apache License

/**
 * Draw the checkbox/*  w  w w . j av  a2 s .c o  m*/
 */
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Picking white color
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    // Drawing the checkbox
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Drawing the text
    this.font.drawString(x + 25, y + (this.height - this.font.getHeight(text)) / 2, text);

    // Being sure that texturing is enabled
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // If the mouse is on the checkbox
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + this.width
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height)
        // If the mouse clicked and clicked is false, setting coched
        // to its oposite and setting clicked to true, so it will do
        // it one time
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                coched = !coched;
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;

    // Checking if the checkbox is coched
    if (coched) {
        // Drawing coched checkbox texture
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, cochedcb.getTextureID());

        // Drawing the image
        GL11.glBegin(GL11.GL_QUADS);
        {
            GL11.glTexCoord2f(0.0f, 0.0f);
            GL11.glVertex2f(x, y);
            GL11.glTexCoord2f(1.0f, 0.0f);
            GL11.glVertex2f(x + width, y);
            GL11.glTexCoord2f(1.0f, 1.0f);
            GL11.glVertex2f(x + width, y + height);
            GL11.glTexCoord2f(0.0f, 1.0f);
            GL11.glVertex2f(x, y + height);
        }
        GL11.glEnd();
    }

    // Disabling texture
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.HorizontalSlider.java

License:Apache License

/**
 * Draw the slider/*from  w  w  w  .j a  v  a2  s .c om*/
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Check if the mouse is on the slider
    if (Mouse.getX() > this.x + this.sliderX && Mouse.getX() < this.x + this.sliderX + this.sliderWidth
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height) {
        // If the mouse clicked and clicked is false, settings clicked to
        // true and saving mouse initial click
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                mouseClick = Mouse.getX();
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;
    }
    // Setting clicked to false only when the mouse stop clicking
    else if (!Mouse.isButtonDown(0))
        clicked = false;

    // If mouse clicked
    if (clicked) {
        // If slider isn't on the minimum / maximum
        if (sliderX >= 0 && sliderX + sliderWidth <= width)
            if (sliderX + Mouse.getX() - mouseClick >= 0)
                if (sliderX + sliderWidth + Mouse.getX() - mouseClick <= width) {
                    sliderX += Mouse.getX() - mouseClick;
                    mouseClick = Mouse.getX();
                } else
                    sliderX = width - sliderWidth;
            else
                sliderX = 0;
    }

    // Picking the background color
    GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255, (float) color.getBlue() / 255,
            (float) color.getAlpha() / 255);

    // Drawing the slider background
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Picking the slider color
    GL11.glColor4f((float) sliderColor.getRed() / 255, (float) sliderColor.getGreen() / 255,
            (float) sliderColor.getBlue() / 255, (float) sliderColor.getAlpha() / 255);

    // Drawing the slider
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x + sliderX, y);
        GL11.glVertex2f(x + sliderX + sliderWidth, y);
        GL11.glVertex2f(x + sliderX + sliderWidth, y + height);
        GL11.glVertex2f(x + sliderX, y + height);
    }
    GL11.glEnd();
}

From source file:fr.theshark34.sharkengine.ui.components.Image.java

License:Apache License

/**
 * Draw it/*w w  w . ja v a  2s. c om*/
 */
@Override
public void draw() {
    // Without this, image can render strangely
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    // Enabling blend and texture
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());

    // Drawing the image
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glTexCoord2f(0.0f, 0.0f);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(1.0f, 0.0f);
        GL11.glVertex2f(x + width, y);
        GL11.glTexCoord2f(1.0f, 1.0f);
        GL11.glVertex2f(x + width, y + height);
        GL11.glTexCoord2f(0.0f, 1.0f);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Disabling blend and texture
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}

From source file:fr.theshark34.sharkengine.ui.components.ProgressBar.java

License:Apache License

/**
 * Draw the bar//www.  ja  va  2  s.  c  o m
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texture is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Picking the base color
    GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255, (float) color.getBlue() / 255,
            (float) color.getAlpha() / 255);

    // Drawing the base
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    if (value != 0 && maximum != 0) {
        // Picking the foreground color
        GL11.glColor4f((float) fgColor.getRed() / 255, (float) fgColor.getGreen() / 255,
                (float) fgColor.getBlue() / 255, (float) fgColor.getAlpha() / 255);

        int fgWidth = (int) (width / ((float) maximum / (float) value));

        // Drawing the foreground
        GL11.glBegin(GL11.GL_QUADS);
        {
            GL11.glVertex2f(x, y);
            GL11.glVertex2f(x + fgWidth, y);
            GL11.glVertex2f(x + fgWidth, y + height);
            GL11.glVertex2f(x, y + height);
        }
        GL11.glEnd();
    }

    // Drawing the text
    this.font.drawString(x + (this.width - this.font.getWidth(string)) / 2,
            y + (this.height - this.font.getHeight(string)) / 2, string);

    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.VerticalSlider.java

License:Apache License

/**
 * Draw the slider/*from ww w .  j av  a2s  .com*/
 */
@Override
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Check if the mouse is on the slider
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + width
            && Mouse.getY() < Display.getHeight() - this.y + this.sliderY
            && Mouse.getY() > Display.getHeight() - this.y - this.sliderY - this.sliderHeight) {
        // If the mouse clicked and clicked is false, settings clicked to
        // true and saving mouse initial click
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                mouseClick = Display.getHeight() - Mouse.getY();
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;
    }
    // Setting clicked to false only when the mouse stop clicking
    else if (!Mouse.isButtonDown(0))
        clicked = false;

    // If mouse clicked
    if (clicked) {

        // If slider isn't on the minimum / maximum
        if (sliderY >= 0 && sliderY + sliderHeight <= height)
            if (sliderY + Display.getHeight() - Mouse.getY() - mouseClick >= 0)
                if (sliderY + sliderHeight + Display.getHeight() - Mouse.getY() - mouseClick <= height) {
                    sliderY += Display.getHeight() - Mouse.getY() - mouseClick;
                    mouseClick = Display.getHeight() - Mouse.getY();
                } else
                    sliderY = height - sliderHeight;
            else
                sliderY = 0;
    }
    // Picking the background color
    GL11.glColor4f((float) color.getRed() / 255, (float) color.getGreen() / 255, (float) color.getBlue() / 255,
            (float) color.getAlpha() / 255);

    // Drawing the slider background
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Picking the slider color
    GL11.glColor4f((float) sliderColor.getRed() / 255, (float) sliderColor.getGreen() / 255,
            (float) sliderColor.getBlue() / 255, (float) sliderColor.getAlpha() / 255);

    // Drawing the slider
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y + sliderY);
        GL11.glVertex2f(x + width, y + sliderY);
        GL11.glVertex2f(x + width, y + sliderY + sliderHeight);
        GL11.glVertex2f(x, y + sliderY + sliderHeight);
    }
    GL11.glEnd();
}

From source file:fractal.PolygonFractal.java

public void next(int depth, double angle) {
    GL11.glRotatef((float) angle, 0, 0, 1);

    float sector = 2f * (float) Math.PI / (float) num_verts;

    /*GL11.glColor3f((float)Math.sin(color_basis) / 2f + 0.5f, 
               (float)Math.sin(color_basis + Math.PI / 1.5) / 2f + 0.5f,
               (float)Math.sin(color_basis + Math.PI / 0.75) / 2f + 0.5f);*/
    GL11.glBegin(GL11.GL_LINE_STRIP);/*from  w  ww .  j  a  v  a  2  s.  co m*/
    for (int i = 0; i <= num_verts; i++) {
        float a = sector * i;
        GL11.glVertex2f((float) Math.cos(a), (float) Math.sin(a));
    }
    GL11.glEnd();

    if (depth > 0) {
        for (int i = 0; i < num_verts; i++) {
            GL11.glRotatef(sector * 180f / (float) Math.PI, 0, 0, 1);
            GL11.glPushMatrix();
            GL11.glTranslatef(1, 0, 0);
            GL11.glScalef(mult, mult, mult);

            next(depth - 1, angle * ang_mult);
            GL11.glPopMatrix();
        }
    }
}

From source file:game.core.blockmap.BlockMapBehavior.java

License:Open Source License

@Override
public void draw(GameObject target) {
    if (textureProvider == null) {
        return;/*w w  w  .  j a v a  2s  .  co  m*/
    }
    int w = Math.min(width, 100);
    int h = Math.min(height, 30);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glColor3ub((byte) 255, (byte) 255, (byte) 255);
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            Texture texture = textureProvider.getBlockTexture(getBlock(x, y));
            if (texture == null) {
                continue;
            }
            texture.glBindTexture();
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(0.0f, 1.0f);
            GL11.glVertex2i(x, y);
            GL11.glTexCoord2f(1.0f, 1.0f);
            GL11.glVertex2i(x + 1, y);
            GL11.glTexCoord2f(1.0f, 0.0f);
            GL11.glVertex2i(x + 1, y + 1);
            GL11.glTexCoord2f(0.0f, 0.0f);
            GL11.glVertex2i(x, y + 1);
            GL11.glEnd();
        }
    }
}