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:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Horizontal line/*from   www  .  j  a va2  s  .  com*/
 * 
 * @param x
 * @param x2
 * @param y
 * @param l1
 * @param col1
 */
public static void drawHorizontalLine(int x, int x2, int y, float l1, int col1) {
    float f = ((col1 >> 24) & 0xFF) / 255F;
    float f1 = ((col1 >> 16) & 0xFF) / 255F;
    float f2 = ((col1 >> 8) & 0xFF) / 255F;
    float f3 = (col1 & 0xFF) / 255F;

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);

    GL11.glPushMatrix();
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glLineWidth(l1);
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2d(x, y);
    GL11.glVertex2d(x2, y);
    GL11.glEnd();
    GL11.glPopMatrix();

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

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Diagonal line?//  w ww  .  j a v a 2  s.c  om
 * 
 * @param x
 * @param x2
 * @param y
 * @param l1
 * @param col1
 */
public static void drawDiagonalLine(int x, int x2, int y, float l1, int col1) {
    float f = ((col1 >> 24) & 0xFF) / 255F;
    float f1 = ((col1 >> 16) & 0xFF) / 255F;
    float f2 = ((col1 >> 8) & 0xFF) / 255F;
    float f3 = (col1 & 0xFF) / 255F;

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);

    GL11.glPushMatrix();
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glLineWidth(l1);
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2d(x, y);
    GL11.glVertex2d(y, x2);
    GL11.glEnd();
    GL11.glPopMatrix();

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

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Border of a circle/*from ww w . j a  v a 2s  .c o m*/
 * 
 * @param x
 * @param y
 * @param r
 * @param c
 */
public static void drawCircle(int x, int y, double r, int c) {
    float f = ((c >> 24) & 0xff) / 255F;
    float f1 = ((c >> 16) & 0xff) / 255F;
    float f2 = ((c >> 8) & 0xff) / 255F;
    float f3 = (c & 0xff) / 255F;
    GL11.glEnable(3042 /* GL_BLEND */);
    GL11.glDisable(3553 /* GL_TEXTURE_2D */);
    GL11.glEnable(2848 /* GL_LINE_SMOOTH */);
    GL11.glBlendFunc(770, 771);
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glBegin(2 /* GL_LINE_LOOP */);
    for (int i = 0; i <= 360; i++) {
        double x2 = Math.sin(((i * 3.141526D) / 180)) * r;
        double y2 = Math.cos(((i * 3.141526D) / 180)) * r;
        GL11.glVertex2d(x + x2, y + y2);
    }
    GL11.glEnd();
    GL11.glDisable(2848 /* GL_LINE_SMOOTH */);
    GL11.glEnable(3553 /* GL_TEXTURE_2D */);
    GL11.glDisable(3042 /* GL_BLEND */);
}

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Circle/*w w w . j  a v  a2 s.com*/
 * 
 * @param x
 * @param y
 * @param r
 * @param c
 */
public static void drawFilledCircle(int x, int y, double r, int c) {
    float f = ((c >> 24) & 0xff) / 255F;
    float f1 = ((c >> 16) & 0xff) / 255F;
    float f2 = ((c >> 8) & 0xff) / 255F;
    float f3 = (c & 0xff) / 255F;
    GL11.glEnable(3042 /* GL_BLEND */);
    GL11.glDisable(3553 /* GL_TEXTURE_2D */);
    GL11.glEnable(2848 /* GL_LINE_SMOOTH */);
    GL11.glBlendFunc(770, 771);
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glBegin(6 /* GL_TRIANGLE_FAN */);
    for (int i = 0; i <= 360; i++) {
        double x2 = Math.sin(((i * 3.141526D) / 180)) * r;
        double y2 = Math.cos(((i * 3.141526D) / 180)) * r;
        GL11.glVertex2d(x + x2, y + y2);
    }
    GL11.glEnd();
    GL11.glDisable(2848 /* GL_LINE_SMOOTH */);
    GL11.glEnable(3553 /* GL_TEXTURE_2D */);
    GL11.glDisable(3042 /* GL_BLEND */);
}

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Triangle/*from  w w w . j  a  v a  2s.  co  m*/
 * 
 * @param cx
 * @param cy
 * @param c
 */
public static void drawTri(int cx, int cy, int c) {
    GL11.glRotatef(180, 0F, 0F, 1.0F);
    float f = ((c >> 24) & 0xff) / 255F;
    float f1 = ((c >> 16) & 0xff) / 255F;
    float f2 = ((c >> 8) & 0xff) / 255F;
    float f3 = (c & 0xff) / 255F;
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glEnable(3042);
    GL11.glDisable(3553);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glBlendFunc(770, 771);
    GL11.glBegin(GL11.GL_TRIANGLES);
    GL11.glRotatef(180, 0F, 0F, 1.0F);
    GL11.glVertex2d(cx, cy + 2);
    GL11.glVertex2d(cx + 2, cy - 2);
    GL11.glVertex2d(cx - 2, cy - 2);

    GL11.glEnd();
    GL11.glDisable(GL11.GL_LINE_SMOOTH);
    GL11.glEnable(3553);
    GL11.glDisable(3042);
    GL11.glRotatef(-180, 0F, 0F, 1.0F);
}

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Triangle. Used for radars//from ww w  .ja v  a  2s.co  m
 * 
 * @param e
 * @param cx
 * @param cy
 * @param c
 */
public static void drawTriangle(Entity e, double cx, double cy, int c) {
    GL11.glPushMatrix();
    GL11.glScaled(0.5, 0.5, 0.5);
    GL11.glTranslated(cx, cy, 0);
    if (e instanceof EntityClientPlayerMP) {
        GL11.glRotatef(e.rotationYaw, 0F, 0F, 1.0F);
    } else {
        GL11.glRotatef(-e.rotationYaw, 0F, 0F, 1.0F);
    }
    float f = ((c >> 24) & 0xff) / 255F;
    float f1 = ((c >> 16) & 0xff) / 255F;
    float f2 = ((c >> 8) & 0xff) / 255F;
    float f3 = (c & 0xff) / 255F;
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glEnable(3042);
    GL11.glDisable(3553);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glBlendFunc(770, 771);
    GL11.glBegin(GL11.GL_TRIANGLES);

    GL11.glVertex2d(0, 0 + 6);
    GL11.glVertex2d(0 + 3, 0 - 2);
    GL11.glVertex2d(0 - 3, 0 - 2);

    GL11.glEnd();
    GL11.glDisable(GL11.GL_LINE_SMOOTH);
    GL11.glEnable(3553);
    GL11.glDisable(3042);
    GL11.glRotatef(e.rotationYaw, 0F, 0F, 1.0F);

    GL11.glPopMatrix();
}

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

/**
 * Half Circle//from w  w w  . j a v  a2  s  .c  o m
 * 
 * Modes: 0 Left to right, bottom to top 1 Top to bottom, left to right 2
 * Right to left, top to bottom 3 Bottom to top, right to left
 * 
 * @param x
 * @param y
 * @param r
 * @param c
 */
public static void drawFilledHalfCircle(int x, int y, double r, int c, int mode) {
    float f = ((c >> 24) & 0xff) / 255F;
    float f1 = ((c >> 16) & 0xff) / 255F;
    float f2 = ((c >> 8) & 0xff) / 255F;
    float f3 = (c & 0xff) / 255F;
    GL11.glDisable(3553 /* GL_TEXTURE_2D */);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(770, 771);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
    GL11.glEnable(GL11.GL_POINT_SMOOTH);
    GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
    GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);
    GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);

    GL11.glColor4f(f1, f2, f3, f);
    GL11.glBegin(6 /* GL_TRIANGLE_FAN */);

    int startang = 0;
    int endang = 0;

    if (mode == 0) {
        startang = 90;
        endang = 270;
    }
    if (mode == 1) {
        startang = 360;
        endang = 540;
    }
    if (mode == 2) {
        startang = 270;
        endang = 450;
    }
    if (mode == 3) {
        startang = 180;
        endang = 360;
    }

    for (int i = startang; i <= endang; i++) {
        double x2 = Math.sin(((i * 3.141526D) / 180)) * r;
        double y2 = Math.cos(((i * 3.141526D) / 180)) * r;
        GL11.glVertex2d(x + x2, y + y2);
    }
    GL11.glEnd();
    GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
    GL11.glDisable(GL11.GL_POINT_SMOOTH);
    GL11.glDisable(2848 /* GL_LINE_SMOOTH */);
    GL11.glEnable(3553 /* GL_TEXTURE_2D */);
    GL11.glDisable(3042 /* GL_BLEND */);
}

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

public static void drawGradientRect(double x, double y, double x2, double y2, int col1, int col2) {
    float f = ((col1 >> 24) & 0xFF) / 255F;
    float f1 = ((col1 >> 16) & 0xFF) / 255F;
    float f2 = ((col1 >> 8) & 0xFF) / 255F;
    float f3 = (col1 & 0xFF) / 255F;

    float f4 = ((col2 >> 24) & 0xFF) / 255F;
    float f5 = ((col2 >> 16) & 0xFF) / 255F;
    float f6 = ((col2 >> 8) & 0xFF) / 255F;
    float f7 = (col2 & 0xFF) / 255F;

    GL11.glEnable(GL11.GL_BLEND);/*from w  w w  .  j  a v  a  2 s.  com*/
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glShadeModel(GL11.GL_SMOOTH);

    GL11.glPushMatrix();
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glVertex2d(x2, y);
    GL11.glVertex2d(x, y);

    GL11.glColor4f(f5, f6, f7, f4);
    GL11.glVertex2d(x, y2);
    GL11.glVertex2d(x2, y2);
    GL11.glEnd();
    GL11.glPopMatrix();

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

From source file:com.kodehawa.gui.api.render.ModGuiUtils.java

License:Open Source License

public static void drawGBRect(double x, double y, double x2, double y2, float l1, int col1, int col2,
        int col3) {
    float f = ((col1 >> 24) & 0xFF) / 255F;
    float f1 = ((col1 >> 16) & 0xFF) / 255F;
    float f2 = ((col1 >> 8) & 0xFF) / 255F;
    float f3 = (col1 & 0xFF) / 255F;

    GL11.glDisable(GL11.GL_TEXTURE_2D);/*from   www .jav  a2 s.  c om*/
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glDisable(GL11.GL_BLEND);

    GL11.glPushMatrix();
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glLineWidth(1F);
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2d(x, y);
    GL11.glVertex2d(x, y2);
    GL11.glVertex2d(x2, y2);
    GL11.glVertex2d(x2, y);
    GL11.glVertex2d(x, y);
    GL11.glVertex2d(x2, y);
    GL11.glVertex2d(x, y2);
    GL11.glVertex2d(x2, y2);
    GL11.glEnd();
    GL11.glPopMatrix();

    drawGradientRect(x, y, x2, y2, col2, col3);

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

From source file:com.lion328.thaifixes.nmod.ThaiFixesFontRenderer.java

License:Open Source License

private float renderThaiChar(char c, boolean italic) {
    try {/*w  ww.j  a  v  a 2s .co  m*/
        float cPosX, cPosY;
        switch (ThaiFixesConfiguration.getFontStyle()) {
        default:
        case UNICODE:
            if (ThaiFixesUtils.isSpecialThaiChar(c)) {
                //posX.setFloat(this, posX.getFloat(this) - 4); // move character to before character position
                byte size = ((byte[]) glyphWidth.get(this))[c];
                if (size == 0)
                    return 0.0F;
                else {
                    invokeMethod("loadGlyphTexture", new Class[] { int.class }, (int) (c / 256)); // load texture

                    float charHeightOnTexture = 4.98F,
                            beginTexcoordY = ThaiFixesUtils.isLowerThaiChar(c) ? 15.98F - charHeightOnTexture
                                    : 0F,
                            quadHeight = charHeightOnTexture / 2; // vertex position, not for texture coordinate.

                    // glyphWidth format:
                    // XXXXYYYY, XXXX as start X position on texture coordinate and YYYY as width.
                    float startTexcoordX = (float) (size >>> 4);
                    float charWidth = (float) ((size & 0xF) + 1);

                    float texcoordX = (float) (c % 16 * 16) + startTexcoordX;
                    float texcoordY = (float) ((c & 255) / 16 * 16);
                    float realCharWidth = charWidth - startTexcoordX - 0.02F;
                    float italicSize = italic ? 1.0F : 0.0F;

                    cPosX = posX.getFloat(this) - (realCharWidth + 0.02F) / 2 - 1; // get current position
                    cPosY = posY.getFloat(this);

                    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
                    GL11.glTexCoord2f(texcoordX / 256.0F, (texcoordY + beginTexcoordY) / 256.0F);
                    GL11.glVertex2f(cPosX + italicSize, cPosY + (beginTexcoordY / 2));
                    GL11.glTexCoord2f(texcoordX / 256.0F,
                            (texcoordY + beginTexcoordY + charHeightOnTexture) / 256.0F);
                    GL11.glVertex2f(cPosX - italicSize, cPosY + (beginTexcoordY / 2) + quadHeight);
                    GL11.glTexCoord2f((texcoordX + realCharWidth) / 256.0F,
                            (texcoordY + beginTexcoordY) / 256.0F);
                    GL11.glVertex2f(cPosX + realCharWidth / 2.0F + italicSize, cPosY + (beginTexcoordY / 2));
                    GL11.glTexCoord2f((texcoordX + realCharWidth) / 256.0F,
                            (texcoordY + beginTexcoordY + charHeightOnTexture) / 256.0F);
                    GL11.glVertex2f(cPosX + realCharWidth / 2.0F - italicSize,
                            cPosY + (beginTexcoordY / 2) + quadHeight);
                    GL11.glEnd();
                    return 0;//(realCharWidth + 0.02F) / 2.0F + 1.0F;
                }
            }
        case DISABLE:
            return (Float) invokeMethod("renderUnicodeChar", new Class[] { char.class, boolean.class }, c,
                    italic);
        case MCPX:
            //if(ThaiFixesUtils.isSpecialThaiChar(c)) posX.setFloat(this, posX.getFloat(this) - 5.0F);
            int posOnArray = c - THAI_CHAR_START;

            cPosX = posX.getFloat(this)
                    - (ThaiFixesUtils.isSpecialThaiChar(c) ? thaiCharWidth[posOnArray] : 0F); // get current position
            cPosY = posY.getFloat(this)
                    + (ThaiFixesUtils
                            .isSpecialThaiChar(c)
                                    ? (ThaiFixesUtils.isUpperThaiChar(c) ? -7.0F : 2.0F)
                                            - (!ThaiFixesUtils.isSpecialSpecialThaiChar(beforeChar)
                                                    ? (ThaiFixesUtils
                                                            .isSpecialThaiChar(beforeChar)
                                                                    ? 2.0F
                                                                    : (ThaiFixesUtils.isVeryLongTailThaiChar(
                                                                            beforeChar) ? 1.0F : 0.0F))
                                                    : 0.0F)
                                    : 0.0F);

            float texcoordX = (float) (posOnArray % 16 * 8);
            float texcoordY = (float) (posOnArray / 16 * 8);
            float italicSize = italic ? 1.0F : 0.0F;
            renderEngine.bindTexture(mcpx_font);
            float f3 = (float) thaiCharWidth[posOnArray] - 0.01F;
            GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
            GL11.glTexCoord2f(texcoordX / 128.0F, texcoordY / 128.0F);
            GL11.glVertex2f(cPosX + italicSize, cPosY);
            GL11.glTexCoord2f(texcoordX / 128.0F, (texcoordY + 7.99F) / 128.0F);
            GL11.glVertex2f(cPosX - italicSize, cPosY + 7.99F);
            GL11.glTexCoord2f((texcoordX + f3 - 1.0F) / 128.0F, texcoordY / 128.0F);
            GL11.glVertex2f(cPosX + f3 - 1.0F + italicSize, cPosY);
            GL11.glTexCoord2f((texcoordX + f3 - 1.0F) / 128.0F, (texcoordY + 7.99F) / 128.0F);
            GL11.glVertex2f(cPosX + f3 - 1.0F - italicSize, cPosY + 7.99F);
            GL11.glEnd();
            return ThaiFixesUtils.isSpecialThaiChar(c) ? 0 : (float) thaiCharWidth[posOnArray];
        }
    } catch (Exception e) {
        System.out.println("[ThaiFixes] Error during render an thai character '" + c + "'"
                + (italic ? " with italic style" : "") + ".");
        e.printStackTrace();
    }
    return 0.0F;
}