Example usage for org.lwjgl.opengl GL11 glVertex2d

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

Introduction

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

Prototype

public static native void glVertex2d(@NativeType("GLdouble") double x, @NativeType("GLdouble") double y);

Source Link

Document

Double version of #glVertex2f Vertex2f .

Usage

From source file:com.lukke100.sbdi.Draw.java

License:Open Source License

static public void drawHollowRectangle(double xCoord, double yCoord, double width, double height) {
    GL11.glColor3d(red, green, blue);//from  ww  w  . j  a va 2  s.c o m
    width--;
    height--;
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2d(xCoord, yCoord);
    GL11.glVertex2d(xCoord + width, yCoord);
    GL11.glVertex2d(xCoord + width, yCoord + height);
    GL11.glVertex2d(xCoord, yCoord + height);
    GL11.glEnd();
}

From source file:com.lukke100.sbdi.Draw.java

License:Open Source License

static public void drawHollowSquare(double xCoord, double yCoord, double size) {
    GL11.glColor3d(red, green, blue);// w  ww.ja  v  a2 s  .com
    size--;
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2d(xCoord, yCoord);
    GL11.glVertex2d(xCoord + size, yCoord);
    GL11.glVertex2d(xCoord + size, yCoord + size);
    GL11.glVertex2d(xCoord, yCoord + size);
    GL11.glEnd();
}

From source file:com.lukke100.sbdi.Draw.java

License:Open Source License

static public void drawRectangle(double xCoord, double yCoord, double width, double height) {
    GL11.glColor3d(red, green, blue);/*from w ww  . j  a v a 2  s.co  m*/
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2d(xCoord, yCoord);
    GL11.glVertex2d(xCoord + width, yCoord);
    GL11.glVertex2d(xCoord + width, yCoord + height);
    GL11.glVertex2d(xCoord, yCoord + height);
    GL11.glEnd();
}

From source file:com.lukke100.sbdi.Draw.java

License:Open Source License

static public void drawSquare(double xCoord, double yCoord, double size) {
    GL11.glColor3d(red, green, blue);//from  ww  w .j a  v a  2 s.com
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2d(xCoord, yCoord);
    GL11.glVertex2d(xCoord + size, yCoord);
    GL11.glVertex2d(xCoord + size, yCoord + size);
    GL11.glVertex2d(xCoord, yCoord + size);
    GL11.glEnd();
}

From source file:com.teambrmodding.luxetumbra.client.gui.GuiToggleMenu.java

License:Creative Commons License

@Override
public void drawScreen(int mx, int my, float partialTicks) {
    super.drawScreen(mx, my, partialTicks);

    GlStateManager.pushMatrix();//from   w  w  w .j a  v  a 2 s .com
    GlStateManager.disableTexture2D();

    final int x = width / 2;
    final int y = height / 2;
    final int maxRadius = 60;

    final boolean mouseIn = true;
    final float angle = mouseAngle(x, y, mx, my);
    final float distance = mouseDistance(x, y, mx, my);

    final int highlight = 5;

    GlStateManager.enableBlend();
    GlStateManager.shadeModel(GL11.GL_SMOOTH);
    final int segments = 2; //TODO
    float totalDeg = 0F;
    final float degPer = 360F / segments;

    final List<int[]> stringPosition = new ArrayList<>();

    boolean wasSelected = false;

    for (int seg = 0; seg <= segments; seg++) {
        boolean mouseOverSection = distance <= maxRadius
                && (mouseIn && angle > totalDeg && angle < totalDeg + degPer);
        float radius = Math.max(0F, Math.min(timeIn * 10F, maxRadius));

        GL11.glBegin(GL11.GL_TRIANGLE_FAN);
        float gs = 0.25F;
        if (seg % 2 == 0)
            gs += 0.1F;
        float r = 200; //TODO
        float g = 200; //TODO
        float b = gs;
        float a = 0.4F;
        if (mouseOverSection) {
            selected = seg;
            wasSelected = true;
            r = 255; //TODO
            g = 255; //TODO
            a = 0.5F;
        }
        GlStateManager.color(r, g, b, a);
        GL11.glVertex2i(x, y);
        float i = degPer;
        while (i >= 0) {
            double rad = ((i + totalDeg) / 180F * Math.PI);
            double xp = x + Math.cos(rad) * radius;
            double yp = y + Math.sin(rad) * radius;
            if (i == (int) (degPer / 2))
                stringPosition.add(new int[] { seg, (int) xp, (int) yp, mouseOverSection ? 'n' : 'r' });
            GL11.glVertex2d(xp, yp);
            i -= 1;
        }
        totalDeg += degPer;

        GL11.glVertex2i(x, y);
        GL11.glEnd();

        if (mouseOverSection)
            radius -= highlight;
    }

    if (!wasSelected)
        selected = -1;

    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.enableTexture2D();

    for (int[] pos : stringPosition) {
        int slot = pos[0];
        float xp = pos[1];
        float yp = pos[2];
        char c = (char) pos[3];

        ItemStack displayStack = new ItemStack(Items.APPLE);
        if (displayStack != null) {
            float xsp = xp - 4;
            float ysp = yp;
            String name = "\u00a7" + c + "testing";
            int width = fontRendererObj.getStringWidth(name);

            float mod = 0.6F;
            int xdp = (int) ((xp - x) * mod + x);
            int ydp = (int) ((yp - y) * mod + y);

            RenderHelper.enableGUIStandardItemLighting();
            GlStateManager.pushMatrix();
            GlStateManager.translate(xdp - 10, ydp - 10, 2);
            GlStateManager.scale(1.25, 1.25, 1.25);
            Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(displayStack, 0, 0);
            GlStateManager.popMatrix();
            RenderHelper.disableStandardItemLighting();

            if (xsp < x)
                xsp -= width - 8;
            if (ysp < y)
                ysp -= 9;

            fontRendererObj.drawStringWithShadow(name, xsp, ysp, 0xFFFFFF);
        }
    }

    GlStateManager.popMatrix();
}

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

License:Open Source License

/**
 * Render simple line.//from   w  ww. j a va 2 s  .c  om
 * @param primitive primitive to paint
 */
private void renderLine(final ParameterizedPolyline line) {
    if (line.getPointCount() < 2) {
        logger.warn("Line has " + line.getPointCount() + " points and cannot be rendered");
        return;
    }
    this.texture.initializeRendering();
    this.texture.setRange(0., 0, line.getParameter(line.getPointCount() - 1), 1);
    //    System.err.println("set range to " + this.texture.getMinX() + "x" + this.texture.getMinY() + " - " + this.texture.getMaxX() + "x"
    //        + this.texture.getMaxY());
    /**
     * p1 is the nth point, n1 the segment normal at p1 point 
     * p2 is the (n+1)th point, n2 the segment normal at p2 point
     * 
     * pXa, pXb are the 
     */
    Point2d p1 = line.getPoint(0); // nth point
    double p1t = line.getParameter(0);
    Point2d p2 = line.getPoint(1); // n+1 th point
    double p2t = line.getParameter(1);
    Point2d p3 = null; // n+2 th point
    Vector2d v1 = MathUtil.vector(p1, p2); // line direction at p1
    Vector2d v2 = null; // line direction at p2 
    Vector2d n1 = MathUtil.computeNormal(v1); // line normal at p1 (perpendicular to segment direction)
    Vector2d n2 = null; // line normal at p2 (perpendicular to segment direction)
    Point2d p1a = MathUtil.pointOfLine(p1, n1, -this.getLineWidth() / 2); // first stretched point at p1 (p1 + lineWidth/2 * n1)
    Point2d p1b = MathUtil.pointOfLine(p1, n1, this.getLineWidth() / 2); // second stretched point at p1 (p1 - lineWidth/2 * n1)
    Point2d p2a = null; // first stretched point at p2 (p2 + lineWidth/2 * n2)
    Point2d p2b = null; // second stretched point at p2 (p2 - lineWidth/2 * n2)

    if (line.getPointCount() <= 2) {
        p3 = p2;
        n2 = n1;
    }

    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GL11.glBegin(GL11.GL_QUAD_STRIP);
    try {
        GL11.glTexCoord2d(p1t, 0);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p1t, 0));
        GL11.glVertex2d(p1a.x, p1a.y);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p1t, 1));
        GL11.glVertex2d(p1b.x, p1b.y);
        //      System.err.println("set first point coordinates = " + p1t + "x" + "0" + " => " + this.texture.vertexCoordinates(p1t, 0));
        //      System.err.println("set first point coordinates = " + p1t + "x" + "1" + " => " + this.texture.vertexCoordinates(p1t, 1));

        for (int nPoint = 0; nPoint < line.getPointCount() - 2; nPoint++) {

            p3 = line.getPoint(nPoint + 2);
            v2 = MathUtil.vector(p2, p3);
            n2 = MathUtil.computeNormal(v2);
            p2a = MathUtil.pointOfLine(p2, n2, -this.getLineWidth() / 2);
            p2b = MathUtil.pointOfLine(p2, n2, this.getLineWidth() / 2);
            p2t = line.getParameter(nPoint);

            Point2d Ia = MathUtil.intersectionPoint(p1a, v1, p2a, v2);
            Point2d Ib = MathUtil.intersectionPoint(p1b, v1, p2b, v2);
            if (Ia == null || Ib == null) {
                Ia = MathUtil.mean(p1a, p2a);
                Ib = MathUtil.mean(p1b, p2b);
            }

            GLTools.glTexCoord(this.texture.vertexCoordinates(p2t, 0));
            GL11.glVertex2d(Ia.x, Ia.y);
            GLTools.glTexCoord(this.texture.vertexCoordinates(p2t, 1));
            GL11.glVertex2d(Ib.x, Ib.y);

            //        System.err.println("set #" + nPoint + " point coordinates = " + p2t + "x" + "0" + " => " + this.texture.vertexCoordinates(p2t, 0));
            //        System.err.println("set #" + nPoint + " point coordinates = " + p2t + "x" + "1" + " => " + this.texture.vertexCoordinates(p2t, 1));
            // shift context to the next point
            p1 = p2;
            p1t = p2t;
            n1 = n2;
            v1 = v2;
            p1a = Ia;
            p1b = Ib;
            p2 = p3;

        }
        // draw the last point
        Point2d p3a = MathUtil.pointOfLine(p3, n2, -this.getLineWidth() / 2);
        Point2d p3b = MathUtil.pointOfLine(p3, n2, this.getLineWidth() / 2);
        double p3t = line.getParameter(line.getPointCount() - 1);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p3t, 0));
        GL11.glVertex2d(p3a.x, p3a.y);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p3t, 1));
        GL11.glVertex2d(p3b.x, p3b.y);
        //      System.err.println("set last point coordinates = " + p3t + "x" + "0" + " => " + this.texture.vertexCoordinates(p3t, 0));
        //      System.err.println("set last point coordinates = " + p3t + "x" + "1" + " => " + this.texture.vertexCoordinates(p3t, 1));
    } finally {
        GL11.glEnd();
    }

    this.texture.initializeRendering();

}

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

License:Open Source License

/**
 * Render simple line./*from   w  w  w .  j a v  a 2  s  . c om*/
 * @param primitive primitive to paint
 */
private void renderLineDebug(final ParameterizedPolyline line) {
    if (line.getPointCount() < 2) {
        logger.warn("Line has " + line.getPointCount() + " points and cannot be rendered");
        return;
    }
    final double epsilon = 1E-1;
    /**
     * p1 is the nth point, n1 the segment normal at p1 point 
     * p2 is the (n+1)th point, n2 the segment normal at p2 point
     * 
     * pXa, pXb are the 
     */
    Point2d p1 = line.getPoint(0); // nth point
    Point2d p2 = line.getPoint(1); // n+1 th point
    Point2d p3 = null; // n+2 th point
    Vector2d v1 = MathUtil.vector(p1, p2); // line direction at p1
    Vector2d v2 = null; // line direction at p2 
    Vector2d n1 = MathUtil.computeNormal(v1); // line normal at p1 (perpendicular to segment direction)
    Vector2d n2 = null; // line normal at p2 (perpendicular to segment direction)
    Point2d p1a = MathUtil.pointOfLine(p1, n1, -this.getLineWidth() / 2); // first stretched point at p1 (p1 + lineWidth/2 * n1)
    Point2d p1b = MathUtil.pointOfLine(p1, n1, this.getLineWidth() / 2); // second stretched point at p1 (p1 - lineWidth/2 * n1)
    Point2d p2a = null; // first stretched point at p2 (p2 + lineWidth/2 * n2)
    Point2d p2b = null; // second stretched point at p2 (p2 - lineWidth/2 * n2)

    if (line.getPointCount() <= 2) {
        p3 = p2;
        n2 = n1;
    }

    double s = 1;
    GL11.glLineWidth(2.f);
    GL11.glBegin(GL11.GL_LINES);
    // first point
    GL11.glColor3d(1, 0, 0);
    GL11.glVertex2d(p1a.x, p1a.y);
    GL11.glVertex2d(p1b.x, p1b.y);
    try {

        for (int nPoint = 0; nPoint < line.getPointCount() - 2; nPoint++) {

            p3 = line.getPoint(nPoint + 2);
            v2 = MathUtil.vector(p2, p3);
            n2 = MathUtil.computeNormal(v2);
            p2a = MathUtil.pointOfLine(p2, n2, -this.getLineWidth() / 2);
            p2b = MathUtil.pointOfLine(p2, n2, this.getLineWidth() / 2);

            GL11.glColor3d(.5, .5, .5);
            GL11.glVertex2d(p1a.x, p1a.y);
            GL11.glVertex2d(p1b.x, p1b.y);

            /*        GL11.glColor3d(.5, .5, .5);
                    GL11.glVertex2d(p1.x, p1.y);
                    GL11.glVertex2d(p1.x + s * v1.x, p1.y + s * v1.y);
                    
                    GL11.glColor3d(.5, .5, .5);
                    GL11.glVertex2d(p1.x, p1.y);
                    GL11.glVertex2d(p1.x + s * n1.x, p1.y + s * n1.y);
            */
            Point2d Ia = MathUtil.intersectionPoint(p1a, v1, p2a, v2, epsilon);
            Point2d Ib = MathUtil.intersectionPoint(p1b, v1, p2b, v2, epsilon);

            // debug
            if (first && Ia != null && Ib != null && MathUtil.norm(MathUtil.vector(Ia, Ib)) > 100) {
                first = false;
                JDialog dialog = new JDialog();
                GraphPanel graphPanel = new GraphPanel();
                dialog.getContentPane().add(graphPanel);
                dialog.pack();
                dialog.setVisible(true);

                graphPanel.addPoint("p1", p1);
                graphPanel.addPoint("p2", p2);
                graphPanel.addPoint("p3", p3);

                //          graphPanel.addVector("n1", p1, n1);
                //          graphPanel.addVector("n2", p2, n2);
                graphPanel.addVector("v1", p1, v1);
                graphPanel.addVector("v2", p1, v2);
                graphPanel.addVector(".", p1a, v1);
                graphPanel.addVector(",", p1b, v1);
                graphPanel.addVector("`", p2a, v2);
                graphPanel.addVector("'", p2b, v2);
                graphPanel.addPoint("p1a", p1a);
                graphPanel.addPoint("p1b", p1b);
                graphPanel.addPoint("p2a", p2a);
                graphPanel.addPoint("p2b", p2b);

                System.out.println("v1.v2 = " + MathUtil.cross(v1, v2));
                //          graphPanel.addPoint("Ia", Ia);
                //          graphPanel.addPoint("Ib", Ib);

                System.out.println(nPoint + " on " + line.getPointCount() + " =>");
                System.out.println(" p1   = " + p1);
                System.out.println(" p2   = " + p2);
                System.out.println(" p3   = " + p3);
                System.out.println(" n1   = " + n1);
                System.out.println(" n2   = " + n2);
                System.out.println(" v1   = " + v1);
                System.out.println(" v2   = " + v2);
                System.out.println(" p1a  = " + p1a);
                System.out.println(" p1b  = " + p1b);
                System.out.println(" p2a  = " + p2a);
                System.out.println(" p2b  = " + p2b);
                System.out.println(" Ia   = " + Ia);
                System.out.println(" Ib   = " + Ib);
                p3 = line.getPoint(nPoint + 2);
                v2 = MathUtil.vector(p2, p3);
                n2 = MathUtil.computeNormal(v2);
                p2a = MathUtil.pointOfLine(p2, n2, -this.getLineWidth() / 2);
                p2b = MathUtil.pointOfLine(p2, n2, this.getLineWidth() / 2);
                Ia = MathUtil.intersectionPoint(p1a, v1, p2a, v2, epsilon);
                Ib = MathUtil.intersectionPoint(p1b, v1, p2b, v2, epsilon);

            }
            if (Ia == null || Ib == null) {
                Ia = MathUtil.mean(p1a, p2a);
                Ib = MathUtil.mean(p1b, p2b);
            }
            // if no intersection, use p2a & p2b
            if (Ia == null) {
                GL11.glColor3d(.5, .5, .5);
                GL11.glVertex2d(p2a.x, p2b.y);
            } else {
                GL11.glColor3d(0, 0, 1);
                GL11.glVertex2d(Ia.x, Ia.y);
            }
            if (Ib == null) {
                GL11.glColor3d(.5, .5, .5);
                GL11.glVertex2d(p2b.x, p2b.y);
            } else {
                GL11.glColor3d(0, 1, 0);
                GL11.glVertex2d(Ib.x, Ib.y);
            }
            // shift context to the next point
            p1 = p2;
            n1 = n2;
            v1 = v2;
            p1a = p2a;
            p1b = p2b;
            p2 = p3;

        }
        if (p3 == null || n2 == null) {
            System.err.println("p3 = " + p3 + " n2 = " + n2 + " nbpt = " + line.getPointCount());
        }
        // draw the last point
        Point2d p3a = MathUtil.pointOfLine(p3, n2, -this.getLineWidth() / 2);
        Point2d p3b = MathUtil.pointOfLine(p3, n2, this.getLineWidth() / 2);
        GL11.glColor3d(1, 1, 0);
        GL11.glVertex2d(p3a.x, p3a.y);
        GL11.glVertex2d(p3b.x, p3b.y);
    } finally {
        GL11.glEnd();
    }
}

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

License:Open Source License

/**
 * set gl vertex coordinate from a Point2D point
 */
public static void glVertex(final Point2d p) {
    GL11.glVertex2d(p.x, p.y);
}

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  w ww. 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:graphics.Graph.java

@Override
public void draw() {
    //if (this.changed) {
    setMinMax();/*from ww  w  . j  a va  2  s  . co  m*/
    float margin = 20;
    // White backdrop...
    GL11.glColor3f(1, 1, 1);
    GL11.glBegin(GL11.GL_POLYGON);
    GL11.glVertex2f(this.xPos, this.yPos);
    GL11.glVertex2f(this.xPos + this.sizeX, this.yPos);
    GL11.glVertex2f(this.xPos + this.sizeX, this.yPos + this.sizeY);
    GL11.glVertex2f(this.xPos, this.yPos + this.sizeY);
    GL11.glEnd();

    // Black lines around...
    GL11.glColor3f(0, 0, 0);
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2f(this.xPos, this.yPos);
    GL11.glVertex2f(this.xPos + this.sizeX, this.yPos);
    GL11.glVertex2f(this.xPos + this.sizeX, this.yPos + this.sizeY);
    GL11.glVertex2f(this.xPos, this.yPos + this.sizeY);
    GL11.glEnd();

    // Moves origo where it should be, based on the dataset...
    GL11.glColor4f(0, 0, 0, 0.25f);
    float origo = this.yPos + 2 * margin;
    if (maxValue == 0 && minValue == 0) {
        origo += (this.sizeY - 3 * margin) / 2;
    } else if (maxValue <= 0 && minValue < 0) {
        origo += this.sizeY - 3 * margin;
    } else if (maxValue > 0 && minValue < 0) {
        origo += ((minValue * -1) / (maxValue + (minValue * -1))) * (this.sizeY - 3 * margin);
    }
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2f(this.xPos + margin, origo);
    GL11.glVertex2f(this.xPos + this.sizeX - margin, origo);
    GL11.glEnd();

    // draws tabs on the origo-line where the values should be put...
    float tabs = 5;
    for (int i = 0; i < dataValues.length; i++) {
        GL11.glBegin(GL11.GL_LINES);
        GL11.glVertex2f(this.xPos + margin + (i * (this.sizeX - 2 * margin) / (this.dataValues.length - 1)),
                origo + tabs);
        GL11.glVertex2f(this.xPos + margin + (i * (this.sizeX - 2 * margin) / (this.dataValues.length - 1)),
                origo - tabs);
        GL11.glEnd();
    }
    Line2D.Double[] lines = new Line2D.Double[dataValues.length - 1];
    for (int i = 0; i < lines.length; i++) {
        if (dataValues[i] == null) {
            continue;
        }
        float x = this.xPos + margin + (i * (this.sizeX - 2 * margin) / (this.dataValues.length - 1));
        float y = (this.yPos + 2 * margin) + ((this.sizeY - 3 * margin)
                * ((this.dataValues[i].getValue() + Math.abs(minValue)) / (maxValue + Math.abs(minValue))));
        float x2 = this.xPos + margin + ((i + 1) * (this.sizeX - 2 * margin) / (this.dataValues.length - 1));
        float y2 = (this.yPos + 2 * margin) + ((this.sizeY - 3 * margin)
                * ((this.dataValues[i + 1].getValue() + Math.abs(minValue)) / (maxValue + Math.abs(minValue))));
        lines[i] = new Line2D.Double(x, y, x2, y2);
    }

    // Draws the value-lines on the graph...
    Line2D.Double origLine = new Line2D.Double(this.xPos + margin, origo,
            this.xPos + margin + (this.sizeX - 2 * margin), origo);
    GL11.glLineWidth(2);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glBegin(GL11.GL_LINE_STRIP);
    for (Line2D.Double line : lines) {
        if (line == null) {
            continue;
        }
        if (line.intersectsLine(origLine)) {
            Point2D interSect = getIntersection(line, origLine);
            if (line.y1 > origo) {
                GL11.glColor4f(0, 1, 0, 1);
                GL11.glVertex2d(line.x1, line.y1);
                GL11.glVertex2d(interSect.getX(), interSect.getY());
                GL11.glColor4f(1, 0, 0, 1);
                GL11.glVertex2d(line.x2, line.y2);
            } else {
                GL11.glColor4f(1, 0, 0, 1);
                GL11.glVertex2d(line.x1, line.y1);
                GL11.glVertex2d(interSect.getX(), interSect.getY());
                GL11.glColor4f(0, 1, 0, 1);
                GL11.glVertex2d(line.x2, line.y2);
            }
        } else {
            if (line.y1 > origo) {
                GL11.glColor4f(0, 1, 0, 1);
                GL11.glVertex2d(line.x1, line.y1);
                GL11.glVertex2d(line.x2, line.y2);
            } else {
                GL11.glColor4f(1, 0, 0, 1);
                GL11.glVertex2d(line.x1, line.y1);
                GL11.glVertex2d(line.x2, line.y2);
            }
        }
    }
    GL11.glEnd();
    GL11.glLineWidth(1);
    GL11.glShadeModel(GL11.GL_SMOOTH);

    // Black lines around box inside the graph...
    GL11.glColor4f(0, 0, 0, 1);
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2f(this.xPos + margin, this.yPos + 2 * margin);
    GL11.glVertex2f(this.xPos + this.sizeX - margin, this.yPos + 2 * margin);
    GL11.glVertex2f(this.xPos + this.sizeX - margin, this.yPos + this.sizeY - margin);
    GL11.glVertex2f(this.xPos + margin, this.yPos + this.sizeY - margin);
    GL11.glEnd();

    //this.changed = false;
    origLine = null;
    //}
}