示例#1
0
  /** @see OpenGLTab#init() */
  void init() {
    GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    // fog color should be the same as the clear color
    // to look appropriate
    float[] fogColor = {1.0f, 1.0f, 1.0f, 1.0f};
    GL.glFogfv(GL.GL_FOG_COLOR, fogColor);
    GL.glHint(GL.GL_FOG_HINT, GL.GL_DONT_CARE);
    GL.glFogf(GL.GL_FOG_START, 0);
    GL.glFogf(GL.GL_FOG_DENSITY, 0.0f);
    // set the end of the start distance; anything > 15
    // units from the camera will be covered in fog
    GL.glFogf(GL.GL_FOG_END, 15);
    GL.glFogf(GL.GL_FOG_MODE, FOG_TYPES[0]);
    GL.glEnable(GL.GL_FOG);
    GL.glEnable(GL.GL_DEPTH_TEST);

    cubeListIndexBase = GL.glGenLists(1);
    createCube();
  }
示例#2
0
  /** @see OpenGLTab#renderScene() */
  void renderScene() {
    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    GL.glLoadIdentity();
    GL.glTranslatef(xPos, yPos, zPos);
    GL.glRotatef(rotY, 0.0f, 1.0f, 0.0f);

    GL.glCallList(cubeListIndexBase);

    GL.glPushMatrix();
    GL.glTranslatef(3, 0, -3);
    GL.glCallList(cubeListIndexBase);
    GL.glPopMatrix();

    GL.glPushMatrix();
    GL.glTranslatef(-3, 0, -3);
    GL.glCallList(cubeListIndexBase);
    GL.glPopMatrix();

    GL.glPushMatrix();
    GL.glTranslatef(0, 0, 4);
    GL.glCallList(cubeListIndexBase);
    GL.glPopMatrix();

    rotY += 0.6f;
  }
示例#3
0
 /** @see OpenGLTab#dispose() */
 void dispose() {
   super.dispose();
   GL.glDeleteLists(cubeListIndexBase, 1);
 }
示例#4
0
 /** Creates a cube at 0,0 in the viewport. */
 void createCube() {
   GL.glNewList(cubeListIndexBase, GL.GL_COMPILE);
   GL.glBegin(GL.GL_QUADS);
   // front
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, -0.5f, 0.5f); // bottom left
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(0.5f, -0.5f, 0.5f); // bottom right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, 0.5f); // top right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, 0.5f); // top left
   // back
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(-0.5f, -0.5f, -0.5f); // bottom left
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, -0.5f, -0.5f); // bottom right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, -0.5f); // top right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, -0.5f); // top left
   // left
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(-0.5f, -0.5f, -0.5f); // bottom left
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, -0.5f, 0.5f); // bottom right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, 0.5f); // top right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, -0.5f); // top left
   // right
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(0.5f, -0.5f, 0.5f); // bottom left
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, -0.5f, -0.5f); // bottom right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, -0.5f); // top right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, 0.5f); // top left
   // top
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, -0.5f);
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, -0.5f);
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, 0.5f);
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, 0.5f);
   // bottom
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(0.5f, -0.5f, 0.5f);
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, -0.5f, 0.5f);
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(-0.5f, -0.5f, -0.5f);
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, -0.5f, -0.5f);
   GL.glEnd();
   GL.glEndList();
 }