Example usage for org.lwjgl.opengl GL11 glBegin

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

Introduction

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

Prototype

public static native void glBegin(@NativeType("GLenum") int mode);

Source Link

Document

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

Usage

From source file:a1.Render2D.java

License:Open Source License

static public void FillEllipse(Coord c, Coord r, int a1, int a2) {
    GLColor();// www.  j a va  2  s. com
    GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    Vertex(c);
    for (int i = a1; i <= a2; i += 5) {
        double a = (i * Math.PI * 2) / 360.0;
        Vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y)));
    }
    GL11.glEnd();
    CheckError();
}

From source file:adrianton.gloptat.plotter.Box.java

License:Open Source License

static void assemble() {
    handle = GL11.glGenLists(1);//from  w ww .java  2  s  .c o  m
    GL11.glNewList(handle, GL11.GL_COMPILE);

    GL11.glLineWidth(3);
    GL11.glColor3f(1f, 1f, 1f);

    GL11.glBegin(GL11.GL_LINES);

    GL11.glVertex3d(-1, -1, 1);
    GL11.glVertex3d(1, -1, 1);
    GL11.glVertex3d(1, -1, 1);
    GL11.glVertex3d(1, 1, 1);
    GL11.glVertex3d(1, 1, 1);
    GL11.glVertex3d(-1, 1, 1);
    GL11.glVertex3d(-1, 1, 1);
    GL11.glVertex3d(-1, -1, 1);

    GL11.glVertex3d(-1, -1, -1);
    GL11.glVertex3d(1, -1, -1);
    GL11.glVertex3d(1, -1, -1);
    GL11.glVertex3d(1, 1, -1);
    GL11.glVertex3d(1, 1, -1);
    GL11.glVertex3d(-1, 1, -1);
    GL11.glVertex3d(-1, 1, -1);
    GL11.glVertex3d(-1, -1, -1);

    GL11.glVertex3d(-1, -1, -1);
    GL11.glVertex3d(-1, -1, 1);
    GL11.glVertex3d(1, -1, -1);
    GL11.glVertex3d(1, -1, 1);
    GL11.glVertex3d(1, 1, -1);
    GL11.glVertex3d(1, 1, 1);
    GL11.glVertex3d(-1, 1, -1);
    GL11.glVertex3d(-1, 1, 1);

    GL11.glEnd();

    GL11.glEndList();
}

From source file:adrianton.gloptat.plotter.Pointer.java

License:Open Source License

static void assemble() {
    final float tmpm = 1;
    final float tmpm2 = 1 / 3;
    final float tmpm3 = 7;

    handle = GL11.glGenLists(1);//from   ww w. java 2  s.  c o m
    GL11.glNewList(handle, GL11.GL_COMPILE);

    GL11.glBegin(GL11.GL_TRIANGLES);
    GL11.glColor3f(1, 1, 1);

    GL11.glVertex3f(0, 0, tmpm2);
    GL11.glVertex3f(-tmpm, -tmpm, tmpm3);
    GL11.glVertex3f(-tmpm, tmpm, tmpm3);

    GL11.glVertex3f(0, 0, tmpm2);
    GL11.glVertex3f(-tmpm, tmpm, tmpm3);
    GL11.glVertex3f(tmpm, tmpm, tmpm3);

    GL11.glVertex3f(0, 0, tmpm2);
    GL11.glVertex3f(tmpm, tmpm, tmpm3);
    GL11.glVertex3f(tmpm, -tmpm, tmpm3);

    GL11.glVertex3f(0, 0, tmpm2);
    GL11.glVertex3f(tmpm, -tmpm, tmpm3);
    GL11.glVertex3f(-tmpm, -tmpm, tmpm3);
    GL11.glEnd();

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex3f(tmpm, tmpm, tmpm3);
    GL11.glVertex3f(tmpm, -tmpm, tmpm3);
    GL11.glVertex3f(-tmpm, -tmpm, tmpm3);
    GL11.glVertex3f(-tmpm, tmpm, tmpm3);
    GL11.glEnd();

    GL11.glEndList();
}

From source file:adrianton.gloptat.plotter.Surface.java

License:Open Source License

public static void assemble(Displayer outer) {
    int i, j;//from  ww w. j  a v a 2 s  .com
    float px, py;
    float z1, z2, z3, z4;
    float tmp;

    Color col;

    float spx = -outer.rezx / 2;
    float spy = -outer.rezy / 2;

    handle = GL11.glGenLists(1);
    GL11.glNewList(handle, GL11.GL_COMPILE);

    GL11.glBegin(GL11.GL_QUADS);

    px = spx;
    for (i = 0; i < outer.rezx - 1; i++) {
        py = spy;
        for (j = 0; j < outer.rezy - 1; j++) {
            z1 = (float) outer.val[i][j];
            z2 = (float) outer.val[i + 1][j];
            z3 = (float) outer.val[i][j + 1];
            z4 = (float) outer.val[i + 1][j + 1];

            tmp = (float) (1 - ((outer.val[i][j] - outer.minc) / (outer.maxc - outer.minc)));
            tmp = tmp * 66 / 100 + 34 / 100;
            col = new Color(Color.HSBtoRGB(tmp, 0.7f, 0.85f));
            GL11.glColor3f((float) (col.getRed() / 255f), (float) (col.getGreen() / 255f),
                    (float) (col.getBlue() / 255f));

            GL11.glVertex3f(px, py, z1);

            tmp = (float) (1 - ((outer.val[i][j + 1] - outer.minc) / (outer.maxc - outer.minc)));
            tmp = tmp * 66 / 100 + 34 / 100;
            col = new Color(Color.HSBtoRGB(tmp, 0.7f, 0.85f));
            GL11.glColor3f((float) (col.getRed() / 255f), (float) (col.getGreen() / 255f),
                    (float) (col.getBlue() / 255f));

            GL11.glVertex3f(px, py + 1, z3);

            tmp = (float) (1 - ((outer.val[i + 1][j + 1] - outer.minc) / (outer.maxc - outer.minc)));
            tmp = tmp * 66 / 100 + 34 / 100;
            col = new Color(Color.HSBtoRGB(tmp, 0.7f, 0.85f));
            GL11.glColor3f((float) (col.getRed() / 255f), (float) (col.getGreen() / 255f),
                    (float) (col.getBlue() / 255f));

            GL11.glVertex3f(px + 1, py + 1, z4);

            tmp = (float) (1 - ((outer.val[i + 1][j] - outer.minc) / (outer.maxc - outer.minc)));
            tmp = tmp * 66 / 100 + 34 / 100;
            col = new Color(Color.HSBtoRGB(tmp, 0.7f, 0.85f));
            GL11.glColor3f((float) (col.getRed() / 255f), (float) (col.getGreen() / 255f),
                    (float) (col.getBlue() / 255f));

            GL11.glVertex3f(px + 1, py, z2);

            py += 1;
        }
        px += 1;
    }

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

From source file:ai.UnitAI.java

License:Open Source License

public void draw() {
    icon.bind();//from   ww  w .  j a  v a  2  s.  c  o  m
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2i(0, 0);
    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2i(0, 64);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2i(64, 64);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2i(64, 0);
    GL11.glEnd();
}

From source file:allout58.mods.techtree.util.RenderingHelper.java

License:Open Source License

public static void draw2DLine(int x1, int y1, int x2, int y2, float width, int colorRGB) {
    float red = (float) (colorRGB >> 16 & 255) / 255.0F;
    float blue = (float) (colorRGB >> 8 & 255) / 255.0F;
    float green = (float) (colorRGB & 255) / 255.0F;

    GL11.glDisable(GL11.GL_TEXTURE_2D);/*from   w  w  w .  ja v a 2s  .c o  m*/
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glLineWidth(width);

    GL11.glPushMatrix();
    GL11.glColor3f(red, green, blue);
    GL11.glBegin(GL11.GL_LINE_STRIP);
    GL11.glVertex3d(x1, y1, 0.0D);
    GL11.glVertex3d(x2, y2, 0.0D);
    GL11.glEnd();
    GL11.glPopMatrix();

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LINE_SMOOTH);
}

From source file:allout58.mods.techtree.util.RenderingHelper.java

License:Open Source License

public static void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color,
        int borderColor) throws IllegalArgumentException {
    if (radius * 2 > Math.abs(width))
        throw new IllegalArgumentException("Error! Width not large enough for radius!");
    if (radius * 2 > Math.abs(height))
        throw new IllegalArgumentException("Error! Height not large enough for radius!");

    if (width < 0) {
        x += width;/*from  w  w w .j  av a2s . c  om*/
        width = Math.abs(width);
    }
    if (height < 0) {
        y += height;
        height = Math.abs(height);
    }

    int x1Inner = x + radius;
    int y1Inner = y + radius;
    int x2Inner = x + width - radius;
    int y2Inner = y + height - radius;

    float red = (float) (borderColor >> 16 & 255) / 255.0F;
    float green = (float) (borderColor >> 8 & 255) / 255.0F;
    float blue = (float) (borderColor & 255) / 255.0F;
    float alpha = (float) (borderColor >> 24 & 255) / 255.0F;

    Gui.drawRect(x, y1Inner, x1Inner, y2Inner, borderColor);
    Gui.drawRect(x1Inner, y, x2Inner, y1Inner, borderColor);
    Gui.drawRect(x2Inner, y1Inner, x + width, y2Inner, borderColor);
    Gui.drawRect(x1Inner, y2Inner, x2Inner, y + height, borderColor);
    Gui.drawRect(x1Inner, y1Inner, x2Inner, y2Inner, color);

    ArrayList<Point> curves = new ArrayList<Point>();

    final double[][] start = new double[][] { { x1Inner, y1Inner }, { x2Inner, y1Inner }, { x2Inner, y2Inner },
            { x1Inner, y2Inner } };

    for (int corner = 0; corner < 4; corner++) {
        curves.clear();
        for (int i = 0; i < VERTEX_PER_CURVE + 1; i++) {
            double theta = deltaTheta * i + dT[corner];
            Point p = new Point(Math.cos(theta), Math.sin(theta));
            curves.add(p);
        }

        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glPushMatrix();
        GL11.glColor4f(red, green, blue, alpha);
        GL11.glBegin(GL11.GL_TRIANGLE_FAN);
        GL11.glVertex3d(start[corner][0], start[corner][1], 0);
        for (int i = curves.size() - 1; i >= 0; i--) {
            GL11.glVertex3d((curves.get(i).getX()) * radius + start[corner][0],
                    (curves.get(i).getY()) * radius + start[corner][1], 0);
        }
        GL11.glEnd();
        GL11.glPopMatrix();
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }
}

From source file:analog.clock.AnalogClock.java

private void drawCircle(double r, int n) {
    GL11.glColor3f(1.0f, 1.0f, 0.0f);//from  w  w  w . j av a2  s .c  om
    double theta = 2 * Math.PI / n;
    GL11.glPushMatrix();
    GL11.glBegin(GL11.GL_LINES);
    for (int i = 0; i < n;) {
        //GL11.glVertex3f(0, 0, 0);
        float x = (float) (r * Math.cos(theta * i));
        float y = (float) (r * Math.sin(theta * i));
        GL11.glVertex3f(x, y, 0);
        i++;
        x = (float) (r * Math.cos(theta * i));
        y = (float) (r * Math.sin(theta * i));
        GL11.glVertex3f(x, y, 0);
    }
    GL11.glEnd();
    GL11.glPopMatrix();
}

From source file:aphelion.client.graphics.world.Projectile.java

License:Open Source License

@Override
public boolean render(@Nonnull Camera camera, int iteration) {
    if (!isExists()) {
        return false;
    }//  ww w.j  a va  2  s  .c  om

    if (iteration > 1) {
        return false;
    }

    updateAnimObjects();

    Point screenPos = new Point();
    camera.mapToScreenPosition(pos, screenPos);

    if (camera.radarRendering) {
        if (iteration == 0 && this.animRadar != null) {
            org.newdawn.slick.Color color = this.animRadar.get();
            TextureImpl.bindNone();
            GL11.glColor4f(color.r, color.g, color.b, color.a * this.alpha);
            float x = screenPos.x - 0.5f;
            float y = screenPos.y - 0.5f;
            GL11.glBegin(SGL.GL_QUADS);
            GL11.glVertex2f(x, y);
            GL11.glVertex2f(x + 1, y);
            GL11.glVertex2f(x + 1, y + 1);
            GL11.glVertex2f(x, y + 1);
            GL11.glEnd();
        }

        return false;
    }

    if (iteration == 0) {
        // render the trail
        SpriteSheetCounted trail = this.imageTrail.getSpriteSheet();
        if (trail != null) {
            Point trailPos = new Point();
            PhysicsPositionVector phyPos = new PhysicsPositionVector();

            long rand = imageTrailRandomized.get() ? SwissArmyKnife.fastRandomIsh() : 0;

            long tick = this.renderingAt_tick - (rand & 0b11); // 0, 1, 2, 3
            rand >>= 2;

            for (int tile = 0; tile < trail.getTilesCount(); tile += (rand & 0b1) + 1, rand >>= 1) {
                physicsProjectile.getHistoricPosition(phyPos, tick - 2 * tile, true);

                if (phyPos.pos.set) {
                    trailPos.set(phyPos.pos);
                    trailPos.divide(1024);
                    camera.mapToScreenPosition(trailPos, trailPos);

                    Image img = trail.getSubImage(tile);
                    img.draw(trailPos.x - img.getWidth() / 2, trailPos.y - img.getHeight() / 2,
                            this.alphaFilter);
                }

            }
        }
    } else if (iteration == 1) {
        Animation anim;

        if (imageInactive.isSet() && !this.physicsProjectile.isActive()) {
            anim = animInactive;
        } else if (imageBounces.isSet() && this.physicsProjectile.getBouncesLeft() != 0) {
            anim = animBounces;
        } else {
            anim = animNoBounce; // also fallback
        }

        if (anim != null) {
            anim.draw(screenPos.x - anim.getWidth() / 2 * camera.zoom,
                    screenPos.y - anim.getHeight() / 2 * camera.zoom, anim.getWidth() * camera.zoom,
                    anim.getHeight() * camera.zoom, this.alphaFilter);
        }

        if (Client.showDebug) {
            camera.renderPlayerText(this.renderDelay_current + "", screenPos.x + 5, screenPos.y + 5,
                    Color.WHITE);
        }
    }

    return iteration < 1;
}

From source file:br.org.archimedes.gui.opengl.OpenGLWrapper.java

License:Open Source License

/**
 * Draws the collection of points based on the current geometric primitive and fill it.
 * /* w ww  .j  av a 2 s. com*/
 * @param points
 *            Points in the model coordinate system
 * @throws NullArgumentException
 *             Thrown if points is null
 */
public void drawFromModel(List<Point> points) throws NullArgumentException {

    if (points == null) {
        throw new NullArgumentException();
    }
    GL11.glBegin(primitiveType);
    for (Point point : points) {
        try {
            Point convertedPoint = br.org.archimedes.Utils.getWorkspace().modelToScreen(point);
            GL11.glVertex2d(convertedPoint.getX(), convertedPoint.getY());
        } catch (NullArgumentException e) {
            // Should never reach this block.
            e.printStackTrace();
        }
    }
    GL11.glEnd();
}