Example #1
0
  @Override
  public void render() {
    int width = App.getScreenWidth();
    int height = App.getScreenHeight();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, width, 0, height);
    glScalef(1, -1, 1);
    glTranslatef(0, -height, 0);
    glMatrixMode(GL_MODELVIEW);
    glDisable(GL_DEPTH_TEST);
    // Draw background
    glBegin(GL_QUADS);
    {
      if (backgroundColor != null) GeneralUtils.glColorShortcut(backgroundColor);

      glVertex2f(0, 0);
      glVertex2f(0, height);
      glVertex2f(width, height);
      glVertex2f(width, 0);
    }
    glEnd();

    for (GuiButton b : buttons) {
      b.render();
      // System.out.println(b.isMouseOver());

    }

    // I don't want to set the same opengl settings for every button.
    // We can reduce a least a tiny bit of overhead by doing it in one go
    font.renderBegin();
    for (GuiButton b : buttons) {
      b.renderText();
    }
    font.renderEnd();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_DEPTH_TEST);
  }
Example #2
0
 public static int prepareSquare(int texId, float size) {
   int list = glGenLists(1);
   glNewList(list, GL_COMPILE);
   glDisable(GL_CULL_FACE);
   glBindTexture(GL_TEXTURE_2D, texId);
   glTranslatef(-size / 2, -size / 2, 0);
   // glRotatef(180.0f, 0.0f, 0.0f, 0.0f);
   glBegin(GL_QUADS);
   glTexCoord2f(0.0f, 0.0f);
   glVertex2f(0.0f, 0.0f);
   glTexCoord2f(1.0f, 0.0f);
   glVertex2f(size, 0.0f);
   glTexCoord2f(1.0f, 1.0f);
   glVertex2f(size, size);
   glTexCoord2f(0.0f, 1.0f);
   glVertex2f(0.0f, size);
   glEnd();
   glEnable(GL_CULL_FACE);
   glEndList();
   return list;
 }
Example #3
0
  protected void render() {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

    glLoadIdentity();

    camera.look();

    // Each frame we calculate the new frustum.  In reality you only need to
    // calculate the frustum when we move the camera.
    GameCore.gFrustum.calculateFrustum();

    // Initialize the total node count that is being draw per frame
    Octree.totalNodesDrawn = 0;

    glPushMatrix();
    // Here we draw the octree, starting with the root node and recursing down each node.
    // This time, we pass in the root node and just the original world model.  You could
    // just store the world in the root node and not have to keep the original data around.
    // This is up to you.  I like this way better because it's easy, though it could be
    // more error prone.
    octree.drawOctree(octree, g_World);
    glPopMatrix();

    // Render the cubed nodes to visualize the octree (in wire frame mode)
    if (g_bDisplayNodes) Octree.debug.drawBoundingBox();

    glPushMatrix();
    // If there was a collision, make the Orange ball Red.
    if (octree.isObjectColliding()) {
      glColor3f(1.0f, 0.0f, 0.0f);
    } else {
      glColor3f(1.0f, 0.5f, 0.0f); // Disable Lighting.
    }
    // Move the Ball into place.
    glTranslatef(g_BallEntity.x, g_BallEntity.y, g_BallEntity.z);

    glDisable(GL_LIGHTING);
    // Draw the Ground Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 1);
    glVertex3f(g_vGroundISector[0].x, g_vGroundISector[0].y, g_vGroundISector[0].z);
    glVertex3f(g_vGroundISector[1].x, g_vGroundISector[1].y, g_vGroundISector[1].z);
    glEnd();

    // Draw the Forward Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 0);
    glVertex3f(
        g_vForwardISector[0].x * 10.0f, g_vForwardISector[0].y, g_vForwardISector[0].z * 10.0f);
    glVertex3f(
        g_vForwardISector[1].x * 10.0f, g_vForwardISector[1].y, g_vForwardISector[1].z * 10.0f);
    glEnd();

    // Re-enable lighting.
    glEnable(GL_LIGHTING);

    // System.out.println("x " + g_BallEntity.x + " y " + g_BallEntity.y);
    // Draw it!
    pObj.draw(g_BallEntity.fRadius, 20, 20);

    glPopMatrix();

    screen.setTitle(
        "Triangles: "
            + Octree.maxTriangles
            + "  -Total Draw: "
            + Octree.totalNodesDrawn
            + "  -Subdivisions: "
            + Octree.maxSubdivisions
            + "  -FPS: "
            + FPSCounter.get()
            + "  -Node Collisions: "
            + Octree.numNodesCollided
            + "  -Object Colliding? "
            + octree.isObjectColliding());
  }