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: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  ww  w .  j  a  v a2s .  c  o  m*/
        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);/*from   w  ww .  j a v a 2s  .  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 w  w . java2  s.  com
    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);//from  w w  w.  j av  a2  s .  co  m
    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 ww  w  .java2s  .  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;
    }
}

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

License:Open Source License

private void drawCylinder(float l, float r, float zoffset) {
    int i;// ww w  .  ja v  a 2s.  co  m
    float tmp, ny, nz, a, ca, sa;
    final int n = 24; // number of sides to the cylinder (divisible by 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 + zoffset);
        GL11.glNormal3d(ny, nz, 0);
        GL11.glVertex3d(ny * r, nz * r, -l + zoffset);
        // rotate ny,nz
        tmp = ca * ny - sa * nz;
        nz = sa * ny + ca * nz;
        ny = tmp;
    }
    GL11.glEnd();

    // draw top cap
    GL11.glShadeModel(GL11.GL_FLAT);
    ny = 1;
    nz = 0; // normal vector = (0,ny,nz)
    GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    GL11.glNormal3d(0, 0, 1);
    GL11.glVertex3d(0, 0, l + zoffset);
    for (i = 0; i <= n; i++) {
        if (i == 1 || i == n / 2 + 1)
            setColor(color[0] * 0.75f, color[1] * 0.75f, color[2] * 0.75f, color[3]);
        GL11.glNormal3d(0, 0, 1);
        GL11.glVertex3d(ny * r, nz * r, l + zoffset);
        if (i == 1 || i == n / 2 + 1)
            setColor(color[0], color[1], color[2], color[3]);

        // rotate ny,nz
        tmp = ca * ny - sa * nz;
        nz = sa * ny + ca * nz;
        ny = tmp;
    }
    GL11.glEnd();

    // draw bottom cap
    ny = 1;
    nz = 0; // normal vector = (0,ny,nz)
    GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    GL11.glNormal3d(0, 0, -1);
    GL11.glVertex3d(0, 0, -l + zoffset);
    for (i = 0; i <= n; i++) {
        if (i == 1 || i == n / 2 + 1)
            setColor(color[0] * 0.75f, color[1] * 0.75f, color[2] * 0.75f, color[3]);
        GL11.glNormal3d(0, 0, -1);
        GL11.glVertex3d(ny * r, nz * r, -l + zoffset);
        if (i == 1 || i == n / 2 + 1)
            setColor(color[0], color[1], color[2], color[3]);

        // rotate ny,nz
        tmp = ca * ny + sa * nz;
        nz = -sa * ny + ca * nz;
        ny = tmp;
    }
    GL11.glEnd();
}

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

License:Open Source License

private void drawSky(float[] view_xyz) {
    GL11.glDisable(GL11.GL_LIGHTING);// ww  w  .  j a  v a2  s. c o  m
    if (use_textures) {
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        sky_texture.bind(false);
    } else {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glColor3f(0f, 0.5f, 1.0f);
    }

    // make sure sky depth is as far back as possible
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glDepthRange(1, 1);

    final float ssize = 1000.0f;

    float x = ssize * sky_scale;
    float y = view_xyz[1] + sky_height;

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glNormal3f(0, -1, 0);
    GL11.glTexCoord2f(x + offset, -x + offset);
    GL11.glVertex3f(ssize + view_xyz[0], y, -ssize + view_xyz[2]);
    GL11.glTexCoord2f(x + offset, x + offset);
    GL11.glVertex3f(ssize + view_xyz[0], y, ssize + view_xyz[2]);
    GL11.glTexCoord2f(-x + offset, x + offset);
    GL11.glVertex3f(-ssize + view_xyz[0], y, ssize + view_xyz[2]);
    GL11.glTexCoord2f(-x + offset, -x + offset);
    GL11.glVertex3f(-ssize + view_xyz[0], y, -ssize + view_xyz[2]);
    GL11.glEnd();

    offset = offset + 0.002f;
    if (offset > 1)
        offset -= 1;

    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glDepthRange(0, 1);
}

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

License:Open Source License

private void drawGround() {
    GL11.glDisable(GL11.GL_LIGHTING);/* www .ja va  2  s . co m*/
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    // GL11.glDepthRange (1,1);

    if (use_textures) {
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        ground_texture.bind(false);
    } else {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glColor3f(GROUND_R, GROUND_G, GROUND_B);
    }

    // ground fog seems to cause problems with TNT2 under windows
    /*
    GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1};
    GL11.glEnable (GL_FOG);
    GL11.glFogi (GL_FOG_MODE, GL_EXP2);
    GL11.glFogfv (GL_FOG_COLOR, fogColor);
    GL11.glFogf (GL_FOG_DENSITY, 0.05f);
    GL11.glHint (GL_FOG_HINT, GL_NICEST); // GL_DONT_CARE);
    GL11.glFogf (GL_FOG_START, 1.0);
    GL11.glFogf (GL_FOG_END, 5.0);
     */

    final float gsize = 100.0f;
    final float offset = 0; // -0.001f; ... polygon offsetting doesn't work well

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glNormal3f(0, 1, 0);

    GL11.glTexCoord2f(-gsize * ground_scale + ground_ofsx, gsize * ground_scale + ground_ofsz);
    GL11.glVertex3f(-gsize, offset, gsize);
    GL11.glTexCoord2f(gsize * ground_scale + ground_ofsx, gsize * ground_scale + ground_ofsz);
    GL11.glVertex3f(gsize, offset, gsize);
    GL11.glTexCoord2f(gsize * ground_scale + ground_ofsx, -gsize * ground_scale + ground_ofsz);
    GL11.glVertex3f(gsize, offset, -gsize);
    GL11.glTexCoord2f(-gsize * ground_scale + ground_ofsx, -gsize * ground_scale + ground_ofsz);
    GL11.glVertex3f(-gsize, offset, -gsize);
    GL11.glEnd();

    GL11.glDisable(GL11.GL_FOG);
}

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

License:Open Source License

private void drawPyramidGrid() {
    // setup stuff
    GL11.glEnable(GL11.GL_LIGHTING);//from  ww  w .  java  2s. c  om
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);

    // draw the pyramid grid
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            GL11.glPushMatrix();
            GL11.glTranslatef(i, 0, j);
            if (i == 1 && j == 0)
                setColor(1, 0, 0, 1);
            else if (i == 0 && j == 1)
                setColor(0, 0, 1, 1);
            else
                setColor(1, 1, 0, 1);
            final float k = 0.03f;
            GL11.glBegin(GL11.GL_TRIANGLE_FAN);
            GL11.glNormal3f(0, 1, -1);
            GL11.glVertex3f(0, k, 0);
            GL11.glVertex3f(-k, 0, -k);
            GL11.glVertex3f(k, 0, -k);
            GL11.glNormal3f(1, 1, 0);
            GL11.glVertex3f(k, 0, k);
            GL11.glNormal3f(0, 1, 1);
            GL11.glVertex3f(-k, 0, k);
            GL11.glNormal3f(-1, 1, 0);
            GL11.glVertex3f(-k, 0, -k);
            GL11.glEnd();
            GL11.glPopMatrix();
        }
    }
}