Example usage for org.lwjgl.opengl GL11 GL_FLAT

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

Introduction

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

Prototype

int GL_FLAT

To view the source code for org.lwjgl.opengl GL11 GL_FLAT.

Click Source Link

Document

ShadingModel

Usage

From source file:org.jtrfp.mtmx.tools.internal.WorldViewerConfiguration.java

License:Open Source License

@Override
public void initLight() {
    GL11.glEnable(GL11.GL_LIGHTING);/* w  w  w .j a va2s  . co  m*/

    // XXX: FloatBuffer must have 4 additional floats free
    float[] amb = new float[] { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
    FloatBuffer ambientBuffer = EngineUtil.createFloatBuffer(amb);
    GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, ambientBuffer);

    // XXX: FloatBuffer must have 4 additional floats free
    float[] vec = new float[] { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
    FloatBuffer diffBuffer = EngineUtil.createFloatBuffer(vec);
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, diffBuffer);
    GL11.glEnable(GL11.GL_LIGHT0);

    GL11.glShadeModel(GL11.GL_FLAT);
}

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

License:Open Source License

private void drawCylinder(float l, float r, float zoffset) {
    int i;//from w  w  w.  j  a v  a  2s .  c o 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);//www. j  a v  a2s  . 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);//w  w  w . jav a 2  s  .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);//from  ww  w .j av  a  2s.  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

@Override
//   void dsDrawFrame (int width, int height, dsFunctions *fn, int pause)
void dsDrawFrame(int width, int height, dsFunctions fn, boolean pause) {
    if (current_state < 1)
        dsDebug("internal error");
    current_state = 2;//from  w  w  w.  j  av  a 2  s .c  o  m

    // setup stuff
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_LIGHT0);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glCullFace(GL11.GL_BACK);
    GL11.glFrontFace(GL11.GL_CCW);

    // setup viewport
    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    final float vnear = 0.1f;
    final float vfar = 100.0f;
    final float k = 0.8f; // view scale, 1 = +/- 45 degrees
    if (width >= height) {
        float k2 = (float) height / (float) width;
        GL11.glFrustum(-vnear * k, vnear * k, -vnear * k * k2, vnear * k * k2, vnear, vfar);
    } else {
        float k2 = (float) width / (float) height;
        GL11.glFrustum(-vnear * k * k2, vnear * k * k2, -vnear * k, vnear * k, vnear, vfar);
    }

    // setup lights. it makes a difference whether this is done in the
    // GL_PROJECTION matrix mode (lights are scene relative) or the
    // GL_MODELVIEW matrix mode (lights are camera relative, bad!).
    //      static GLfloat light_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
    //      static GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    //      static GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, light_ambient);
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, light_diffuse);
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, light_specular);
    GL11.glColor3f(1.0f, 1.0f, 1.0f);

    // clear the window
    GL11.glClearColor(0.5f, 0.5f, 0.5f, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    // snapshot camera position (in MS Windows it is changed by the GUI thread)
    float[] view2_xyz = view_xyz.clone();
    float[] view2_rxyz = view_rxyz.clone();
    //      memcpy (view2_xyz,view_xyz);//,sizeof(float)*3);
    //      memcpy (view2_hpr,view_hpr);//,sizeof(float)*3);

    // go to GL_MODELVIEW matrix mode and set the camera
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    setCamera(view2_xyz[0], view2_xyz[1], view2_xyz[2], view2_rxyz[0], view2_rxyz[1], view2_rxyz[2]);

    // set the light position (for some reason we have to do this in model view.
    //      static GLfloat light_position[] = { LIGHTX, LIGHTY, 1.0, 0.0 };
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, light_position);

    // draw the background (ground, sky etc)
    drawSky(view2_xyz);
    drawGround();

    // draw the little markers on the ground
    drawPyramidGrid();

    // leave openGL in a known state - flat shaded white, no textures
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glColor3f(1, 1, 1);
    setColor(1, 1, 1, 1);

    // draw the rest of the objects. set drawing state first.
    color[0] = 1;
    color[1] = 1;
    color[2] = 1;
    color[3] = 1;
    tnum = DS_TEXTURE_NUMBER.DS_NONE;
    //if (fn.step) 
    fn.step(pause);
}

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

License:Open Source License

@Override
public void dsDrawBox(final float[] pos, final float[] R, final float[] sides) {
    if (current_state != 2)
        dsError("drawing function called outside simulation loop");
    setupDrawingMode();/*  www .  j  av  a 2s.  co m*/
    GL11.glShadeModel(GL11.GL_FLAT);
    setTransform(pos, R);
    drawBox(sides);
    GL11.glPopMatrix();

    if (use_shadows) {
        setShadowDrawingMode();
        setShadowTransform();
        setTransform(pos, R);
        drawBox(sides);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
        GL11.glDepthRange(0, 1);
    }
}

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

License:Open Source License

void dsDrawConvex(final float[] pos, final float[] R, float[] _planes, int _planecount, float[] _points,
        int _pointcount, int[] _polygons) {
    if (current_state != 2)
        dsError("drawing function called outside simulation loop");
    setupDrawingMode();// w  w w  . j  a  v  a2  s.  c om
    GL11.glShadeModel(GL11.GL_FLAT);
    setTransform(pos, R);
    drawConvex(_planes, _planecount, _points, _pointcount, _polygons);
    GL11.glPopMatrix();
    if (use_shadows) {
        setShadowDrawingMode();
        setShadowTransform();
        setTransform(pos, R);
        drawConvex(_planes, _planecount, _points, _pointcount, _polygons);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
        GL11.glDepthRange(0, 1);
    }
}

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

License:Open Source License

@Override
public void dsDrawSphere(final float[] pos, final float[] R, float radius) {
    if (current_state != 2)
        dsError("drawing function called outside simulation loop");
    setupDrawingMode();/*w  ww .j  a  va 2 s  .  c om*/
    GL11.glEnable(GL11.GL_NORMALIZE);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    setTransform(pos, R);
    GL11.glScaled(radius, radius, radius);
    drawSphere();
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_NORMALIZE);

    // draw shadows
    if (use_shadows) {
        GL11.glDisable(GL11.GL_LIGHTING);
        if (use_textures) {
            ground_texture.bind(true);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
            GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
            GL11.glColor3f(SHADOW_INTENSITY, SHADOW_INTENSITY, SHADOW_INTENSITY);
        } else {
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glColor3f(GROUND_R * SHADOW_INTENSITY, GROUND_G * SHADOW_INTENSITY,
                    GROUND_B * SHADOW_INTENSITY);
        }
        GL11.glShadeModel(GL11.GL_FLAT);
        GL11.glDepthRange(0, 0.9999);
        drawSphereShadow(pos[0], pos[1], pos[2], radius);
        GL11.glDepthRange(0, 1);
    }
}

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

License:Open Source License

void dsDrawTriangle(final float[] pos, final float[] R, final float[] v0, final float[] v1, final float[] v2,
        boolean solid) {
    if (current_state != 2)
        dsError("drawing function called outside simulation loop");
    setupDrawingMode();/*  w  w  w  .  j  a  v  a2  s.c o  m*/
    GL11.glShadeModel(GL11.GL_FLAT);
    setTransform(pos, R);
    drawTriangle(v0, v1, v2, solid);
    GL11.glPopMatrix();
}