Example usage for org.lwjgl.opengl GL11 glVertex2f

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

Introduction

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

Prototype

public static native void glVertex2f(@NativeType("GLfloat") float x, @NativeType("GLfloat") float y);

Source Link

Document

Specifies a single vertex between #glBegin Begin and #glEnd End by giving its coordinates in two dimensions.

Usage

From source file:com.samrj.devil.ui.Font.java

License:Open Source License

public void draw(String text, Vec2 pos, Vec2 align) {
    pos = new Vec2(pos.x, pos.y - cellHeight);
    align = new Vec2(align.x - 1.0f, -align.y - 1.0f).mult(0.5f);
    align.x *= getWidth(text);/*from  w  w w.j a va 2 s .  c om*/
    align.y *= -height;
    pos.add(align);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glTranslatef(Math.round(pos.x), Math.round(pos.y), 0.0f);

    float x0 = 0f;
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    tex.bind();
    GL11.glBegin(GL11.GL_QUADS);
    for (int i = 0; i < text.length(); i++) {
        int charbits = text.charAt(i) - 32;
        int fontposx = charbits & 0xF;
        int fontposy = 15 - (charbits >> 4);
        float u0 = fontposx++ / 16f;
        float v0 = fontposy++ / 16f;
        float u1 = fontposx / 16f;
        float v1 = fontposy / 16f;

        float x1 = x0 + cellHeight;

        GL11.glTexCoord2f(u0, v0);
        GL11.glVertex2f(x0, 0f);
        GL11.glTexCoord2f(u0, v1);
        GL11.glVertex2f(x0, cellHeight);
        GL11.glTexCoord2f(u1, v1);
        GL11.glVertex2f(x1, cellHeight);
        GL11.glTexCoord2f(u1, v0);
        GL11.glVertex2f(x1, 0f);

        x0 += getWidth(text.charAt(i));
    }
    GL11.glEnd();
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    GL11.glPopMatrix();
}

From source file:displayexample.Entities.Box2D.java

@Override
public void draw() {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    // set the color of the quad (R,G,B,A)
    GL11.glColor3f(0.5f, 0.5f, 1.0f);/*from w  w w  .  j  a  va  2  s. com*/

    // draw quad
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(x, y);
    GL11.glVertex2f(x + size, y);
    GL11.glVertex2f(x + size, y + size);
    GL11.glVertex2f(x, y + size);
    GL11.glEnd();
}

From source file:dripdisplay.DripDisplayLWJGL.java

private void drawTile(Rectangle bounds, Rectangle2D.Float r) {
    GL11.glBegin(GL11.GL_QUADS);//from  ww  w .  j  a  v a 2s  .  c  o m

    GL11.glTexCoord2f(r.x, r.y + r.height);
    GL11.glVertex2f(bounds.getX(), bounds.getY() + bounds.getHeight());

    GL11.glTexCoord2f(r.x + r.width, r.y + r.height);
    GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight());

    GL11.glTexCoord2f(r.x + r.width, r.y);
    GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY());

    GL11.glTexCoord2f(r.x, r.y);
    GL11.glVertex2f(bounds.getX(), bounds.getY());

    GL11.glEnd();
}

From source file:eu.over9000.veya.gui.TrueTypeFont.java

License:Open Source License

private void drawQuad(final float drawX, final float drawY, final float drawX2, final float drawY2,
        final float srcX, final float srcY, final float srcX2, final float srcY2) {
    final float DrawWidth = drawX2 - drawX;
    final float DrawHeight = drawY2 - drawY;
    final float TextureSrcX = srcX / textureWidth;
    final float TextureSrcY = srcY / textureHeight;
    final float SrcWidth = srcX2 - srcX;
    final float SrcHeight = srcY2 - srcY;
    final float RenderWidth = (SrcWidth / textureWidth);
    final float RenderHeight = (SrcHeight / textureHeight);

    GL11.glTexCoord2f(TextureSrcX, TextureSrcY);
    GL11.glVertex2f(drawX, drawY);
    GL11.glTexCoord2f(TextureSrcX, TextureSrcY + RenderHeight);
    GL11.glVertex2f(drawX, drawY + DrawHeight);
    GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY + RenderHeight);
    GL11.glVertex2f(drawX + DrawWidth, drawY + DrawHeight);
    GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY);
    GL11.glVertex2f(drawX + DrawWidth, drawY);
}

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

License:Open Source License

/**
 * Draw a shape polygon using open GL. It can either fill the polygon or
 * display only//from   ww  w.  ja va2 s. c om
 * the edges. No tesselation is done when filling, so the shape has to be
 * simple and convex
 * 
 * @param shape
 *            Java2D shape to paint
 * @param close
 *            automatically close the polygon between start and end point
 * @param fill
 *            if true fills the polygon with current color. if false, draw
 *            only edges
 */
private static void glDrawRawShape(final Shape shape, final boolean close, final boolean fill) {

    final int glDrawType = fill ? GL11.GL_POLYGON : close ? GL11.GL_LINE_LOOP : GL_LINE_STRIP;
    //    final int glDrawType = GL11.GL_LINE_LOOP;
    //    glLineWidth(5.f);

    boolean polygonStarted = false;

    PathIterator pathIterator = shape.getPathIterator(null);
    // System.err.print("polygon ");
    while (!pathIterator.isDone()) {
        float[] coords = new float[6];

        int segmentType = pathIterator.currentSegment(coords);
        switch (segmentType) {
        case PathIterator.SEG_CLOSE:
            if (polygonStarted) {
                GL11.glEnd();
                polygonStarted = false;
            }
        case PathIterator.SEG_MOVETO:
            if (polygonStarted) {
                GL11.glEnd(); // close the current polygon
                polygonStarted = false;
            }
            GL11.glBegin(glDrawType); // open a new one
            polygonStarted = true;
            GL11.glVertex2f(coords[0], coords[1]); // starting at the given position
            break;
        case PathIterator.SEG_CUBICTO:

            if (!polygonStarted) {
                GL11.glBegin(glDrawType); // start a new polygon if not already done
                polygonStarted = true;
            }
            GL11.glVertex2f(coords[4], coords[5]);
            break;
        case PathIterator.SEG_QUADTO:

            if (!polygonStarted) {
                GL11.glBegin(glDrawType); // start a new polygon if not already done
                polygonStarted = true;
            }
            GL11.glVertex2f(coords[2], coords[3]);
            break;

        case PathIterator.SEG_LINETO:

            if (!polygonStarted) {
                GL11.glBegin(glDrawType); // start a new polygon if not already done
                polygonStarted = true;
            }
            GL11.glVertex2f(coords[0], 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();
    }
    if (polygonStarted) {
        GL11.glEnd();
        polygonStarted = false;
    }
}

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./* w  w  w.ja  v  a  2s  .c  om*/
 * 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.theshark34.sharkengine.ui.components.Button.java

License:Apache License

/**
 * Draw the button// www  . ja 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 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/*from   w  w w .j a  va 2s .  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  ww  . j a va  2  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  .  j  a  v a  2  s . c  o m
 */
@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);
}