Beispiel #1
0
  public void render() {
    lock.lock();

    quads = 0;
    draw_calls = 0;
    batch_draw_calls = 0;

    GL11.glLoadIdentity();
    GLU.gluLookAt(
        camera.pos.x,
        camera.pos.y,
        camera.pos.z,
        camera.pos.x + camera.look.x,
        camera.pos.y + camera.look.y,
        camera.pos.z + camera.look.z,
        camera.up.x,
        camera.up.y,
        camera.up.z);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    for (ChunkNode.Batch batch : batches) render_batch(batch);

    GL11.glFlush();

    lock.unlock();
  }
Beispiel #2
0
 @Override
 public void gluLookAt(
     GL10 gl,
     float eyeX,
     float eyeY,
     float eyeZ,
     float centerX,
     float centerY,
     float centerZ,
     float upX,
     float upY,
     float upZ) {
   org.lwjgl.util.glu.GLU.gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
 }
  @Override
  public void draw() {
    GL11.glClearColor(0.8f, 0.8f, 0.8f, 0.0f);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glLoadIdentity();
    GLU.gluLookAt(5.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    GL11.glRotatef(rot, 0.0f, 1.0f, 0.0f);
    GL11.glRotatef(rot2, 1.0f, 0.0f, 0.0f);
    drawer.draw();

    Keyboard.poll();

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
          return;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT) {
          rot -= 15.0f;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_LEFT) {
          rot += 15.0f;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_UP) {
          rot2 -= 15.0f;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_DOWN) {
          rot2 += 15.0f;
        }

        if (Keyboard.getEventKey() == Keyboard.KEY_T) {
          if (renderMode == GL11.GL_POLYGON) {
            renderMode = GL11.GL_LINE_LOOP;
          } else {
            renderMode = GL11.GL_POLYGON;
          }
        }
      }
    }
  }
Beispiel #4
0
 public static void set() {
   GL11.glViewport(0, 0, HouseCalc.programFrame.getWidth(), HouseCalc.programFrame.getHeight());
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glLoadIdentity();
   float width = HouseCalc.programFrame.getWidth();
   float height = HouseCalc.programFrame.getHeight();
   GLU.gluPerspective(70, width / height, 0.1f, 600.0f);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glLoadIdentity();
   GLU.gluLookAt(
       (float) posx,
       (float) posy,
       (float) posz,
       (float) posx + dirx,
       (float) posy + diry,
       (float) posz + dirz,
       0,
       1,
       0);
   MatrixTools.multMatrix(matrix);
 }
Beispiel #5
0
  @Override
  protected void init() {
    glEnable(GL_LINE_SMOOTH);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // brak efektu na moim kompie
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glMatrixMode(GL_PROJECTION); // chcemy zrobić coś na macierzy projekcji
    glLoadIdentity();
    if (width > height) {
      glOrtho(-5 * (float) width / height, 5 * (float) width / height, -5, 5, -5, 5);
    } else {

      glOrtho(-5, 5, -5 * (float) height / width, 5 * (float) height / width, -5, 5);
    }
    // glTranslatef(-0.5f, -0.5f, 0);
    // glScalef(0.5f, 0.5f, 0.5f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(1, 1, 1, 0, 0, 0, 0, 1, 0);
    // glScalef(0.5f, 0.5f, 0.5f);

    buffer.rewind();
    buffer.put(data);
    buffer.rewind();

    brickIndices.rewind();
    brickIndices.put(indidata);
    brickIndices.rewind();

    paintedWall.rewind();
    paintedWall.put(paintedWallindi);
    paintedWall.rewind();

    glInterleavedArrays(GL_C3F_V3F, 0, buffer);
  }
Beispiel #6
0
  public void display() {
    GL11.glViewport(0, 0, width, height);
    GL11.glClearColor(0.5f, 0.5f, 0.5f, 0.1f);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    float widthHeightRatio = width / height;
    GLU.gluPerspective(45, widthHeightRatio, 1, 1000);
    GLU.gluLookAt(
        player.getX(),
        player.getY(),
        player.getZ(),
        player.getCamX(),
        player.getCamY(),
        player.getCamZ(),
        0,
        1,
        0);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    // Level

    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    for (byte i = 0; i < level.getSizeX(); i += 1) {
      for (byte j = 0; j < level.getSizeY(); j += 1) {
        for (byte k = 0; k < level.getSizeZ(); k += 1) {
          if (level.getCubeName(i, j, k).equals(Cube.CUBE_BOMB)) {
            objects.DrawCubeBomb(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION)) {
            objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION_HIDE_EXIT)) {
            objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION_HIDE_ITEM)) {
            objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_HEALTH)) {
            objects.DrawCubeItemHealth(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_XTRA_BOMB)) {
            objects.DrawCubeItemXtraBomb(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_BOMB_RANGE)) {
            objects.DrawCubeItemBombRange(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_BOMB_STRENGTH)) {
            objects.DrawCubeItemBombStrength(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_PORTAL)) {
            objects.DrawCubeItemPortal(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_DOUBLE_SCORE)) {
            objects.DrawCubeItemDoubleScore(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_SOLID)) {
            objects.DrawCubeSolid(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OUTSIDE)) {
            objects.DrawCubeOutside(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OBSTACLE)) {
            objects.DrawCubeObstacle(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OBSTACLE_HIDE_EXIT)) {
            objects.DrawCubeObstacle(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXIT)) {
            objects.DrawCubeExit(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_SOLID_RAMP)) {
            objects.DrawCubeRamp(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
            // Menüwürfel
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_NEW_GAME)) {
            objects.DrawMenuCubeNewGame(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_NEW_GAME_GRAVITY)) {
            objects.DrawMenuCubeNewGameGravity(
                i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_EXIT_PROGRAM)) {
            objects.DrawMenuCubeExitProgram(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_MULTI)) {
            objects.DrawMenuCubeMulti(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_SERVER)) {
            objects.DrawMenuCubeServer(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_OPTIONS)) {
            objects.DrawMenuCubeOptions(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_LOAD_LEVEL)) {
            objects.DrawMenuCubeLoadLevel(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE);
          }
        }
      }
    }
    if (listPlayer != null) {
      for (int i = 0; i < listPlayer.size(); i++) {
        if (listPlayer.get(i).getNumber() != player.getNumber()) {
          objects.DrawPlayer(
              listPlayer.get(i).getX() - (SIZE_OF_CUBE / 2),
              listPlayer.get(i).getY() - (SIZE_OF_CUBE / 2),
              listPlayer.get(i).getZ() - (SIZE_OF_CUBE / 2));
        }
      }
    }

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    // GL11.glOrtho(-CLIPSIZE, +CLIPSIZE, -CLIPSIZE, +CLIPSIZE, -CLIPSIZE *
    // 100.0f, +CLIPSIZE * 100.0f);
    // GL11.glOrtho(-CLIPSIZE, +CLIPSIZE, -CLIPSIZE, +CLIPSIZE, -CLIPSIZE,
    // +CLIPSIZE);
    GL11.glOrtho(
        -Window.width / 2,
        +Window.width / 2,
        -Window.height / 2,
        +Window.height / 2,
        -CLIPSIZE,
        +CLIPSIZE);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    // GL11.glTranslatef(1f, 1f, 0.0f);

    GL11.glDisable(GL11.GL_DEPTH_TEST);

    hud.renderHUD();

    GL11.glFlush();
  }
Beispiel #7
0
  /** Render the current frame */
  private static void render() {
    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    gluPerspective(30f, aspect, 1f, 10000000f);

    float look = anchorL.z * 5;

    gluLookAt(look, look, anchorL.z, 0, 0, 0, 0, 0, 1);

    glClearColor(.5f, 0.5f, 0.5f, .5f);

    // clear the screen
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    {
      // int systemDimLength = cube.sideLength / 2;
      // rotate square according to angle
      glRotatef(angle, 0, 0, 1.0f);

      // glColor3f(1f, 1f, 1f);
      // cube.glSurfaceDraw();

      /*
       * Draw the particle in the system
       */
      glColor3f(0.0f, 1.0f, 0.0f);
      glPointSize(3.0f);
      /*
       * glBegin(GL_POINTS); { for (Particle p : system) {
       * glVertex3f(p.x.x, p.x.y, p.x.z); } } glEnd();
       */

      /*
       * Draw the lines
       */
      glLineWidth(2.0f);
      for (Constraint p : constraints) {
        glBegin(GL_LINES);
        {
          glVertex3f(p.getA().x.x, p.getA().x.y, p.getA().x.z);
          glVertex3f(p.getB().x.x, p.getB().x.y, p.getB().x.z);
        }
        glEnd();
      }

      /*
       * Shadows, just for effect!
       */
      glColor4f(0, 0, 0, .5f);
      /*
       * glBegin(GL_POINTS); { for (Particle p : system) {
       * glVertex3f(p.x.x, p.x.y, -systemDimLength); } } glEnd();
       */

      /*
       * Draw the line shadows
       */
      for (Constraint p : constraints) {
        glBegin(GL_LINES);
        {
          glVertex3f(p.getA().x.x, p.getA().x.y, -0);
          glVertex3f(p.getB().x.x, p.getB().x.y, -0);
        }
        glEnd();
      }

      glBegin(GL_LINES);
      {
        glVertex3f(anchorL.x, anchorL.y, -0);
        glVertex3f(anchorR.x, anchorR.y, -0);
      }
      glEnd();

      glColor3f(1, 0, 0);

      /*
       * Draw the tension line
       */
      glBegin(GL_LINES);
      {
        glVertex3f(anchorL.x, anchorL.y, -0);
        glVertex3f(anchorL.x, anchorL.y, anchorL.z);
        glVertex3f(anchorL.x, anchorL.y, anchorL.z);
        glVertex3f(anchorR.x, anchorR.y, anchorR.z);
        glVertex3f(anchorR.x, anchorR.y, anchorR.z);
        glVertex3f(anchorR.x, anchorR.y, -0);
      }
      glEnd();
    }
    glPopMatrix();
  }
Beispiel #8
0
  public void render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    glLoadIdentity(); // Reset The matrix

    //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

    // Give OpenGL our position,	then view,		then up vector
    gluLookAt(0, 1.5f, 100, 0, .5f, 0, 0, 1, 0);

    // We want the model to rotate around the axis so we give it a rotation
    // value, then increase/decrease it. You can rotate right of left with the arrow keys.

    glRotatef(g_RotateX, 0, 1.0f, 0); // Rotate the object around the Y-Axis
    g_RotateX += g_RotationSpeed; // Increase the speed of rotation

    // Make sure we have valid objects just in case. (size() is in the vector class)
    if (g_World.getObject().size() <= 0) return;

    for (int i = 0; i < g_World.getObject().size(); i++) {
      // Get the current object that we are displaying
      Object3d pObject = g_World.getObject(i);

      glBindTexture(GL_TEXTURE_2D, pObject.getMaterialID());

      // Render lines or normal triangles mode, depending on the global variable
      glBegin(g_ViewMode);

      // Go through all of the faces (polygons) of the object and draw them
      for (int j = 0; j < pObject.getNumFaces(); j++) {
        // Go through each corner of the triangle and draw it.
        for (int whichVertex = 0; whichVertex < 3; whichVertex++) {
          // Get the index for each point in the face
          int index = pObject.getFace(j).getVertices(whichVertex);

          // Get the index for each texture coord in the face
          int index2 = pObject.getFace(j).getTexCoords(whichVertex);

          // Give OpenGL the normal for this vertex.  Notice that we put a
          // - sign in front.  It appears that because of the ordering of Quake2's
          // polygons, we need to invert the normal
          // glNormal3f(-pObject.getNormal(index).x, -pObject.getNormal(index).y,
          // -pObject.getNormal(index).z);

          // Make sure there was a UVW map applied to the object or else it won't have tex coords.
          if (pObject.getNumTexcoords() > 0) {
            glTexCoord2f(pObject.getTexcoords(index2).s, pObject.getTexcoords(index2).t);
          }

          // Pass in the current vertex of the object (Corner of current face)
          glVertex3f(
              pObject.getVertices(index).x,
              pObject.getVertices(index).y,
              pObject.getVertices(index).z);
        }
      }

      glEnd();
    }
    // Render the cubed nodes to visualize the octree (in wire frame mode)
    if (g_bDisplayNodes) {
      // TOctree.g_Debug.renderDebugLines();
      for (int j = 0; j < g_World.getObject().size(); j++) {
        g_World.getObject(j).drawBoundingBox();
      }
    }
  }