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:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Renders a nonstandard horizontal rectangle (nonstandard referring primarily to
 * the texture size (ie: when we're not pulling a single element out of a 16x16
 * grid).//  ww w  . jav  a  2  s  . c  o  m
 *
 * @param tx  X index within the texture
 * @param ty  Y index within the texture
 * @param tdx Width of texture
 * @param tdy Height of texture
 * @param x1
 * @param z1
 * @param x2
 * @param z2
 * @param y
 */
public static void renderNonstandardHorizontal(float tx, float ty, float tdx, float tdy, float x1, float z1,
        float x2, float z2, float y) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y, z1);

    GL11.glTexCoord2f(tx + tdx, ty);
    GL11.glVertex3f(x1, y, z2);

    GL11.glTexCoord2f(tx, ty + tdy);
    GL11.glVertex3f(x2, y, z1);

    GL11.glTexCoord2f(tx + tdx, ty + tdy);
    GL11.glVertex3f(x2, y, z2);
    GL11.glEnd();
}

From source file:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Render a surface on a horizontal plane; pass in all four verticies.  This can result,
 * obviously, in non-rectangular and non-orthogonal shapes.
 *
 * @param tx//from w ww  . j a va 2s  .co  m
 * @param ty
 * @param tdx
 * @param tdy
 * @param x1
 * @param z1
 * @param x2
 * @param z2
 * @param x3
 * @param z3
 * @param x4
 * @param z4
 * @param y
 */
public static void renderHorizontalAskew(float tx, float ty, float tdx, float tdy, float x1, float z1, float x2,
        float z2, float x3, float z3, float x4, float z4, float y) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y, z1);

    GL11.glTexCoord2f(tx + tdx, ty);
    GL11.glVertex3f(x2, y, z2);

    GL11.glTexCoord2f(tx, ty + tdy);
    GL11.glVertex3f(x3, y, z3);

    GL11.glTexCoord2f(tx + tdx, ty + tdy);
    GL11.glVertex3f(x4, y, z4);
    GL11.glEnd();
}

From source file:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Renders a block sized face with the given facing.
 *
 * @param dimensions Texture dimensions//from  www.  j  ava  2  s.  c o  m
 * @param x
 * @param y
 * @param z
 * @param facing     The face that should be drawn
 */
public static void renderBlockFace(TextureDimensions dimensions, float x, float y, float z, Facing facing) {
    float curFace[][];
    switch (facing) {
    case UP:
        curFace = new float[][] { { 0f, 1f, 1f }, { 0f, 1f, 0f }, { 1f, 1f, 1f }, { 1f, 1f, 0f } };
        break;
    case DOWN:
        curFace = new float[][] { { 0f, 0f, 1f }, { 0f, 0f, 0f }, { 1f, 0f, 1f }, { 1f, 0f, 0f } };
        break;
    case NORTH:
        curFace = new float[][] { { 0f, 1f, 0f }, { 1f, 1f, 0f }, { 0f, 0f, 0f }, { 1f, 0f, 0f } };
        break;
    case SOUTH:
        curFace = new float[][] { { 0f, 1f, 1f }, { 1f, 1f, 1f }, { 0f, 0f, 1f }, { 1f, 0f, 1f } };
        break;
    case WEST:
        curFace = new float[][] { { 0f, 1f, 1f }, { 0f, 1f, 0f }, { 0f, 0f, 1f }, { 0f, 0f, 0f } };
        break;
    case EAST:
        curFace = new float[][] { { 1f, 1f, 1f }, { 1f, 1f, 0f }, { 1f, 0f, 1f }, { 1f, 0f, 0f } };
        break;
    default:
        return;
    }

    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(dimensions.getTexLeft(), dimensions.getTexTop());
    GL11.glVertex3f(x + curFace[0][0], y + curFace[0][1], z + curFace[0][2]);

    GL11.glTexCoord2f(dimensions.getTexLeft() + dimensions.getTexWidth(), dimensions.getTexTop());
    GL11.glVertex3f(x + curFace[1][0], y + curFace[1][1], z + curFace[1][2]);

    GL11.glTexCoord2f(dimensions.getTexLeft(), dimensions.getTexTop() + dimensions.getTexHeight());
    GL11.glVertex3f(x + curFace[2][0], y + curFace[2][1], z + curFace[2][2]);

    GL11.glTexCoord2f(dimensions.getTexLeft() + dimensions.getTexWidth(),
            dimensions.getTexTop() + dimensions.getTexHeight());
    GL11.glVertex3f(x + curFace[3][0], y + curFace[3][1], z + curFace[3][2]);
    GL11.glEnd();
}

From source file:de.kitsunealex.projectx.client.render.RenderTruncatedIcosahedron.java

License:Open Source License

private void generate() {
    int[] s = { 1, -1 };

    for (int i = 0; i < 4; i++) {
        VERTS[i] = new Vector3(0D, s[(i / 2)], s[(i % 2)] * 3 * MathHelper.phi);
    }// w ww  .j  a  v  a2  s  .  c om

    for (int i = 0; i < 8; i++) {
        VERTS[(i + 4)] = new Vector3(s[(i / 4)] * 2, s[(i / 2 % 2)] * 4.2360679999999995D,
                s[(i % 2)] * MathHelper.phi);
        VERTS[(i + 12)] = new Vector3(s[(i / 4)], s[(i / 2 % 2)] * 3.6180339999999998D,
                s[(i % 2)] * 2 * MathHelper.phi);
    }

    for (int i = 0; i < 20; i++) {
        VERTS[(i + 20)] = new Vector3(VERTS[i].y, VERTS[i].z, VERTS[i].x);
        VERTS[(i + 40)] = new Vector3(VERTS[i].z, VERTS[i].x, VERTS[i].y);
    }

    LIST_INDEX = GL11.glGenLists(2);
    GL11.glNewList(LIST_INDEX, GL11.GL_COMPILE);
    GL11.glBegin(GL11.GL_LINE_BIT);

    for (int rot = 0; rot < 3; rot++) {
        for (int i = 0; i < 4; i++) {
            pentagon(rot, i);
        }
    }

    GL11.glEnd();
    GL11.glEndList();
    GL11.glNewList(LIST_INDEX + 1, GL11.GL_COMPILE);
    GL11.glBegin(GL11.GL_LINE_BIT);

    for (int rot = 0; rot < 3; rot++) {
        for (int i = 0; i < 4; i++) {
            hexagon1(rot, i);
        }
    }

    for (int i = 0; i < 8; i++) {
        hexagon2(i);
    }

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

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);/*  w w w . j av a2 s.  c  o m*/

    // 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);

    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);/*from   w ww. j  a va  2s .  c om*/
    GL11.glVertex2f(bounds.getX(), bounds.getY());

    GL11.glEnd();
}

From source file:eb.core.gui.GuiHelper.java

License:LGPL

public static void drawTexturedRect(int x, int y, int width, int height, int textureSize, int[] u, int[] v) {
    float uf[] = new float[] { (float) u[0] / (float) textureSize, (float) u[1] / (float) textureSize };
    float vf[] = new float[] { (float) v[0] / (float) textureSize, (float) v[1] / (float) textureSize };

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uf[0], vf[0]);/*from ww  w  . ja  v  a  2s  .  c  o m*/
    GL11.glVertex2i(x, y);
    GL11.glTexCoord2f(uf[0], vf[1]);
    GL11.glVertex2i(x, y + height);
    GL11.glTexCoord2f(uf[1], vf[1]);
    GL11.glVertex2i(x + width, y + height);
    GL11.glTexCoord2f(uf[1], vf[0]);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.FramedControl.java

License:Apache License

public void render() {
    // render with no texture
    Texture texture = getTexture();/*from   www . j  a va2s  . c o m*/
    setTexture((Texture) null);

    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    super.render();
    GL11.glPopMatrix();

    setTexture(texture);

    // rendering texture
    if ((!isVisible()) || (texture == null)) {
        return;
    }

    Size controlSize = getSize();
    Size imageSize = texture.getImage().getSize();
    float margin = getMargin();
    if ((margin >= controlSize.getWidth()) || (margin >= controlSize.getHeight())) {
        margin = 0.0f;
    }

    Color color = getColor();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(((float) color.getRed() / 255.0f), ((float) color.getGreen() / 255.0f),
            ((float) color.getBlue() / 255.0f), getOpacity());

    Point position = getOpenGlPosition();
    float halfWidth = (controlSize.getWidth() / 2.0f);
    float halfHeight = (controlSize.getHeight() / 2.0f);
    GL11.glTranslatef(position.getX(), position.getY(), 0.0f);

    float rotation = OpenGlUtility.getOpenGlRotation(getRotation());
    GL11.glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    // render texture
    GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(((-1 * halfWidth) + margin), ((-1 * halfHeight) + margin), 0.0f);

    GL11.glTexCoord2f(imageSize.getWidth(), 0.0f);
    GL11.glVertex3f((halfWidth - margin), ((-1 * halfHeight) + margin), 0.0f);

    GL11.glTexCoord2f(imageSize.getWidth(), imageSize.getHeight());
    GL11.glVertex3f((halfWidth - margin), (halfHeight - margin), 0.0f);

    GL11.glTexCoord2f(0.0f, imageSize.getHeight());
    GL11.glVertex3f(((-1 * halfWidth) + margin), (halfHeight - margin), 0.0f);
    GL11.glEnd();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.TexturedControl.java

License:Apache License

public void render() {
    if (!isVisible()) {
        return;/*from  w ww.  j a  v a2  s.c om*/
    }

    Size controlSize = getSize();
    Size imageSize = null;
    if (texture != null) {
        imageSize = texture.getImage().getSize();
    }

    Color color = getColor();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(((float) color.getRed() / 255.0f), ((float) color.getGreen() / 255.0f),
            ((float) color.getBlue() / 255.0f), getOpacity());

    Point position = getOpenGlPosition();
    float halfWidth = (controlSize.getWidth() / 2.0f);
    float halfHeight = (controlSize.getHeight() / 2.0f);
    GL11.glTranslatef(position.getX(), position.getY(), 0.0f);

    float rotation = OpenGlUtility.getOpenGlRotation(getRotation());
    GL11.glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    if (texture != null) {
        GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
        GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());
    } else {
        GL11.glDisable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    }

    // bl -> br -> tr -> tl
    GL11.glBegin(GL11.GL_QUADS);
    if (texture != null) {
        GL11.glTexCoord2f(0.0f, 0.0f);
    }
    GL11.glVertex3f((-1 * halfWidth), (-1 * halfHeight), 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(imageSize.getWidth(), 0.0f);
    }
    GL11.glVertex3f(halfWidth, (-1 * halfHeight), 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(imageSize.getWidth(), imageSize.getHeight());
    }
    GL11.glVertex3f(halfWidth, halfHeight, 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(0.0f, imageSize.getHeight());
    }
    GL11.glVertex3f((-1 * halfWidth), halfHeight, 0.0f);
    GL11.glEnd();
}

From source file:effects.Projectile.java

License:Open Source License

public void draw() {
    GL11.glDisable(GL11.GL_LIGHTING);//from w ww  . j  a  v a  2  s  .  co  m
    material.bind();
    GL11.glColor3f(1.0f, 1.0f, 1.0f);
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex3f(pos.x, pos.y, pos.z);
    GL11.glVertex3f(pos.x + vel.x / 10, pos.y + vel.y / 10, pos.z + vel.z / 10);
    GL11.glEnd();
    GL11.glEnable(GL11.GL_LIGHTING);
}