Example usage for org.lwjgl.opengl GL11 glVertex3f

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

Introduction

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

Prototype

public static native void glVertex3f(@NativeType("GLfloat") float x, @NativeType("GLfloat") float y,
        @NativeType("GLfloat") float z);

Source Link

Document

Specifies a single vertex between #glBegin Begin and #glEnd End by giving its coordinates in three dimensions.

Usage

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

License:Open Source License

private void drawPatch(float[] p1, float[] p2, float[] p3, int level) {
    int i;/*from ww  w . ja  va 2s .  c o  m*/
    if (level > 0) {
        float[] q1 = new float[3], q2 = new float[3], q3 = new float[3]; // sub-vertices
        for (i = 0; i < 3; i++) {
            q1[i] = 0.5f * (p1[i] + p2[i]);
            q2[i] = 0.5f * (p2[i] + p3[i]);
            q3[i] = 0.5f * (p3[i] + p1[i]);
        }
        float length1 = (float) (1.0 / Math.sqrt(q1[0] * q1[0] + q1[1] * q1[1] + q1[2] * q1[2]));
        float length2 = (float) (1.0 / Math.sqrt(q2[0] * q2[0] + q2[1] * q2[1] + q2[2] * q2[2]));
        float length3 = (float) (1.0 / Math.sqrt(q3[0] * q3[0] + q3[1] * q3[1] + q3[2] * q3[2]));
        for (i = 0; i < 3; i++) {
            q1[i] *= length1;
            q2[i] *= length2;
            q3[i] *= length3;
        }
        drawPatch(p1, q1, q3, level - 1);
        drawPatch(q1, p2, q2, level - 1);
        drawPatch(q1, q2, q3, level - 1);
        drawPatch(q3, q2, p3, level - 1);
    } else {
        GL11.glNormal3f(p1[0], p1[1], p1[2]);
        GL11.glVertex3f(p1[0], p1[1], p1[2]);
        GL11.glNormal3f(p2[0], p2[1], p2[2]);
        GL11.glVertex3f(p2[0], p2[1], p2[2]);
        GL11.glNormal3f(p3[0], p3[1], p3[2]);
        GL11.glVertex3f(p3[0], p3[1], p3[2]);
    }
}

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) {/*  ww  w  . j a  v  a  2s  .  co  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);//w ww.  j  a v 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.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  .  j a v  a 2  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 drawSky(float[] view_xyz) {
    GL11.glDisable(GL11.GL_LIGHTING);/*ww  w .j av  a 2s.  co 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);//from  w w  w  .  j a va 2s.  c o  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);//ww  w .j ava2  s.  c  o  m
    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();
        }
    }
}

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

License:Open Source License

/** 
 * @see DrawStuffApi#dsDrawLine(float[], float[])
 *///from   ww w  . jav a  2 s.  co m
@Override
public void dsDrawLine(final float[] pos1, final float[] pos2) {
    setupDrawingMode();
    GL11.glColor3f(color[0], color[1], color[2]);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glLineWidth(2);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex3f(pos1[0], pos1[1], pos1[2]);
    GL11.glVertex3f(pos2[0], pos2[1], pos2[2]);
    GL11.glEnd();
}

From source file:org.spout.engine.batcher.GL11SpriteBatch.java

License:Open Source License

public void render() {
    GL11.glDisable(GL11.GL_DEPTH_TEST);//  w  ww  . j  a  v a 2 s . c o  m

    for (int i = 0; i < sprites.size(); i++) {
        RenderPart rect = sprites.get(i);

        rect.getRenderMaterial().getShader().setUniform("View", this.view);
        rect.getRenderMaterial().getShader().setUniform("Projection", this.projection);
        rect.getRenderMaterial().getShader().setUniform("Model", this.view); //View is always an identity matrix.

        rect.getRenderMaterial().assign();

        GL11.glBegin(GL11.GL_TRIANGLES);

        float r = (float) rect.getColor().getRed() / 255f;
        float g = (float) rect.getColor().getGreen() / 255f;
        float b = (float) rect.getColor().getBlue() / 255f;
        float a = (float) rect.getColor().getAlpha() / 255f;

        GL11.glColor4f(r, g, b, a);
        GL11.glTexCoord2f(rect.getSource().getX(), rect.getSource().getY());
        GL11.glVertex3f(rect.getSprite().getX(), rect.getSprite().getY() + rect.getSprite().getHeight(), 0.f);

        GL11.glColor4f(r, g, b, a);
        GL11.glTexCoord2f(rect.getSource().getX(), rect.getSource().getY() + rect.getSource().getHeight());
        GL11.glVertex3f(rect.getSprite().getX(), rect.getSprite().getY(), 0.f);

        GL11.glColor4f(r, g, b, a);
        GL11.glTexCoord2f(rect.getSource().getX() + rect.getSource().getWidth(),
                rect.getSource().getY() + rect.getSource().getHeight());
        GL11.glVertex3f(rect.getSprite().getX() + rect.getSprite().getWidth(), rect.getSprite().getY(), 0.f);

        GL11.glColor4f(r, g, b, a);
        GL11.glTexCoord2f(rect.getSource().getX(), rect.getSource().getY());
        GL11.glVertex3f(rect.getSprite().getX(), rect.getSprite().getY() + rect.getSprite().getHeight(), 0.f);

        GL11.glColor4f(r, g, b, a);
        GL11.glTexCoord2f(rect.getSource().getX() + rect.getSource().getWidth(),
                rect.getSource().getY() + rect.getSource().getHeight());
        GL11.glVertex3f(rect.getSprite().getX() + rect.getSprite().getWidth(), rect.getSprite().getY(), 0.f);

        GL11.glColor4f(r, g, b, a);
        GL11.glTexCoord2f(rect.getSource().getX() + rect.getSource().getWidth(), rect.getSource().getY());
        GL11.glVertex3f(rect.getSprite().getX() + rect.getSprite().getWidth(),
                rect.getSprite().getY() + rect.getSprite().getHeight(), 0.f);

        GL11.glEnd();
    }
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

From source file:org.terasology.componentSystem.BlockParticleEmitterSystem.java

License:Apache License

private void drawParticle(byte blockType) {
    Block b = BlockManager.getInstance().getBlock(blockType);

    glBegin(GL_QUADS);/* w  w w .  ja  v a2 s  .  c o  m*/
    GL11.glTexCoord2f(b.getTextureOffsetFor(BlockPart.FRONT).x, b.getTextureOffsetFor(BlockPart.FRONT).y);
    GL11.glVertex3f(-0.5f, -0.5f, 0.0f);

    GL11.glTexCoord2f(b.getTextureOffsetFor(BlockPart.FRONT).x + TEX_SIZE,
            b.getTextureOffsetFor(BlockPart.FRONT).y);
    GL11.glVertex3f(0.5f, -0.5f, 0.0f);

    GL11.glTexCoord2f(b.getTextureOffsetFor(BlockPart.FRONT).x + TEX_SIZE,
            b.getTextureOffsetFor(BlockPart.FRONT).y + TEX_SIZE);
    GL11.glVertex3f(0.5f, 0.5f, 0.0f);

    GL11.glTexCoord2f(b.getTextureOffsetFor(BlockPart.FRONT).x,
            b.getTextureOffsetFor(BlockPart.FRONT).y + TEX_SIZE);
    GL11.glVertex3f(-0.5f, 0.5f, 0.0f);
    glEnd();

}