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:net.phatcode.rel.multimedia.Graphics.java

License:Open Source License

public void drawSpriteOnLine(int x1, int y1, int x2, int y2, int width, int type) {

    SpriteGL sprite = glowImages.getSprite(type % glowImages.getNumImages());

    // Only change active texture when there is a need
    // Speeds up the rendering by batching textures

    if (sprite.textureID != currentTexture) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID);
        currentTexture = sprite.textureID;
    }//from  w w  w.j a v  a 2  s .  c o  m

    float u1 = sprite.u1;
    float v1 = sprite.v1;
    float u2 = sprite.u2;
    float v2 = sprite.v2;
    float uh = (u1 + u2) / 2.0f;

    float nx, ny;
    nx = -(y2 - y1);
    ny = (x2 - x1);

    float leng;
    leng = (float) Math.sqrt(nx * nx + ny * ny);
    nx = nx / leng;
    ny = ny / leng;

    nx *= width / 2.0;
    ny *= width / 2.0;

    float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4;

    lx1 = x2 + nx;
    ly1 = y2 + ny;
    lx2 = x2 - nx;
    ly2 = y2 - ny;
    lx3 = x1 - nx;
    ly3 = y1 - ny;
    lx4 = x1 + nx;
    ly4 = y1 + ny;

    // MAIN
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx1, ly1, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx2, ly2, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx3, ly3, 0.0f);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx4, ly4, 0.0f);
    GL11.glEnd();

    //RIGHT
    float lx5, ly5, lx6, ly6, vx, vy;
    vx = (x2 - x1);
    vy = (y2 - y1);
    leng = (float) Math.sqrt(vx * vx + vy * vy);
    vx = vx / leng;
    vy = vy / leng;
    vx *= width / 2.0;
    vy *= width / 2.0;

    lx5 = lx1 + vx;
    ly5 = ly1 + vy;
    lx6 = lx2 + vx;
    ly6 = ly2 + vy;

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx1, ly1, 0.0f);
    GL11.glTexCoord2f(u2, v1);
    GL11.glVertex3f(lx5, ly5, 0.0f);
    GL11.glTexCoord2f(u2, v2);
    GL11.glVertex3f(lx6, ly6, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx2, ly2, 0.0f);
    GL11.glEnd();

    // LEFT
    lx5 = lx4 - vx;
    ly5 = ly4 - vy;
    lx6 = lx3 - vx;
    ly6 = ly3 - vy;

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx4, ly4, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx3, ly3, 0.0f);
    GL11.glTexCoord2f(u2, v2);
    GL11.glVertex3f(lx6, ly6, 0.0f);
    GL11.glTexCoord2f(u2, v1);
    GL11.glVertex3f(lx5, ly5, 0.0f);
    GL11.glEnd();

}

From source file:net.phatcode.rel.multimedia.Graphics.java

License:Open Source License

public void drawSpriteOnLine(int x1, int y1, int x2, int y2, int width, int type, float r, float g, float b,
        float a) {

    SpriteGL sprite = glowImages.getSprite(type % glowImages.getNumImages());

    // Only change active texture when there is a need
    // Speeds up the rendering by batching textures

    if (sprite.textureID != currentTexture) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID);
        currentTexture = sprite.textureID;
    }/* w w  w.j av  a2s . co  m*/

    GL11.glColor4f(r, g, b, a);

    float u1 = sprite.u1;
    float v1 = sprite.v1;
    float u2 = sprite.u2;
    float v2 = sprite.v2;
    float uh = (u1 + u2) / 2.0f;

    float nx, ny;
    nx = -(y2 - y1);
    ny = (x2 - x1);

    float leng;
    leng = (float) Math.sqrt(nx * nx + ny * ny);
    nx = nx / leng;
    ny = ny / leng;

    nx *= width / 2.0;
    ny *= width / 2.0;

    float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4;

    lx1 = x2 + nx;
    ly1 = y2 + ny;
    lx2 = x2 - nx;
    ly2 = y2 - ny;
    lx3 = x1 - nx;
    ly3 = y1 - ny;
    lx4 = x1 + nx;
    ly4 = y1 + ny;

    // MAIN
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx1, ly1, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx2, ly2, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx3, ly3, 0.0f);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx4, ly4, 0.0f);
    GL11.glEnd();

    //RIGHT
    float lx5, ly5, lx6, ly6, vx, vy;
    vx = (x2 - x1);
    vy = (y2 - y1);
    leng = (float) Math.sqrt(vx * vx + vy * vy);
    vx = vx / leng;
    vy = vy / leng;
    vx *= width / 2.0;
    vy *= width / 2.0;

    lx5 = lx1 + vx;
    ly5 = ly1 + vy;
    lx6 = lx2 + vx;
    ly6 = ly2 + vy;

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx1, ly1, 0.0f);
    GL11.glTexCoord2f(u2, v1);
    GL11.glVertex3f(lx5, ly5, 0.0f);
    GL11.glTexCoord2f(u2, v2);
    GL11.glVertex3f(lx6, ly6, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx2, ly2, 0.0f);
    GL11.glEnd();

    // LEFT
    lx5 = lx4 - vx;
    ly5 = ly4 - vy;
    lx6 = lx3 - vx;
    ly6 = ly3 - vy;

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(uh, v1);
    GL11.glVertex3f(lx4, ly4, 0.0f);
    GL11.glTexCoord2f(uh, v2);
    GL11.glVertex3f(lx3, ly3, 0.0f);
    GL11.glTexCoord2f(u2, v2);
    GL11.glVertex3f(lx6, ly6, 0.0f);
    GL11.glTexCoord2f(u2, v1);
    GL11.glVertex3f(lx5, ly5, 0.0f);
    GL11.glEnd();

}

From source file:net.phatcode.rel.multimedia.Graphics.java

License:Open Source License

private void drawScrolledSprite(float x, float y, float scaleX, float scaleY, float u, float v, int flipmode,
        SpriteGL sprite) {/*from ww w  . j a v  a 2s.co m*/

    flipmode = getflipMode(flipmode);

    float x2 = x + sprite.width;
    float y2 = y + sprite.height;

    float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2;
    float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2;
    float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1;
    float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1;

    if (sprite.textureID != currentTexture) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID);
        currentTexture = sprite.textureID;
    }

    GL11.glPushMatrix();

    GL11.glScalef(scaleX, scaleY, 1.0f);

    GL11.glBegin(GL11.GL_QUADS);

    GL11.glTexCoord2f(u1 + u, v1 + v);
    GL11.glVertex2f(x, y);
    GL11.glTexCoord2f(u1 + u, v2 + v);
    GL11.glVertex2f(x, y2);
    GL11.glTexCoord2f(u2 + u, v2 + v);
    GL11.glVertex2f(x2, y2);
    GL11.glTexCoord2f(u2 + u, v1 + v);
    GL11.glVertex2f(x2, y);

    GL11.glEnd();

    GL11.glPopMatrix();

}

From source file:net.phatcode.rel.multimedia.Graphics.java

License:Open Source License

private void drawScrolledSprite(float x, float y, float scaleX, float scaleY, float u, float v, float r,
        float g, float b, float a, int flipmode, SpriteGL sprite) {

    flipmode = getflipMode(flipmode);/*from   w  ww .  jav a2 s . c  om*/

    float x2 = x + sprite.width;
    float y2 = y + sprite.height;

    float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2;
    float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2;
    float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1;
    float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1;

    if (sprite.textureID != currentTexture) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID);
        currentTexture = sprite.textureID;
    }

    GL11.glColor4f(r, g, b, a);

    GL11.glPushMatrix();

    GL11.glScalef(scaleX, scaleY, 1.0f);

    GL11.glBegin(GL11.GL_QUADS);

    GL11.glTexCoord2f(u1 + u, v1 + v);
    GL11.glVertex2f(x, y);
    GL11.glTexCoord2f(u1 + u, v2 + v);
    GL11.glVertex2f(x, y2);
    GL11.glTexCoord2f(u2 + u, v2 + v);
    GL11.glVertex2f(x2, y2);
    GL11.glTexCoord2f(u2 + u, v1 + v);
    GL11.glVertex2f(x2, y);

    GL11.glEnd();

    GL11.glPopMatrix();

}

From source file:net.quetzi.bluepower.part.gate.GateBase.java

License:Open Source License

@Override
public final void renderDynamic(Vector3 loc, int pass, float frame) {

    GL11.glPushMatrix();// w ww.j a v  a 2 s  .c  om
    {
        super.rotateAndTranslateDynamic(loc, pass, frame);

        /* Top */
        renderTop(frame);

        Minecraft.getMinecraft().renderEngine
                .bindTexture(new ResourceLocation(Refs.MODID + ":textures/blocks/gates/bottom.png"));
        GL11.glBegin(GL11.GL_QUADS);
        /* Bottom */
        GL11.glNormal3d(0, -1, 0);
        RenderHelper.addVertexWithTexture(0, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(1, 0, 0, 1, 0);
        RenderHelper.addVertexWithTexture(1, 0, 1, 1, 1);
        RenderHelper.addVertexWithTexture(0, 0, 1, 0, 1);
        GL11.glEnd();
        Minecraft.getMinecraft().renderEngine
                .bindTexture(new ResourceLocation(Refs.MODID + ":textures/blocks/gates/side.png"));
        GL11.glBegin(GL11.GL_QUADS);
        /* East */
        GL11.glNormal3d(1, 0, 0);
        RenderHelper.addVertexWithTexture(1, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 0, 1, 0);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 1, 1, 1);
        RenderHelper.addVertexWithTexture(1, 0, 1, 0, 1);
        /* West */
        GL11.glNormal3d(-1, 0, 0);
        RenderHelper.addVertexWithTexture(0, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(0, 0, 1, 0, 1);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 1, 1, 1);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 0, 1, 0);
        /* North */
        GL11.glNormal3d(0, 0, -1);
        RenderHelper.addVertexWithTexture(0, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 0, 1, 0);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 0, 1, 1);
        RenderHelper.addVertexWithTexture(1, 0, 0, 0, 1);
        /* South */
        GL11.glNormal3d(0, 0, 1);
        RenderHelper.addVertexWithTexture(0, 0, 1, 0, 0);
        RenderHelper.addVertexWithTexture(1, 0, 1, 0, 1);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 1, 1, 1);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 1, 1, 0);
        GL11.glEnd();
    }
    GL11.glPopMatrix();
}

From source file:net.quetzi.bluepower.part.gate.GateBase.java

License:Open Source License

public void renderTopTexture(String texture) {

    Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(texture));
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glNormal3d(0, 1, 0);//from   w  ww . j a  v  a  2s.  c o m
    RenderHelper.addVertexWithTexture(0, 1D / 8D, 0, 0, 0);
    RenderHelper.addVertexWithTexture(0, 1D / 8D, 1, 0, 1);
    RenderHelper.addVertexWithTexture(1, 1D / 8D, 1, 1, 1);
    RenderHelper.addVertexWithTexture(1, 1D / 8D, 0, 1, 0);
    GL11.glEnd();
}

From source file:net.quetzi.bluepower.part.gate.GateBase.java

License:Open Source License

@Override
public final void renderItem(ItemRenderType type, ItemStack item, Object... data) {

    GL11.glPushMatrix();//from   w w  w .  j  a v a  2s .c om
    {

        if (type == ItemRenderType.INVENTORY) {
            GL11.glTranslated(0, 0.5, 0);
            GL11.glRotated(-12, -1, 0, 1);
        }

        /* Top */
        renderTop();

        Minecraft.getMinecraft().renderEngine
                .bindTexture(new ResourceLocation(Refs.MODID + ":textures/blocks/gates/bottom.png"));
        GL11.glBegin(GL11.GL_QUADS);
        /* Bottom */
        GL11.glNormal3d(0, -1, 0);
        RenderHelper.addVertexWithTexture(0, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(1, 0, 0, 1, 0);
        RenderHelper.addVertexWithTexture(1, 0, 1, 1, 1);
        RenderHelper.addVertexWithTexture(0, 0, 1, 0, 1);
        GL11.glEnd();
        Minecraft.getMinecraft().renderEngine
                .bindTexture(new ResourceLocation(Refs.MODID + ":textures/blocks/gates/side.png"));
        GL11.glBegin(GL11.GL_QUADS);
        /* East */
        GL11.glNormal3d(1, 0, 0);
        RenderHelper.addVertexWithTexture(1, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 0, 1, 0);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 1, 1, 1);
        RenderHelper.addVertexWithTexture(1, 0, 1, 0, 1);
        /* West */
        GL11.glNormal3d(-1, 0, 0);
        RenderHelper.addVertexWithTexture(0, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(0, 0, 1, 0, 1);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 1, 1, 1);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 0, 1, 0);
        /* North */
        GL11.glNormal3d(0, 0, -1);
        RenderHelper.addVertexWithTexture(0, 0, 0, 0, 0);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 0, 1, 0);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 0, 1, 1);
        RenderHelper.addVertexWithTexture(1, 0, 0, 0, 1);
        /* South */
        GL11.glNormal3d(0, 0, 1);
        RenderHelper.addVertexWithTexture(0, 0, 1, 0, 0);
        RenderHelper.addVertexWithTexture(1, 0, 1, 0, 1);
        RenderHelper.addVertexWithTexture(1, 1D / 8D, 1, 1, 1);
        RenderHelper.addVertexWithTexture(0, 1D / 8D, 1, 1, 0);
        GL11.glEnd();
    }
    GL11.glPopMatrix();
}

From source file:net.shadowmage.ancientwarfare.core.model.ModelPiece.java

License:Open Source License

public void renderForEditor(ModelPiece piece, Primitive prim, List<ModelPiece> highlightedPieces, float tw,
        float th) {
    GL11.glPushMatrix();//from ww  w .  jav a  2s  .  c o  m
    if (x != 0 || y != 0 || z != 0) {
        GL11.glTranslatef(x, y, z);
    }
    if (rx != 0) {
        GL11.glRotatef(rx, 1, 0, 0);
    }
    if (ry != 0) {
        GL11.glRotatef(ry, 0, 1, 0);
    }
    if (rz != 0) {
        GL11.glRotatef(rz, 0, 0, 1);
    }

    boolean selected = piece == this;
    boolean colored = selected || highlightedPieces.contains(this);
    if (selected) {
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glColor4f(1.0f, 0.f, 0.f, 1.f);
        GL11.glPointSize(5.f);
        GL11.glBegin(GL11.GL_POINTS);
        GL11.glVertex3f(0, 0, 0);
        GL11.glEnd();
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }
    if (colored) {
        GL11.glColor4f(0.75f, 0.5f, 0.5f, 1.f);
    } else {
        GL11.glColor4f(1.f, 1.f, 1.f, 1.f);
    }
    for (Primitive primitive : this.primitives) {
        if (primitive == prim) {
            GL11.glDisable(GL11.GL_LIGHTING);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glColor4f(1.0f, 0.f, 0.f, 1.f);
            GL11.glBegin(GL11.GL_POINTS);
            GL11.glVertex3f(prim.x, prim.y, prim.z);
            GL11.glEnd();
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glColor4f(1.0f, 0.5f, 0.5f, 1.f);
        } else if (colored) {
            GL11.glColor4f(0.75f, 0.5f, 0.5f, 1.f);
        } else {
            GL11.glColor4f(1.f, 1.f, 1.f, 1.f);
        }
        primitive.render(tw, th);
    }
    for (ModelPiece child : this.children) {
        child.renderForEditor(piece, prim, highlightedPieces, tw, th);
    }
    GL11.glPopMatrix();
}

From source file:net.shadowmage.ancientwarfare.core.model.PrimitiveBox.java

License:Open Source License

@Override
protected void renderPrimitive(float tw, float th) {
    float px = 1.f / tw;
    float py = 1.f / th;
    float w = (float) Math.ceil((x2 - x1) * 16.f);
    float h = (float) Math.ceil((y2 - y1) * 16.f);
    float l = (float) Math.ceil((z2 - z1) * 16.f);
    float ty = this.ty();
    float tx = this.tx();

    float tx1, ty1, tx2, ty2;
    if (w < 1) {
        w = 1;/*from  w w  w .j a v a  2 s.com*/
    }
    if (h < 1) {
        h = 1;
    }
    if (l < 1) {
        l = 1;
    }

    //render the cube. only called a single time when building the display list for a piece
    if (rx != 0) {
        GL11.glRotatef(rx, 1, 0, 0);
    }
    if (ry != 0) {
        GL11.glRotatef(ry, 0, 1, 0);
    }
    if (rz != 0) {
        GL11.glRotatef(rz, 0, 0, 1);
    }

    GL11.glBegin(GL11.GL_QUADS);

    //front side  
    tx1 = (tx + l) * px;
    ty1 = (th - (ty + l + h)) * py;
    tx2 = (tx + l + w) * px;
    ty2 = (th - (ty + l)) * py;
    ty1 = 1.f - ty1;
    ty2 = 1.f - ty2;
    GL11.glNormal3f(0, 0, 1);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x1, y1, z2);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x2, y1, z2);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x2, y2, z2);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x1, y2, z2);

    ////rear side
    tx1 = (tx + l + l + w) * px;
    ty1 = (th - (ty + l + h)) * py;
    tx2 = (tx + l + w + l + w) * px;
    ty2 = (th - (ty + l)) * py;
    ty1 = 1.f - ty1;
    ty2 = 1.f - ty2;
    GL11.glNormal3f(0, 0, -1);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x2, y1, z1);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x1, y1, z1);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x1, y2, z1);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x2, y2, z1);

    //right side
    tx1 = (tx + l + w) * px;
    ty1 = (th - (ty + l + h)) * py;
    tx2 = (tx + l + w + l) * px;
    ty2 = (th - (ty + l)) * py;
    ty1 = 1.f - ty1;
    ty2 = 1.f - ty2;
    GL11.glNormal3f(-1, 0, 0);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x1, y1, z1);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x1, y1, z2);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x1, y2, z2);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x1, y2, z1);

    //  //left side
    tx1 = (tx) * px;
    ty1 = (th - (ty + l + h)) * py;
    tx2 = (tx + l) * px;
    ty2 = (th - (ty + l)) * py;
    ty1 = 1.f - ty1;
    ty2 = 1.f - ty2;
    GL11.glNormal3f(1, 0, 0);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x2, y1, z2);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x2, y1, z1);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x2, y2, z1);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x2, y2, z2);

    //  //top side
    tx1 = (tx + l) * px;
    ty1 = (th - (ty + l)) * py;
    tx2 = (tx + l + w) * px;
    ty2 = (th - (ty)) * py;
    ty1 = 1.f - ty1;
    ty2 = 1.f - ty2;
    GL11.glNormal3f(0, 1, 0);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x2, y2, z1);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x1, y2, z1);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x1, y2, z2);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x2, y2, z2);

    //  //bottom side
    tx1 = (tx + l + w) * px;
    ty1 = (th - (ty + l)) * py;
    tx2 = (tx + l + w + w) * px;
    ty2 = (th - (ty)) * py;
    ty1 = 1.f - ty1;
    ty2 = 1.f - ty2;
    GL11.glNormal3f(0, -1, 0);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x2, y1, z2);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x1, y1, z2);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x1, y1, z1);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x2, y1, z1);

    GL11.glEnd();
}

From source file:net.shadowmage.ancientwarfare.core.model.PrimitiveQuad.java

License:Open Source License

@Override
protected void renderPrimitive(float tw, float th) {
    float px = 1.f / tw;
    float py = 1.f / th;
    float w = (x2 - x1) * 16.f;
    float l = 1.f;//TODO fix this for proper texture handling
    float h = (y2 - y1) * 16.f;
    float ty = this.ty();
    float tx = this.tx();

    float tx1, ty1, tx2, ty2;

    //render the cube. only called a single time when building the display list for a piece
    if (rx != 0) {
        GL11.glRotatef(rx, 1, 0, 0);/*from  ww  w . j av  a  2s.c om*/
    }
    if (ry != 0) {
        GL11.glRotatef(ry, 0, 1, 0);
    }
    if (rz != 0) {
        GL11.glRotatef(rz, 0, 0, 1);
    }

    GL11.glBegin(GL11.GL_QUADS);

    //front side  
    tx1 = (tx + l) * px;
    ty1 = (th - (ty + l + h)) * py;
    tx2 = (tx + l + w) * px;
    ty2 = (th - (ty + l)) * py;

    GL11.glNormal3f(0, 0, 1);
    GL11.glTexCoord2f(tx1, ty1);
    GL11.glVertex3f(x1, y1, 0.f);
    GL11.glTexCoord2f(tx2, ty1);
    GL11.glVertex3f(x2, y1, 0.f);
    GL11.glTexCoord2f(tx2, ty2);
    GL11.glVertex3f(x2, y2, 0.f);
    GL11.glTexCoord2f(tx1, ty2);
    GL11.glVertex3f(x1, y2, 0.f);

    GL11.glEnd();
}