private void drawStar(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // STAR
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // BEGIN Star
    gl.glBegin(GL_LINE_LOOP);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to GREEN
    gl.glColor3f(0.0f, 1.0f, 0.0f);

    // Draw the sides
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(0.2f, 0.2f, 0.0f);
    gl.glVertex3f(1.0f, 0.0f, 0.0f);
    gl.glVertex3f(0.2f, -0.2f, 0.0f);
    gl.glVertex3f(0.0f, -1.0f, 0.0f);
    gl.glVertex3f(-0.2f, -0.2f, 0.0f);
    gl.glVertex3f(-1.0f, 0.0f, 0.0f);
    gl.glVertex3f(-0.2f, 0.2f, 0.0f);

    // END Star
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
  private void drawSquare(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // SQUARE
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Makes so that square is filled in
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // BEGIN Square
    gl.glBegin(GL_QUADS);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to BLUE
    gl.glColor3f(0.0f, 0.0f, 1.0f);

    // The Quad
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // END Square
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
 /** Pops all attributes */
 public void endmap2f() {
   // TODO Auto-generated method stub
   if (output_triangles) {
     //            System.out.println("TODO surfaceevaluator.endmap2f output triangles");
   } else {
     gl.glPopAttrib();
     // TODO use LOD
   }
 }
  /** Unbinds all color textures for rendering. You can now use them for texturing operations. */
  public void unbind(GL2 gl) throws OpenGLException {
    if (mIsBound) {
      gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, mPreviousBinding[0]);
      gl.glPopAttrib();
      mIsBound = false;

      OpenGLException.checkOpenGLError(gl);
    }
  }
Exemple #5
0
  /**
   * Render the arrow as a line and a _head.
   *
   * @param gl OpenGL Context
   */
  public void render(GL2 gl) {
    // save Light Attributes and remove lighting to get "full" RGB colors
    // gl.glPushAttrib( GL2.GL_LIGHTING_BIT );
    gl.glPushAttrib(GL2.GL_ENABLE_BIT);
    gl.glDisable(GL2.GL_LIGHTING);

    if (_fg_verb) {
      System.out.println(
          "Arrow pos="
              + _pos.toString()
              + "  angZ1="
              + _angZ1
              + "  angY2="
              + _angY2
              + "  length="
              + _length);
      _fg_verb = false;
    }

    // save transformation matrix, then translate and scale.
    gl.glPushMatrix();
    gl.glTranslatef(_pos.x, _pos.y, _pos.z);
    gl.glRotatef(Matrix.rad2Deg(_angZ1), 0, 0, 1); // rotation around 0z
    gl.glRotatef(Matrix.rad2Deg(_angY2), 0, 1, 0); // rotation around 0y

    // draw line
    gl.glColor4f(_color_fg.x, _color_fg.y, _color_fg.z, _color_fg.w);
    gl.glLineWidth(1.0f);
    gl.glBegin(GL.GL_LINES);
    {
      gl.glVertex3f(0, 0, 0);
      gl.glVertex3f(_length, 0, 0);
    }
    gl.glEnd();

    // draw head
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
    gl.glTranslatef(_length, 0, 0);
    gl.glBegin(GL.GL_TRIANGLES);
    {
      for (float[] face : _head_faces) {
        gl.glVertex3f(face[0], face[1], face[2]);
        gl.glVertex3f(face[3], face[4], face[5]);
        gl.glVertex3f(face[6], face[7], face[8]);
      }
    }
    gl.glEnd();

    // restore transformation matrix
    gl.glPopMatrix();
    // restore attributes
    gl.glPopAttrib();
  }
  // Support Methods
  private void drawPyramid(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // PYRAMID
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Rotates the pyramid, just for "fun"
    gl.glRotatef(-55.0f, 0.0f, 1.0f, 0.0f);

    // Makes only the outlines
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    // BEGIN Pyramid
    gl.glBegin(GL_TRIANGLES);

    // Pushing current color to stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to RED
    gl.glColor3f(1.0f, 0.0f, 0.0f);

    // Front triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // Right triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);

    // Left triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);

    // Back triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);

    // END Pyramid
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
  @Override
  public void draw(float fXCenter, float fYCenter, GL2 gl, GLU glu) {

    HashMap<PartialDisc, PDDrawingStrategySelected> mapSelectedDrawingStrategies =
        new HashMap<PartialDisc, PDDrawingStrategySelected>();
    parentIndicatorType = SelectionType.NORMAL;

    initDrawingStrategies(mapSelectedDrawingStrategies);

    PartialDisc pdCurrentRootElement = radialHierarchy.getCurrentRootElement();

    gl.glLoadIdentity();
    gl.glTranslatef(fXCenter, fYCenter, 0);

    float fHierarchyOuterRadius =
        Math.min(
            fXCenter * RadialHierarchyRenderStyle.USED_SCREEN_PERCENTAGE,
            fYCenter * RadialHierarchyRenderStyle.USED_SCREEN_PERCENTAGE);
    float fDiscWidth = fHierarchyOuterRadius / iDisplayedHierarchyDepth;

    pdCurrentRootElement.drawHierarchyFull(gl, glu, fDiscWidth, iDisplayedHierarchyDepth);

    // The selected elements have to be drawn (again using their own drawing
    // strategy) at last for
    // correct antialiasing

    for (PartialDisc pdSelected : mapSelectedDrawingStrategies.keySet()) {
      PDDrawingStrategySelected dsCurrent = mapSelectedDrawingStrategies.get(pdSelected);
      dsCurrent.drawPartialDisc(gl, glu, pdSelected);
    }

    if (parentIndicatorType != SelectionType.NORMAL) {
      gl.glPushClientAttrib(GL.GL_COLOR_BUFFER_BIT);
      if (parentIndicatorType == SelectionType.SELECTION)
        gl.glColor3fv(SelectionType.SELECTION.getColor().getRGB(), 0);
      else gl.glColor3fv(SelectionType.MOUSE_OVER.getColor().getRGB(), 0);
      GLPrimitives.renderCircle(glu, fDiscWidth / 2.0f, 100);
      GLPrimitives.renderCircleBorder(gl, glu, fDiscWidth / 2.0f, 100, 2);
      gl.glPopAttrib();
    }

    LabelManager.get()
        .drawAllLabels(gl, glu, fXCenter * 2.0f, fYCenter * 2.0f, fHierarchyOuterRadius);
    LabelManager.get().clearLabels();

    radialHierarchy.setNewSelection(false);
  }
Exemple #8
0
  @Override
  public void display(GLAutoDrawable drawable) {

    gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    // desenha ou nao a bounding sphere de cada objeto
    if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_B)) { // tecla B
      BoundingVolume.isVisible = !BoundingVolume.isVisible;
    }
    // habilita ou nao fog
    if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_F)) { // tecla F
      fogEnabled = !fogEnabled;
      if (fogEnabled) gl.glEnable(GL2.GL_FOG);
      else gl.glDisable(GL2.GL_FOG);
    }

    // atualiza camera
    camera.update();
    // atualiza objetos
    {
      Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject so = it.next();
        // animacao da porta
        if (so.getName().contains("door")) {
          if (Collision.collide(
              camera.getSceneObject().getBoundingSphere(), so.getBoundingSphere()))
            so.setAnimating(true);
          else so.setAnimating(false);
        }

        so.update();
      }
    }

    glu.gluLookAt(
        FPCamera.position.x,
        FPCamera.position.y,
        FPCamera.position.z,
        FPCamera.position.x + FPCamera.look.x,
        FPCamera.position.y + FPCamera.look.y,
        FPCamera.position.z + FPCamera.look.z,
        FPCamera.up.x,
        FPCamera.up.y,
        FPCamera.up.z);

    if (FPCamera.changed) { // se direcao da camera mudar
      FPCamera.changed = false;

      frustum.generate(drawable); // gera o frustum

      Scene.getInstance().clearVisibleObjectsList();

      Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject so = it.next();
        if (frustum.sphereInFrustum(so.getBoundingSphere()))
          Scene.getInstance().addVisibleObject(so);
      }

      //            System.out.println("Renderable objects: "+ Scene.getInstance().getSize());
      //            System.out.println(FPCamera.position);
    }

    // desenha objetos
    {
      Iterator<SceneObject> it = Scene.getInstance().getVisibleObjectsIterator();
      SceneObject so;
      while (it.hasNext()) {
        so = it.next();

        if (so.getName().contains("lake")) {
          gl.glPushAttrib(GL2.GL_ENABLE_BIT);
          gl.glEnable(GL.GL_BLEND);
          gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
          so.draw(drawable);
          gl.glPopAttrib();
          continue;
        }
        so.draw(drawable);
      }
    }

    //        int e = gl.glGetError();
    //        if(e != GL.GL_NO_ERROR) {
    //            System.err.println("Erro: "+ gl.glGetString(e));
    //        }
    // calculo do fps
    ++frame;
    long time = System.currentTimeMillis();
    elapsed = time - timebase;
    if (elapsed > 1000) {
      long fps = frame * 1000 / (time - timebase);
      timebase = time;
      frame = 0;

      String str = "FPS: " + fps;
      mainFrame.setTitle(str);
    }

    // gl.glFlush();
  }