Example usage for org.lwjgl.opengl GL11 glEnd

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

Introduction

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

Prototype

public static native void glEnd();

Source Link

Document

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

Usage

From source file:org.mkdev.ai.langton3d.misc.GLUT.java

License:GNU General Public License

public static void drawBox(double size, int type) {

    float v[][] = new float[8][3];
    float sz = (float) size;
    int i;/*from w  w  w .ja  v  a 2  s . c  o m*/

    v[0][0] = v[1][0] = v[2][0] = v[3][0] = -sz / 2.0f;
    v[4][0] = v[5][0] = v[6][0] = v[7][0] = sz / 2.0f;
    v[0][1] = v[1][1] = v[4][1] = v[5][1] = -sz / 2.0f;
    v[2][1] = v[3][1] = v[6][1] = v[7][1] = sz / 2.0f;
    v[0][2] = v[3][2] = v[4][2] = v[7][2] = -sz / 2.0f;
    v[1][2] = v[2][2] = v[5][2] = v[6][2] = sz / 2.0f;

    for (i = 5; i >= 0; i--) {
        GL11.glBegin(type);

        GL11.glNormal3f(CUBE_NORMALS[i][0], CUBE_NORMALS[i][1], CUBE_NORMALS[i][2]);
        GL11.glVertex3f(v[CUBE_FACES[i][0]][0], v[CUBE_FACES[i][0]][1], v[CUBE_FACES[i][0]][2]);
        GL11.glVertex3f(v[CUBE_FACES[i][1]][0], v[CUBE_FACES[i][1]][1], v[CUBE_FACES[i][1]][2]);
        GL11.glVertex3f(v[CUBE_FACES[i][2]][0], v[CUBE_FACES[i][2]][1], v[CUBE_FACES[i][2]][2]);
        GL11.glVertex3f(v[CUBE_FACES[i][3]][0], v[CUBE_FACES[i][3]][1], v[CUBE_FACES[i][3]][2]);

        GL11.glEnd();
    }
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawConvex(float[] _planes, int _planecount, float[] _points, int _pointcount, int[] _polygons) {
    //unsigned /*from  w  w  w.  j a  v a  2  s. c om*/
    int polyindex = 0;
    for (int i = 0; i < _planecount; ++i) {
        //unsigned 
        int pointcount = _polygons[polyindex];
        polyindex++;
        GL11.glBegin(GL11.GL_POLYGON);
        GL11.glNormal3f(_planes[(i * 4) + 0], _planes[(i * 4) + 1], _planes[(i * 4) + 2]);
        for (int j = 0; j < pointcount; ++j) {
            GL11.glVertex3f(_points[_polygons[polyindex] * 3], _points[(_polygons[polyindex] * 3) + 1],
                    _points[(_polygons[polyindex] * 3) + 2]);
            polyindex++;
        }
        GL11.glEnd();
    }
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawConvexD(double[] _planes, int _planecount, double[] _points, int _pointcount,
        int[] _polygons) {
    //unsigned //from   ww w.  j a va 2 s . c om
    int polyindex = 0;
    for (int i = 0; i < _planecount; ++i) {
        //unsigned 
        int pointcount = _polygons[polyindex];
        polyindex++;
        GL11.glBegin(GL11.GL_POLYGON);
        GL11.glNormal3d(_planes[(i * 4) + 0], _planes[(i * 4) + 1], _planes[(i * 4) + 2]);
        for (int j = 0; j < pointcount; ++j) {
            GL11.glVertex3d(_points[_polygons[polyindex] * 3], _points[(_polygons[polyindex] * 3) + 1],
                    _points[(_polygons[polyindex] * 3) + 2]);
            polyindex++;
        }
        GL11.glEnd();
    }
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawBox(final float[] sides) {
    float lx = sides[0] * 0.5f;
    float ly = sides[1] * 0.5f;
    float lz = sides[2] * 0.5f;

    // sides//  w  ww. j  a va  2 s . c  o  m
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glNormal3f(-1, 0, 0);
    GL11.glVertex3f(-lx, -ly, -lz);
    GL11.glVertex3f(-lx, -ly, lz);
    GL11.glVertex3f(-lx, ly, -lz);
    GL11.glVertex3f(-lx, ly, lz);
    GL11.glNormal3f(0, 1, 0);
    GL11.glVertex3f(lx, ly, -lz);
    GL11.glVertex3f(lx, ly, lz);
    GL11.glNormal3f(1, 0, 0);
    GL11.glVertex3f(lx, -ly, -lz);
    GL11.glVertex3f(lx, -ly, lz);
    GL11.glNormal3f(0, -1, 0);
    GL11.glVertex3f(-lx, -ly, -lz);
    GL11.glVertex3f(-lx, -ly, lz);
    GL11.glEnd();

    // top face
    GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    GL11.glNormal3f(0, 0, 1);
    GL11.glVertex3f(-lx, -ly, lz);
    GL11.glVertex3f(lx, -ly, lz);
    GL11.glVertex3f(lx, ly, lz);
    GL11.glVertex3f(-lx, ly, lz);
    GL11.glEnd();

    // bottom face
    GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    GL11.glNormal3f(0, 0, -1);
    GL11.glVertex3f(-lx, -ly, -lz);
    GL11.glVertex3f(-lx, ly, -lz);
    GL11.glVertex3f(lx, ly, -lz);
    GL11.glVertex3f(lx, -ly, -lz);
    GL11.glEnd();
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawSphere() {
    // icosahedron data for an icosahedron of radius 1.0
    //      # define ICX 0.525731112119133606f
    //      # define ICZ 0.850650808352039932f
    if (listnum == 0) {
        listnum = GL11.glGenLists(1);/*from  w  w  w  .  j a  va 2 s  .c  om*/
        GL11.glNewList(listnum, GL11.GL_COMPILE);
        GL11.glBegin(GL11.GL_TRIANGLES);
        for (int i = 0; i < 20; i++) {
            //            drawPatch (&idata[index[i][2]][0],&idata[index[i][1]][0],
            //                  &idata[index[i][0]][0],sphere_quality);
            drawPatch(idata[index[i][2]], idata[index[i][1]], idata[index[i][0]], sphere_quality);
        }
        GL11.glEnd();
        GL11.glEndList();
    }
    GL11.glCallList(listnum);
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawSphereShadow(float px, float py, float pz, float radius) {
    // calculate shadow constants based on light vector
    if (!init) {//from w  w w. j  ava 2  s  .c om
        len2 = LIGHTX * LIGHTX + LIGHTZ * LIGHTZ;
        len1 = 1.0f / (float) Math.sqrt(len2);
        scale = (float) Math.sqrt(len2 + 1);
        init = true;
    }

    // map sphere center to ground plane based on light vector
    px -= LIGHTX * py;
    pz -= LIGHTZ * py;

    final float kx = 0.96592582628907f;
    final float kz = 0.25881904510252f;
    float x = radius, z = 0;

    GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    for (int i = 0; i < 24; i++) {
        // for all points on circle, scale to elongated rotated shadow and draw
        float x2 = (LIGHTX * x * scale - LIGHTZ * z) * len1 + px;
        float z2 = (LIGHTZ * x * scale + LIGHTX * z) * len1 + pz;
        GL11.glTexCoord2f(x2 * ground_scale + ground_ofsx, z2 * ground_scale + ground_ofsz);
        GL11.glVertex3f(x2, 0, z2);

        // rotate [x,y] vector
        float xtmp = kx * x - kz * z;
        z = kz * x + kx * z;
        x = xtmp;
    }
    GL11.glEnd();
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawTriangle(final float[] vAll, final int v0, final int v1, final int v2, boolean solid) {
    float[] u = new float[3], v = new float[3], normal = new float[3];
    u[0] = vAll[v1] - vAll[v0];//v1[0] - v0[0];
    u[1] = vAll[v1 + 1] - vAll[v0 + 1];//v1[1] - v0[1];
    u[2] = vAll[v1 + 2] - vAll[v0 + 2];//v1[2] - v0[2];
    v[0] = vAll[v2] - vAll[v0];//v2[0] - v0[0];
    v[1] = vAll[v2 + 1] - vAll[v0 + 1];//v2[1] - v0[1];
    v[2] = vAll[v2 + 2] - vAll[v0 + 2];//v2[2] - v0[2];
    crossProduct3(normal, u, v);// w  w w.j a v  a 2  s. c  o  m
    normalizeVector3(normal);

    GL11.glBegin(solid ? GL11.GL_TRIANGLES : GL11.GL_LINE_STRIP);
    GL11.glNormal3f(normal[0], normal[1], normal[2]);
    GL11.glVertex3f(vAll[v0], vAll[v0 + 1], vAll[v0 + 2]);//, v0[0], v0[1], v0[2]);
    GL11.glVertex3f(vAll[v1], vAll[v1 + 1], vAll[v1 + 2]);//v1[0], v1[1], v1[2]);
    GL11.glVertex3f(vAll[v2], vAll[v2 + 1], vAll[v2 + 2]);//v2[0], v2[1], v2[2]);
    GL11.glEnd();
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawTriangle(final float[] v0, final float[] v1, final float[] v2, boolean solid) {
    float[] u = new float[3], v = new float[3], normal = new float[3];
    u[0] = v1[0] - v0[0];/*from w ww  . jav  a  2 s  .c om*/
    u[1] = v1[1] - v0[1];
    u[2] = v1[2] - v0[2];
    v[0] = v2[0] - v0[0];
    v[1] = v2[1] - v0[1];
    v[2] = v2[2] - v0[2];
    crossProduct3(normal, u, v);
    normalizeVector3(normal);

    GL11.glBegin(solid ? GL11.GL_TRIANGLES : GL11.GL_LINE_STRIP);
    GL11.glNormal3f(normal[0], normal[1], normal[2]);
    GL11.glVertex3f(v0[0], v0[1], v0[2]);
    GL11.glVertex3f(v1[0], v1[1], v1[2]);
    GL11.glVertex3f(v2[0], v2[1], v2[2]);
    GL11.glEnd();
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawTriangle(final DVector3C v0, final DVector3C v1, final DVector3C v2, boolean solid) {
    float[] u = new float[3], v = new float[3], normal = new float[3];
    u[0] = (float) (v1.get0() - v0.get0());
    u[1] = (float) (v1.get1() - v0.get1());
    u[2] = (float) (v1.get2() - v0.get2());
    v[0] = (float) (v2.get0() - v0.get0());
    v[1] = (float) (v2.get1() - v0.get1());
    v[2] = (float) (v2.get2() - v0.get2());
    crossProduct3(normal, u, v);// ww w  . j  a  va  2s  .com
    normalizeVector3(normal);

    GL11.glBegin(solid ? GL11.GL_TRIANGLES : GL11.GL_LINE_STRIP);
    GL11.glNormal3f(normal[0], normal[1], normal[2]);
    GL11.glVertex3d(v0.get0(), v0.get1(), v0.get2());
    GL11.glVertex3d(v1.get0(), v1.get1(), v1.get2());
    GL11.glVertex3d(v2.get0(), v2.get1(), v2.get2());
    GL11.glEnd();
}

From source file:org.ode4j.drawstuff.internal.DrawStuffGL.java

License:Open Source License

private void drawCapsule(float l, float r) {
    int i, j;//from   www. ja va2  s. com
    float tmp, nx, ny, nz, start_nx, start_ny, a, ca, sa;
    // number of sides to the cylinder (divisible by 4):
    final int n = capped_cylinder_quality * 4;

    l *= 0.5;
    a = (float) ((M_PI * 2.0) / n);
    sa = (float) Math.sin(a);
    ca = (float) Math.cos(a);

    // draw cylinder body
    ny = 1;
    nz = 0; // normal vector = (0,ny,nz)
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    for (i = 0; i <= n; i++) {
        GL11.glNormal3d(ny, nz, 0);
        GL11.glVertex3d(ny * r, nz * r, l);
        GL11.glNormal3d(ny, nz, 0);
        GL11.glVertex3d(ny * r, nz * r, -l);
        // rotate ny,nz
        tmp = ca * ny - sa * nz;
        nz = sa * ny + ca * nz;
        ny = tmp;
    }
    GL11.glEnd();

    // draw first cylinder cap
    start_nx = 0;
    start_ny = 1;
    for (j = 0; j < (n / 4); j++) {
        // get start_n2 = rotated start_n
        float start_nx2 = ca * start_nx + sa * start_ny;
        float start_ny2 = -sa * start_nx + ca * start_ny;
        // get n=start_n and n2=start_n2
        nx = start_nx;
        ny = start_ny;
        nz = 0;
        float nx2 = start_nx2, ny2 = start_ny2, nz2 = 0;
        GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
        for (i = 0; i <= n; i++) {
            GL11.glNormal3d(ny2, nz2, nx2);
            GL11.glVertex3d(ny2 * r, nz2 * r, l + nx2 * r);
            GL11.glNormal3d(ny, nz, nx);
            GL11.glVertex3d(ny * r, nz * r, l + nx * r);
            // rotate n,n2
            tmp = ca * ny - sa * nz;
            nz = sa * ny + ca * nz;
            ny = tmp;
            tmp = ca * ny2 - sa * nz2;
            nz2 = sa * ny2 + ca * nz2;
            ny2 = tmp;
        }
        GL11.glEnd();
        start_nx = start_nx2;
        start_ny = start_ny2;
    }

    // draw second cylinder cap
    start_nx = 0;
    start_ny = 1;
    for (j = 0; j < (n / 4); j++) {
        // get start_n2 = rotated start_n
        float start_nx2 = ca * start_nx - sa * start_ny;
        float start_ny2 = sa * start_nx + ca * start_ny;
        // get n=start_n and n2=start_n2
        nx = start_nx;
        ny = start_ny;
        nz = 0;
        float nx2 = start_nx2, ny2 = start_ny2, nz2 = 0;
        GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
        for (i = 0; i <= n; i++) {
            GL11.glNormal3d(ny, nz, nx);
            GL11.glVertex3d(ny * r, nz * r, -l + nx * r);
            GL11.glNormal3d(ny2, nz2, nx2);
            GL11.glVertex3d(ny2 * r, nz2 * r, -l + nx2 * r);
            // rotate n,n2
            tmp = ca * ny - sa * nz;
            nz = sa * ny + ca * nz;
            ny = tmp;
            tmp = ca * ny2 - sa * nz2;
            nz2 = sa * ny2 + ca * nz2;
            ny2 = tmp;
        }
        GL11.glEnd();
        start_nx = start_nx2;
        start_ny = start_ny2;
    }
}