public void display(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   synchronized (this._camera) {
     try {
       gl.glClear(
           GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
       NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0);
       this._nyar.update(this._camera);
       if (this._nyar.isExistMarker(this.ids[0])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       if (this._nyar.isExistMarker(this.ids[1])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       Thread.sleep(1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Exemple #2
0
  public void desenhar(GL gl, GLUT glut) {
    gl.glShadeModel(GL.GL_FLAT);
    gl.glNormal3f(0.0f, 0.0f, 1.0f);
    gl.glColor3f(1f, 1f, 1f);

    float corWhite[] = {1.0f, 1.0f, 1.0f, 1.0f};

    // base
    setTexture(Util.loadImage("texture/textureBrick.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, corWhite, 0);
    gl.glEnable(GL.GL_LIGHTING);
    gl.glPushMatrix();
    gl.glTranslatef(0f, -dif, 0f);
    gl.glScalef(getxEscala(), getyEscala(), getzEscala());
    glut.glutSolidCube(1f);
    gl.glPopMatrix();

    // esquerda
    setTexture(Util.loadImage("texture/tijolos/medio2.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glPushMatrix();
    gl.glTranslatef(-(getxEscala() / 2), (getAltura() / 2) - dif, 0f);
    gl.glScalef(0.1f, getAltura(), getzEscala());
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
    gl.glDisable(GL.GL_LIGHTING);

    // direita
    setTexture(Util.loadImage("texture/tijolos/medio2.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glPushMatrix();
    gl.glTranslatef(getxEscala() / 2, (getAltura() / 2) - dif, 0f);
    gl.glScalef(0.1f, getAltura(), getzEscala());
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
    gl.glDisable(GL.GL_LIGHTING);

    // fundo
    setTexture(Util.loadImage("texture/tijolos/fraco.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glPushMatrix();
    gl.glTranslatef(0f, (getAltura() / 2) - dif, -(getzEscala() / 2));
    gl.glScalef(getxEscala(), getAltura(), 0.1f);
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
    gl.glDisable(GL.GL_LIGHTING);
  }
Exemple #3
0
  public void display(GL gl, float time, int screenWidth, int screenHeight) {
    // TODO: most of this only needs to be done once per frame, not per button.
    if (!visible) {
      return;
    }
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    if (flipx) {
      gl.glTranslatef(1.0f, 0.0f, 0.0f);
      gl.glScalef(-1.0f, 1.0f, 1.0f);
    }
    if (flipy) {
      gl.glTranslatef(0.0f, 1.0f, 0.0f);
      gl.glScalef(1.0f, -1.0f, 1.0f);
    }
    gl.glScalef(1.0f / screenWidth, 1.0f / screenHeight, 1.0f);
    if (isSelected() || (mDown && mOver)) {
      gl.glColor3f(0.6f, 0.6f, 0.8f);
    } else {
      gl.glColor3f(0.8f, 0.8f, 0.8f);
    }
    gl.glActiveTexture(GL.GL_TEXTURE0);
    marble.enable();
    marble.bind();
    gl.glMatrixMode(GL.GL_TEXTURE);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glBegin(GL.GL_POLYGON);

    for (int n = 0; n < buttonShape.npoints; n++) {
      gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2);
      gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -0.5f);
    }
    gl.glEnd();

    tex.enable();
    tex.bind();
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glBegin(GL.GL_POLYGON);

    for (int n = 0; n < buttonShape.npoints; n++) {
      gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2);
      gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -1.0f);
    }
    gl.glEnd();
    gl.glPopMatrix();

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();
  }
Exemple #4
0
  /**
   * @param glRenderContext
   * @param prototype
   * @param buffer to be used for rendering.
   */
  public static synchronized void render(
      RenderContext glRenderContext, PrototypeReference prototype, DirectGeometryBuffer buffer) {
    if (prototype == null || prototype.getPrototypeID() == null) {
      return;
    }
    RenderablePrototype model = prototypes.get(prototype.getPrototypeID());

    if (model == null) {
      LOG.warn("No model found for prototype: " + prototype.getPrototypeID());
      return;
    }

    GL context = glRenderContext.getContext();

    context.glPushMatrix();

    float[] loc = prototype.getLocation();
    context.glTranslatef(loc[0], loc[1], loc[2]);
    context.glRotatef(prototype.getAngle(), 0, 0, 1);
    context.glScalef(prototype.getWidth(), prototype.getDepth(), prototype.getHeight());
    if (buffer == null) {
      model.render(null);
    } else {
      model.renderPrepared(glRenderContext, buffer);
    }
    context.glPopMatrix();
  }
Exemple #5
0
  /** Draws circular particle using a display list. */
  public void display(GL gl) {
    if (PARTICLE_DISPLAY_LIST < 0) { // MAKE DISPLAY LIST:
      int displayListIndex = gl.glGenLists(1);
      gl.glNewList(displayListIndex, GL.GL_COMPILE);
      drawParticle(gl, new Point3d(), radius); // /particle at origin
      gl.glEndList();
      System.out.println("MADE LIST " + displayListIndex + " : " + gl.glIsList(displayListIndex));
      PARTICLE_DISPLAY_LIST = displayListIndex;
    }

    // / COLOR: DEFAULT WHITE; GREEN IF HIGHLIGHTED; ADD RED IF PINNED
    Color3f c = new Color3f(1, 1, 1); // default: white
    if (pin) {
      c.x = 1f; // add red
      c.y *= 0.2f;
      c.z = 0;
    }
    if (highlight) {
      c.y = 1;
      c.z = 0;
    }
    if (GooParticle.class.isInstance(this)) {
      c.x = 0;
      c.y = 0;
      // now its blue
    }

    gl.glColor3f(c.x, c.y, c.z);

    // / DRAW ORIGIN-CIRCLE TRANSLATED TO "p":
    gl.glPushMatrix();
    gl.glTranslated(x.x, x.y, x.z);
    gl.glCallList(PARTICLE_DISPLAY_LIST);
    gl.glPopMatrix();
  }
  /**
   * Draw labels for picking.
   *
   * @param dc Current draw context.
   * @param pickSupport the PickSupport instance to be used.
   */
  protected void doPick(DrawContext dc, PickSupport pickSupport) {
    GL gl = dc.getGL();

    Angle heading = this.rotation;

    double headingDegrees;
    if (heading != null) headingDegrees = heading.degrees;
    else headingDegrees = 0;

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    boolean matrixPushed = false;
    try {
      if (headingDegrees != 0) {
        gl.glPushMatrix();
        matrixPushed = true;

        gl.glTranslated(x, y, 0);
        gl.glRotated(headingDegrees, 0, 0, 1);
        gl.glTranslated(-x, -y, 0);
      }

      for (int i = 0; i < this.lines.length; i++) {
        Rectangle2D bounds = this.lineBounds[i];
        double width = bounds.getWidth();
        double height = bounds.getHeight();

        x = this.screenPoint.x;
        if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0);
        else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width;
        y -= this.lineHeight;

        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false);
        pickSupport.addPickableObject(po);

        // Draw line rectangle
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());

        try {
          gl.glBegin(GL.GL_POLYGON);
          gl.glVertex3d(x, y, 0);
          gl.glVertex3d(x + width - 1, y, 0);
          gl.glVertex3d(x + width - 1, y + height - 1, 0);
          gl.glVertex3d(x, y + height - 1, 0);
          gl.glVertex3d(x, y, 0);
        } finally {
          gl.glEnd();
        }

        y -= this.lineSpacing;
      }
    } finally {
      if (matrixPushed) {
        gl.glPopMatrix();
      }
    }
  }
Exemple #7
0
  public void render3D(GL gl, GLDrawable glc) {
    if (pts2d.size() < 4) return;
    if (fill != null || texture != null) {
      if (texture == null) {
        setColor(gl, fill);
        gl.glDisable(GL.GL_TEXTURE_2D);
      } else {
        setColor(gl, Color.white);
        Texture gltexture = texture.getTexture(glc);
        gltexture.enable();
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
        gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
        gltexture.bind();
      }
      gl.glPushMatrix();

      // get 4 control points of portal
      Point2D p0 = pts2d.get(0);
      Point2D p1 = pts2d.get(1);
      Point2D p2 = pts2d.get(2);
      Point2D p3 = pts2d.get(3);

      // render 1st side of portal with height extra[0]
      renderOneside(p0, p1, gl, extra[0]);

      // render 1st side of portal with height extra[1]
      renderOneside(p2, p3, gl, extra[1]);

      gl.glPopMatrix();
    }
  }
Exemple #8
0
  public void renderBox(GL gl) {
    gl.glDisable(GL_TEXTURE_2D);
    int c1 = Math.abs(this.hashCode()) % 256;
    int c2 = Math.abs(getImage().hashCode()) % 256;
    gl.glColor4f(c1 / 256f, c2 / 256f, ((c1 + c2) * 34) % 256 / 256f, 0.3f);
    gl.glPushMatrix();
    gl.glTranslatef(bounds.getLeft(), bounds.getTop(), minHeight);
    gl.glScalef(bounds.getWidth(), bounds.getHeight(), maxHeight - minHeight);
    gl.glBegin(GL_QUADS);
    gl.glVertex3f(0, 0, 0);
    gl.glVertex3f(0, 1, 0);
    gl.glVertex3f(1, 1, 0);
    gl.glVertex3f(1, 0, 0);

    gl.glVertex3f(0, 0, 1);
    gl.glVertex3f(0, 1, 1);
    gl.glVertex3f(1, 1, 1);
    gl.glVertex3f(1, 0, 1);
    gl.glEnd();
    gl.glColor4f(1, 1, 0, 0.2f);
    gl.glBegin(GL_QUAD_STRIP);
    gl.glVertex3f(0, 0, 0);
    gl.glVertex3f(0, 0, 1);
    gl.glVertex3f(0, 1, 0);
    gl.glVertex3f(0, 1, 1);
    gl.glVertex3f(1, 1, 0);
    gl.glVertex3f(1, 1, 1);
    gl.glVertex3f(1, 0, 0);
    gl.glVertex3f(1, 0, 1);
    gl.glVertex3f(0, 0, 0);
    gl.glVertex3f(0, 0, 1);
    gl.glEnd();
    gl.glPopMatrix();
  }
Exemple #9
0
  private void renderPin(GL gl, Coordinates position, float[] color, float size) {
    float height = heightmap.getHeight(projection.getGeoCoordinates(position));
    gl.glPushMatrix();
    double[] model = new double[16];
    gl.glGetDoublev(GL_MODELVIEW_MATRIX, model, 0);
    double zoomH =
        0.1 / Math.sqrt((model[0] * model[0]) + (model[1] * model[1]) + (model[2] * model[2]));
    double zoomZ =
        0.1 / Math.sqrt((model[8] * model[8]) + (model[9] * model[9]) + (model[10] * model[10]));
    gl.glTranslatef(position.getLongitude(), position.getLatitude(), height);
    gl.glScaled(zoomH * size, zoomH * size, zoomZ * size);
    gl.glDisable(GL_TEXTURE_2D);

    gl.glRotatef(20, 0.3f, 1, 0);

    GLU glu = new GLU();
    GLUquadric quadric = glu.gluNewQuadric();
    // glu.gluQuadricNormals(quadric, GLU.GLU_FLAT);
    gl.glColor3f(0.5f, 0.5f, 0.5f);
    gl.glEnable(GL_LIGHTING);
    glu.gluCylinder(quadric, 0.03, 0.03, 0.6f, 5, 1);
    gl.glTranslatef(0, 0, 0.6f);

    gl.glColor3f(color[0], color[1], color[2]);
    gl.glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glu.gluSphere(quadric, 0.12, 8, 8);
    // glu.gluCylinder(quadric, 0.2, 0.1, 0.5, 8, 1);
    gl.glDisable(GL_LIGHTING);
    glu.gluDeleteQuadric(quadric);
    gl.glPopMatrix();
  }
  public void updateSelectedOctant(GL gl, GLU glu, float[] mousePosition, float[] pickRectangle) {
    // Start Picking mode
    int capacity =
        1 * 4 * visibleLeaves.size(); // Each object take in maximium : 4 * name stack depth
    IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity);

    gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
    gl.glRenderMode(GL.GL_SELECT);
    gl.glDisable(GL.GL_CULL_FACE); // Disable flags

    gl.glInitNames();
    gl.glPushName(0);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    glu.gluPickMatrix(
        mousePosition[0],
        mousePosition[1],
        pickRectangle[0],
        pickRectangle[1],
        drawable.getViewport());
    gl.glMultMatrixd(drawable.getProjectionMatrix());

    gl.glMatrixMode(GL.GL_MODELVIEW);

    // Draw the nodes' cube int the select buffer
    int hitName = 1;
    for (int i = 0; i < visibleLeaves.size(); i++) {
      Octant node = visibleLeaves.get(i);
      gl.glLoadName(hitName);
      node.displayOctant(gl);
      hitName++;
    }

    // Restoring the original projection matrix
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glFlush();

    // Returning to normal rendering mode
    int nbRecords = gl.glRenderMode(GL.GL_RENDER);
    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }

    // Clean previous selection
    selectedLeaves.clear();

    // Get the hits and put the node under selection in the selectionArray
    for (int i = 0; i < nbRecords; i++) {
      int hit = hitsBuffer.get(i * 4 + 3) - 1; // -1 Because of the glPushName(0)

      Octant nodeHit = visibleLeaves.get(hit);
      selectedLeaves.add(nodeHit);
    }
  }
Exemple #11
0
  /** OpenGL drawing function */
  @Override
  public void display(GLAutoDrawable auto_drawable) {
    // get the GL context
    final GL gl = auto_drawable.getGL();
    // clear the buffers
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    // load the identity matrix
    gl.glLoadIdentity();

    // translations so we can see drawing
    gl.glTranslatef(0, 0, -0.7f);

    if (LoadTexturePosted == true) {
      if (LoadGuessModelPosted == null) System.err.println("ERROR: LoadGuessModelPosted is null!");
      current_Texture =
          AnimalTexture.findAnimalTexture(Animal_Tex_Array, LoadGuessModelPosted.getAnimalName());
      LoadTexturePosted = false;
    }

    // if the current texture is null, load the question texture
    if (current_Texture == null) question_Texture.bind();
    else current_Texture.bind();

    // draw the cube
    gl.glPushMatrix();
    gl.glRotatef(yrotate, 0.0f, 1.0f, 0.0f);
    drawOpenCube(gl);
    gl.glPopMatrix();

    // increase rotation
    yrotate += 0.05;
  }
  public void render(GLOContext ctx) {
    GUIContext guictx = (GUIContext) ctx;
    GL gl = ctx.getGL();

    ModelRenderer mrend =
        guictx.rendcache.getModelRenderer(xpointermodel, ModelRenderer.NO_NORMALS);

    gl.glPushMatrix(); // #1
    gl.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT);
    gl.glEnable(GL.GL_CULL_FACE);

    setShader("xpointer");
    Point org = origin;
    float w2 = getWidth() * 0.5f;
    float h2 = getHeight() * 0.5f;
    float cenx = org.x + w2;
    float ceny = org.y + h2;

    gl.glTranslatef(cenx, ceny, 0);
    gl.glScalef(w2, h2, 1); // must convert right-hand to left-hand coords

    // draw the x value
    gl.glPushMatrix();
    float xval = getXValue();
    xval = Math.max(-maxrot, Math.min(maxrot, xval * maxrot));
    gl.glRotatef(90, 0, 0, 1);
    gl.glRotatef(xval, -1, 0, 0);
    mrend.render();
    gl.glPopMatrix();

    // draw the y value
    float yval = getYValue();
    yval = Math.max(-maxrot, Math.min(maxrot, yval * maxrot));
    gl.glRotatef(yval, -1, 0, 0);
    mrend.render();

    gl.glPopAttrib();
    gl.glPopMatrix(); // #1
  }
Exemple #13
0
  /** Draws a canonical circular particle. */
  private static void drawParticle(GL gl, Point3d p, double r) {
    double radius = r;

    double vectorY1 = p.y;
    double vectorX1 = p.x;
    double vectorZ1 = p.z;

    GLU glu = new GLU();
    GLUquadric quadratic = glu.gluNewQuadric();
    glu.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH);
    glu.gluQuadricTexture(quadratic, true);

    gl.glPushMatrix();
    gl.glTranslated(p.x, p.y, p.z);
    glu.gluSphere(quadratic, radius, 12, 12);
    gl.glPopMatrix();
  }
  /**
   * Render the label interior as a filled rectangle.
   *
   * @param dc Current draw context.
   */
  protected void drawInterior(DrawContext dc) {
    GL gl = dc.getGL();

    double width = this.bounds.getWidth();
    double height = this.bounds.getHeight();

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    // Adjust x to account for text alignment
    int xAligned = x;
    if (AVKey.CENTER.equals(textAlign)) xAligned = x - (int) (width / 2);
    else if (AVKey.RIGHT.equals(textAlign)) xAligned = x - (int) width;

    // We draw text top-down, so adjust y to compensate.
    int yAligned = (int) (y - height);

    // Apply insets
    Insets insets = this.getInsets();
    xAligned -= insets.left;
    width = width + insets.left + insets.right;
    yAligned -= insets.bottom;
    height = height + insets.bottom + insets.top;

    if (!dc.isPickingMode()) {
      // Apply the frame background color and opacity if we're in normal rendering mode.
      Color color = this.computeBackgroundColor(this.getMaterial().getDiffuse());
      gl.glColor4ub(
          (byte) color.getRed(),
          (byte) color.getGreen(),
          (byte) color.getBlue(),
          (byte) (this.interiorOpacity < 1 ? (int) (this.interiorOpacity * 255 + 0.5) : 255));
    }

    try {
      // Draw a quad
      gl.glPushMatrix();
      gl.glTranslated(xAligned, yAligned, 0);
      gl.glScaled(width, height, 1.0);
      dc.drawUnitQuad();
    } finally {
      gl.glPopMatrix();
    }
  }
Exemple #15
0
 void glSpiral(final GL gl, Node aref, HashSet<Node> cluster) {
   int i = 0;
   float r = 0;
   float matrix[] = new float[16];
   for (Node bref : cluster) {
     if (bref != null) {
       i++;
       r = spiral_rad(aref, i);
       gl.glPushMatrix();
       gl.glLoadIdentity();
       gl.glTranslatef(aref.pos.x, aref.pos.y, aref.pos.z);
       gl.glRotatef(spiral_angle(aref, i), 0, 0, 1);
       gl.glTranslatef(-r, 0, 0);
       gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, matrix, 0);
       bref.pos.setXYZ(matrix[12], matrix[13], matrix[14]);
       gl.glPopMatrix();
     }
   }
 }
Exemple #16
0
  @Override
  public boolean renderizar(GL gl) {
    float[] cor2 = {cor.r, cor.g, cor.b, 1f};
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, cor2, 0);

    gl.glPushMatrix();
    {
      gl.glMultMatrixd(transformacao.getMatriz(), 0);

      gl.glBegin(primitiva);
      {
        for (Ponto ponto : pontos) {
          gl.glVertex3d(ponto.x, ponto.y, ponto.z);
        }
      }
      gl.glEnd();
      this.bbox.draw(gl);
    }
    gl.glPopMatrix();
    return super.renderizar(gl);
  }
  /**
   * Draw the label's text. This method sets up the text renderer, and then calls {@link
   * #doDrawText(TextRenderer) doDrawText} to actually draw the text.
   *
   * @param dc Current draw context.
   * @param textRenderer Text renderer.
   */
  protected void drawText(DrawContext dc, TextRenderer textRenderer) {
    GL gl = dc.getGL();

    Angle heading = this.rotation;

    double headingDegrees;
    if (heading != null) headingDegrees = heading.degrees;
    else headingDegrees = 0;

    boolean matrixPushed = false;
    try {
      int x = this.screenPoint.x;
      int y = this.screenPoint.y;

      if (headingDegrees != 0) {
        gl.glPushMatrix();
        matrixPushed = true;

        gl.glTranslated(x, y, 0);
        gl.glRotated(headingDegrees, 0, 0, 1);
        gl.glTranslated(-x, -y, 0);
      }

      if (this.isDrawInterior()) this.drawInterior(dc);

      textRenderer.begin3DRendering();
      try {
        this.doDrawText(textRenderer);

        // Draw other labels that share the same text renderer configuration, if possible.
        if (this.isEnableBatchRendering()) this.drawBatchedText(dc, textRenderer);
      } finally {
        textRenderer.end3DRendering();
      }
    } finally {
      if (matrixPushed) {
        gl.glPopMatrix();
      }
    }
  }
Exemple #18
0
 private void clusterCircle(final GL gl, float xRot, float yRot, Node aref) {
   aref.spiralcluster = false;
   int jcount = 0;
   float matrix[] = new float[16];
   float rad = aref.cluster.size();
   float clusterDist = calcClusterDistance(aref);
   for (Node bref : aref.cluster) {
     if (bref != null) {
       gl.glPushMatrix();
       gl.glLoadIdentity();
       gl.glTranslatef(aref.pos.x, aref.pos.y, aref.pos.z);
       //				gl.glRotatef(xRot, 0, 1, 0);
       //				gl.glRotatef(yRot, 1, 0, 0);
       gl.glRotatef(90 + 360 * jcount / rad, 0, 0, 1);
       gl.glTranslatef(-clusterDist, 0, 0);
       gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, matrix, 0);
       bref.pos.setXYZ(matrix[12], matrix[13], matrix[14]);
       gl.glPopMatrix();
       jcount++;
     }
   }
 }
Exemple #19
0
 static final void method547(
     int i, int i_86_, int i_87_, int i_88_, boolean[][] bools, int[][] is) {
   GL gl = Class97.aGL1536;
   Class97.method1546(1);
   Class97.method1553(1);
   Class97.method1538();
   Class97.method1518(false);
   Class83_Sub14.method943(116, 0, 0);
   gl.glDepthMask(false);
   for (int i_89_ = 0; i_89_ < anInt941; i_89_++) {
     for (int i_90_ = 0; i_90_ < anInt944; i_90_++) {
       while_57_:
       for (int i_91_ = i_89_ * 8; i_91_ < i_89_ * 8 + 8; i_91_++) {
         if (i_91_ - i >= -i_87_ && i_91_ - i <= i_87_) {
           for (int i_92_ = i_90_ * 8; i_92_ < i_90_ * 8 + 8; i_92_++) {
             if (i_92_ - i_86_ >= -i_87_
                 && i_92_ - i_86_ <= i_87_
                 && (bools[i_91_ - i + i_87_][i_92_ - i_86_ + i_87_])) {
               Class38 class38 = aClass38ArrayArray940[i_89_][i_90_];
               if (((Class38) class38).aBoolean718) {
                 class38.method351(aClass17_Sub1_942, i_89_, i_90_);
                 ((Class38) class38).aBoolean718 = false;
               }
               gl.glPushMatrix();
               gl.glTranslatef((float) (i_89_ * 1024), 0.0F, (float) (i_90_ * 1024));
               class38.method354();
               gl.glPopMatrix();
               break while_57_;
             }
           }
         }
       }
     }
   }
   gl.glEnableClientState(32886);
   gl.glDepthMask(true);
   Class97.method1552();
 }
Exemple #20
0
  public void draw() {
    if (!isTiling) {
      psys.update(srcImage.getPixels(), dstImage.getPixels());
    }

    tiler.pre();

    background(0);

    srcImage.draw();
    //		dstImage.draw();

    // lights.
    if (isLightingEnabled) {
      gl.glEnable(GL.GL_LIGHTING);
      gl.glEnable(GL.GL_LIGHT1);
    } else {
      gl.glDisable(GL.GL_LIGHTING);
      gl.glDisable(GL.GL_LIGHT1);
    }

    // START DRAW.
    pgl.beginGL();
    gl.glPushMatrix();
    gl.glTranslatef(sceneCenterX, sceneCenterY, sceneCenterZ);
    drawSomething();
    gl.glPopMatrix();
    pgl.endGL();

    tiler.post();
    if (!tiler.checkStatus() && isTiling) {
      isTiling = false;
    }

    if (isRecording) save("export/image" + frameCount + ".png");
  }
  protected void drawIcon(DrawContext dc, SurfaceTileDrawContext sdc) {
    if (this.locations == null) return;

    GL gl = dc.getGL();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    double drawScale = 1;
    TextureCoords textureCoords = new TextureCoords(0, 0, 1, 1);

    // Compute draw scale only once if not maintaining strict appearance
    if (!this.isMaintainAppearance()) drawScale = this.computeDrawScale(dc, sdc, null);
    // Determine which locations are to be drawn
    Iterable<? extends LatLon> drawLocations = this.computeDrawLocations(dc, sdc);
    // Draw icons
    for (LatLon location : drawLocations) {
      gl.glPushMatrix();

      if (this.isMaintainAppearance()) drawScale = this.computeDrawScale(dc, sdc, location);
      this.applyDrawTransform(dc, sdc, location, drawScale);
      gl.glScaled(this.imageWidth, this.imageHeight, 1d);
      dc.drawUnitQuad(textureCoords);

      gl.glPopMatrix();
    }
  }
  // Rendering
  public void draw(DrawContext dc) {
    GL gl = dc.getGL();

    boolean attribsPushed = false;
    boolean modelviewPushed = false;
    boolean projectionPushed = false;

    try {
      gl.glPushAttrib(
          GL.GL_DEPTH_BUFFER_BIT
              | GL.GL_COLOR_BUFFER_BIT
              | GL.GL_ENABLE_BIT
              | GL.GL_TEXTURE_BIT
              | GL.GL_TRANSFORM_BIT
              | GL.GL_VIEWPORT_BIT
              | GL.GL_CURRENT_BIT);
      attribsPushed = true;

      gl.glDisable(GL.GL_TEXTURE_2D); // no textures

      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      gl.glDisable(GL.GL_DEPTH_TEST);

      double width = this.size.width;
      double height = this.size.height;

      // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
      // into the GL projection matrix.
      java.awt.Rectangle viewport = dc.getView().getViewport();
      gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION);
      gl.glPushMatrix();
      projectionPushed = true;
      gl.glLoadIdentity();
      double maxwh = width > height ? width : height;
      gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glPushMatrix();
      modelviewPushed = true;
      gl.glLoadIdentity();

      // Scale to a width x height space
      // located at the proper position on screen
      double scale = this.computeScale(viewport);
      Vec4 locationSW = this.computeLocation(viewport, scale);
      gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
      gl.glScaled(scale, scale, 1);

      // Compute scale size in real world
      Position referencePosition = dc.getViewportCenterPosition();
      if (referencePosition != null) {
        Vec4 groundTarget = dc.getGlobe().computePointFromPosition(referencePosition);
        Double distance = dc.getView().getEyePoint().distanceTo3(groundTarget);
        this.pixelSize = dc.getView().computePixelSizeAtDistance(distance);
        Double scaleSize = this.pixelSize * width * scale; // meter
        String unitLabel = "m";
        if (this.unit.equals(UNIT_METRIC)) {
          if (scaleSize > 10000) {
            scaleSize /= 1000;
            unitLabel = "Km";
          }
        } else if (this.unit.equals(UNIT_IMPERIAL)) {
          scaleSize *= 3.280839895; // feet
          unitLabel = "ft";
          if (scaleSize > 5280) {
            scaleSize /= 5280;
            unitLabel = "mile(s)";
          }
        }

        // Rounded division size
        int pot = (int) Math.floor(Math.log10(scaleSize));
        if (!Double.isNaN(pot)) {
          int digit = Integer.parseInt(String.format("%.0f", scaleSize).substring(0, 1));
          double divSize = digit * Math.pow(10, pot);
          if (digit >= 5) divSize = 5 * Math.pow(10, pot);
          else if (digit >= 2) divSize = 2 * Math.pow(10, pot);
          double divWidth = width * divSize / scaleSize;

          // Draw scale
          if (!dc.isPickingMode()) {
            // Set color using current layer opacity
            Color backColor = this.getBackgroundColor(this.color);
            float[] colorRGB = backColor.getRGBColorComponents(null);
            gl.glColor4d(
                colorRGB[0],
                colorRGB[1],
                colorRGB[2],
                (double) backColor.getAlpha() / 255d * this.getOpacity());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawScale(dc, divWidth, height);

            colorRGB = this.color.getRGBColorComponents(null);
            gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity());
            gl.glTranslated(-1d / scale, 1d / scale, 0d);
            this.drawScale(dc, divWidth, height);

            // Draw label
            String label = String.format("%.0f ", divSize) + unitLabel;
            gl.glLoadIdentity();
            gl.glDisable(GL.GL_CULL_FACE);
            drawLabel(
                dc,
                label,
                locationSW.add3(
                    new Vec4(divWidth * scale / 2 + (width - divWidth) / 2, height * scale, 0)));
          } else {
            // Picking
            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);
            // Draw unique color across the map
            Color color = dc.getUniquePickColor();
            int colorCode = color.getRGB();
            // Add our object(s) to the pickable list
            this.pickSupport.addPickableObject(colorCode, this, referencePosition, false);
            gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawRectangle(dc, divWidth, height);
            // Done picking
            this.pickSupport.endPicking(dc);
            this.pickSupport.resolvePick(dc, dc.getPickPoint(), this);
          }
        }
      }
    } finally {
      if (projectionPushed) {
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glPopMatrix();
      }
      if (modelviewPushed) {
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glPopMatrix();
      }
      if (attribsPushed) gl.glPopAttrib();
    }
  }
Exemple #23
0
  public void display(GLAutoDrawable glDrawable) {
    GL gl = glDrawable.getGL();

    // Store old matrices
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glViewport(0, 0, glDrawable.getWidth(), glDrawable.getHeight());

    // Store enabled state and disable lighting, texture mapping and the depth buffer
    gl.glPushAttrib(GL.GL_ENABLE_BIT);
    gl.glDisable(GL.GL_BLEND);
    gl.glDisable(GL.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Retrieve the current viewport and switch to orthographic mode
    IntBuffer viewPort = BufferUtil.newIntBuffer(4);
    gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort);
    glu.gluOrtho2D(0, viewPort.get(2), viewPort.get(3), 0);

    // Render the text
    gl.glColor3f(1, 1, 1);

    int x = OFFSET;
    int maxx = 0;
    int y = OFFSET + CHAR_HEIGHT;

    if (keyboardEntries.size() > 0) {
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS);
      maxx =
          Math.max(
              maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS));

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < keyboardEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        String text = (String) keyboardEntries.get(i);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, text);
        maxx = Math.max(maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, text));
        y += OFFSET;
      }
    }

    if (mouseEntries.size() > 0) {
      x = maxx + OFFSET;
      y = OFFSET + CHAR_HEIGHT;
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, MOUSE_CONTROLS);

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < mouseEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, (String) mouseEntries.get(i));
        y += OFFSET;
      }
    }

    // Restore enabled state
    gl.glPopAttrib();

    // Restore old matrices
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();
  }
  /**
   * Render the geometry now.
   *
   * @param gl The GL context to render with
   */
  public void render(GL gl) {
    gl.glBegin(GL.GL_LINES);
    gl.glColor3f(0, 0, 1);

    gl.glVertex3f(minBounds[0], minBounds[1], minBounds[2]);
    gl.glVertex3f(minBounds[0], minBounds[1], maxBounds[2]);

    gl.glVertex3f(minBounds[0], minBounds[1], minBounds[2]);
    gl.glVertex3f(minBounds[0], maxBounds[1], minBounds[2]);

    gl.glVertex3f(minBounds[0], minBounds[1], minBounds[2]);
    gl.glVertex3f(maxBounds[0], minBounds[1], minBounds[2]);

    gl.glVertex3f(maxBounds[0], maxBounds[1], maxBounds[2]);
    gl.glVertex3f(maxBounds[0], maxBounds[1], minBounds[2]);

    gl.glVertex3f(maxBounds[0], maxBounds[1], maxBounds[2]);
    gl.glVertex3f(maxBounds[0], minBounds[1], maxBounds[2]);

    gl.glVertex3f(maxBounds[0], maxBounds[1], maxBounds[2]);
    gl.glVertex3f(minBounds[0], maxBounds[1], maxBounds[2]);

    gl.glVertex3f(minBounds[0], minBounds[1], maxBounds[2]);
    gl.glVertex3f(minBounds[0], maxBounds[1], maxBounds[2]);

    gl.glVertex3f(minBounds[0], minBounds[1], maxBounds[2]);
    gl.glVertex3f(maxBounds[0], minBounds[1], maxBounds[2]);

    gl.glVertex3f(minBounds[0], maxBounds[1], maxBounds[2]);
    gl.glVertex3f(minBounds[0], maxBounds[1], minBounds[2]);

    gl.glVertex3f(maxBounds[0], maxBounds[1], minBounds[2]);
    gl.glVertex3f(minBounds[0], maxBounds[1], minBounds[2]);

    gl.glVertex3f(maxBounds[0], maxBounds[1], minBounds[2]);
    gl.glVertex3f(maxBounds[0], minBounds[1], minBounds[2]);

    gl.glVertex3f(maxBounds[0], minBounds[1], minBounds[2]);
    gl.glVertex3f(maxBounds[0], minBounds[1], maxBounds[2]);
    gl.glEnd();

    if (showParent) {
      gl.glPopMatrix();

      gl.glBegin(GL.GL_LINES);
      gl.glColor3f(1, 0, 1);

      gl.glVertex3f(minBox[0], minBox[1], minBox[2]);
      gl.glVertex3f(minBox[0], minBox[1], maxBox[2]);

      gl.glVertex3f(minBox[0], minBox[1], minBox[2]);
      gl.glVertex3f(minBox[0], maxBox[1], minBox[2]);

      gl.glVertex3f(minBox[0], minBox[1], minBox[2]);
      gl.glVertex3f(maxBox[0], minBox[1], minBox[2]);

      gl.glVertex3f(maxBox[0], maxBox[1], maxBox[2]);
      gl.glVertex3f(maxBox[0], maxBox[1], minBox[2]);

      gl.glVertex3f(maxBox[0], maxBox[1], maxBox[2]);
      gl.glVertex3f(maxBox[0], minBox[1], maxBox[2]);

      gl.glVertex3f(maxBox[0], maxBox[1], maxBox[2]);
      gl.glVertex3f(minBox[0], maxBox[1], maxBox[2]);

      gl.glVertex3f(minBox[0], minBox[1], maxBox[2]);
      gl.glVertex3f(minBox[0], maxBox[1], maxBox[2]);

      gl.glVertex3f(minBox[0], minBox[1], maxBox[2]);
      gl.glVertex3f(maxBox[0], minBox[1], maxBox[2]);

      gl.glVertex3f(minBox[0], maxBox[1], maxBox[2]);
      gl.glVertex3f(minBox[0], maxBox[1], minBox[2]);

      gl.glVertex3f(maxBox[0], maxBox[1], minBox[2]);
      gl.glVertex3f(minBox[0], maxBox[1], minBox[2]);

      gl.glVertex3f(maxBox[0], maxBox[1], minBox[2]);
      gl.glVertex3f(maxBox[0], minBox[1], minBox[2]);

      gl.glVertex3f(maxBox[0], minBox[1], minBox[2]);
      gl.glVertex3f(maxBox[0], minBox[1], maxBox[2]);
      gl.glEnd();

      // Push it back down again as the next call after this will pop it
      gl.glPushMatrix();
    }
  }
Exemple #25
0
 public void restoreGLMatrices() {
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glPopMatrix();
   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glPopMatrix();
 }
Exemple #26
0
  public void prerenderToTexture(GL gl) {
    int texSize = 256;
    final int[] tmp = new int[1];
    gl.glGenTextures(1, tmp, 0);
    textureID = tmp[0];
    gl.glBindTexture(GL_TEXTURE_2D, textureID);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    gl.glTexImage2D(
        GL_TEXTURE_2D, 0, GL_RGBA, texSize, texSize, 0, GL_BGRA, GL_UNSIGNED_BYTE, null);

    final int[] fbo = new int[1];
    gl.glGenFramebuffersEXT(1, IntBuffer.wrap(fbo));
    gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[0]);
    gl.glFramebufferTexture2DEXT(
        GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureID, 0);

    gl.glDrawBuffers(1, IntBuffer.wrap(new int[] {GL_COLOR_ATTACHMENT0_EXT}));

    final int[] rba = new int[1];
    gl.glGenRenderbuffersEXT(1, IntBuffer.wrap(rba));
    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rba[0]);
    gl.glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texSize, texSize);
    gl.glFramebufferRenderbufferEXT(
        GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rba[0]);

    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glPushAttrib(GL_VIEWPORT_BIT);
    gl.glViewport(0, 0, texSize, texSize);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrtho(0, texSize, 0, texSize, 0, 10);
    gl.glMatrixMode(GL.GL_MODELVIEW);

    Set<MapElement> map = State.getInstance().getMapInfo().queryElements(detailLevel, bounds, true);

    gl.glDisable(GL_TEXTURE_2D);
    gl.glColor3f(1, 1, 1);
    for (MapElement element : map) {
      if (element instanceof Street) {
        drawLine(
            gl,
            ((Street) element).getDrawingSize() / (float) Projection.getZoomFactor(detailLevel),
            ((Street) element).getNodes());
      }
    }
    gl.glColor3f(0.3f, 0.3f, 0.3f);
    for (MapElement element : map) {
      if ((element instanceof Area) && (((Area) element).getWayInfo().isBuilding())) {
        gl.glBegin(GL_POLYGON);
        for (Node node : ((Area) element).getNodes()) {
          Coordinates pos = getLocalCoordinates(node.getPos());
          gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), 0f);
        }
        gl.glEnd();
      }
    }

    gl.glEnable(GL_TEXTURE_2D);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopAttrib();
    gl.glPopMatrix();

    gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    gl.glDeleteFramebuffersEXT(1, fbo, 0);
    gl.glDeleteRenderbuffersEXT(1, rba, 0);
  }
  public void display(GLAutoDrawable gLDrawable) {
    key = Input.keysPressed();

    double dt = (System.currentTimeMillis() - dt_timer) / 1000.0;
    dt_timer = System.currentTimeMillis();

    // Start 3d Rendering
    GL gl = gLDrawable.getGL();

    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    gl.glLoadIdentity();

    GLU glu = new GLU();

    // Code to adjust camera
    if (input.getKey(KeyEvent.VK_UP)) z -= .5 * dt;
    if (input.getKey(KeyEvent.VK_DOWN)) z += .5 * dt;

    if (input.getKey(KeyEvent.VK_LEFT)) y -= .5 * dt;
    if (input.getKey(KeyEvent.VK_RIGHT)) y += .5 * dt;
    if (input.getKey(KeyEvent.VK_SPACE)) System.out.println(y + " " + z);

    glu.gluLookAt(0, y, z, 0, 0, -3, 0, 1, 0);

    // orangeNote.drawBar(gLDrawable, zTest);
    // redNote.draw(gLDrawable, -3f, -4f, zTest);
    // yellowNote.draw(gLDrawable, -1.5f, -4f, zTest);
    // blueNote.draw(gLDrawable, 0f, -4f, zTest);
    // greenNote.draw(gLDrawable, 1.5f, -4f, zTest);
    zTest += 0.005f;
    if (zTest > -2f) zTest = -10f;

    gl.glPushMatrix();
    gl.glEnable(GL.GL_BLEND);
    // gl.glRotatef(70,1,-2,1);

    gl.glBegin(GL.GL_QUADS);
    // Draw the Board
    // x goes basically from -1 to 1(camera changed tho)
    // y stays same
    // board length is -z
    gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); // R,G,B,A
    gl.glVertex3f(-3f, -4f, 0f); // x,y,z

    gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f);
    gl.glVertex3f(3f, -4f, 0f);

    gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f);
    gl.glVertex3f(3f, -4f, -10f);

    gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f);
    gl.glVertex3f(-3f, -4f, -10f);

    // All y values on top of the Board must have at least
    // 0.0001f added for some reason
    // Bottom bar - Orange
    gl.glColor4f(255 / 256f, 165 / 256f, 0 / 256f, 1f);
    gl.glVertex3f(-3f, -4f + .0001f, -2.15f); // close left
    gl.glVertex3f(3f, -4f + .0001f, -2.15f); // close right
    gl.glVertex3f(3f, -4f + .0001f, -2.85f); // far right
    gl.glVertex3f(-3f, -4f + .0001f, -2.85f); // far left
    // RedNote
    gl.glColor4f(1f, 0f, 0f, 1f);
    gl.glVertex3f(-3f, -4f + .001f, -2.25f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.75f);
    gl.glVertex3f(-3f, -4f + .001f, -2.75f);
    // YellowNote
    gl.glColor4f(1f, 1f, 0f, 1f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(0f, -4f + .001f, -2.25f);
    gl.glVertex3f(0f, -4f + .001f, -2.75f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.75f);
    // BlueNote
    gl.glColor4f(0f, 0f, 1f, 1f);
    gl.glVertex3f(0f, -4f + .001f, -2.25f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.75f);
    gl.glVertex3f(0f, -4f + .001f, -2.75f);
    // GreenNote
    gl.glColor4f(0f, 1f, 0f, 1f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(3f, -4f + .001f, -2.25f);
    gl.glVertex3f(3f, -4f + .001f, -2.75f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.75f);
    // End Bottom Bar

    this.renderNotes(gLDrawable, dt);

    /////////////////////////////////////
    gl.glEnd();

    gl.glDisable(GL.GL_BLEND);
    gl.glPopMatrix();

    try {
      Thread.sleep(1);
    } catch (Exception e) {
    }
  }
  /**
   * Draws the five sides of the hemicube into the provided drawable
   *
   * @param drawable
   * @param which
   * @param near
   * @param far
   * @param bCollect
   */
  public void drawHemiCube(
      GLAutoDrawable drawable, int which, double near, double far, boolean bCollect) {

    // TODO - PART 1 - DRAW HEMICUBE!

    GL gl = drawable.getGL();
    GLU glu = new GLU();

    /* Return the face based on which parameter */
    int[] vertices = scene.getObject().getFace(which);

    /* Find the center of the face */
    /* Center of the face is the average of the three vertices */

    /* Using returned list of vertex indices, find the vertices
     * corresponding to a particular face */
    Vertex v1 = scene.getObject().vertexList.get(vertices[0]);
    Vertex v2 = scene.getObject().vertexList.get(vertices[1]);
    Vertex v3 = scene.getObject().vertexList.get(vertices[2]);

    /* Locate center of face */
    /* Average of three vertices */
    Point3d centerPoint = new Point3d();
    centerPoint = new Point3d(v1.p);
    centerPoint.add(v2.p);
    centerPoint.add(v3.p);
    centerPoint.scale(0.33333);

    /* Set up camera frame */

    /* --- Surface normal --- */
    /* Declare points of vertex for face */
    Point3d p1 = new Point3d(v1.p);
    Point3d p2 = new Point3d(v2.p);
    Point3d p3 = new Point3d(v3.p);

    /* Declare vector u as p2-p1 */
    Point3d uVec = new Point3d(p2);
    uVec.sub(p1);
    Vector3d u = new Vector3d(uVec);

    /* Declare vector v as p3-p1 */
    Point3d vVec = new Point3d(p3);
    vVec.sub(p1);
    Vector3d v = new Vector3d(vVec);

    /* Make normal vector */
    Vector3d norm = new Vector3d();
    norm.cross(u, v);

    /* --- Vectors Orthonormal to Normal --- */
    Point3d vec1pt = new Point3d(p1);
    vec1pt.sub(p2);
    Vector3d vec1 = new Vector3d(vec1pt);
    vec1.cross(vec1, norm); // Cross surface normal with vec1 to get orthogonal vector

    Vector3d vec2 = new Vector3d();
    vec2.cross(
        norm,
        vec1); // Cross product of surface normal with new vector vec1 to get 2nd orthogonal vector

    /* Make unit vectors */
    norm.normalize();
    vec1.normalize();
    vec2.normalize();

    /* Set up the five different frustums, and stitch together using viewPort */
    /* Viewport to set up the view of the scene */

    /* ----- FRONT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight() / 3);

    /* Set up frustums for this face */

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + norm.x,
        centerPoint.y + norm.y,
        centerPoint.z + norm.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- BOTTOM FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(0, drawable.getHeight() / 3, drawable.getWidth(), drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, 0, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + (-vec1.x),
        centerPoint.y + (-vec1.y),
        centerPoint.z + (-vec1.z),
        centerPoint.x + norm.x,
        centerPoint.y + norm.y,
        centerPoint.z + norm.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- TOP FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, -near, 0, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z,
        centerPoint.x - norm.x,
        centerPoint.y - norm.y,
        centerPoint.z - norm.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- LEFT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + 2 * (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(0, near, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + vec2.x,
        centerPoint.y + vec2.y,
        centerPoint.z + vec2.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- RIGHT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + 3 * (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(near, 0, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + (-vec2.x),
        centerPoint.y + (-vec2.y),
        centerPoint.z + (-vec2.z),
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ---- End Frustums ---- */

    // if collecting the form factors, then read back and process the data
    if (bCollect) {
      gl.glFlush();
      gl.glFinish();
      gl.glReadPixels(
          0, 0, divisions * 2, divisions * 6, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelDataBuffer);
      collectData(which);
    }
  }
Exemple #29
0
  @Override
  public void render(final DrawContext dc) {
    //      _lastDC = dc;

    runFrameWorkers();

    final GTexture texture = getTexture();
    if ((texture == null) || !texture.hasGLTexture()) {
      return;
    }

    final GL gl = dc.getGL();

    gl.glPushAttrib(
        GL.GL_DEPTH_BUFFER_BIT
            | GL.GL_COLOR_BUFFER_BIT
            | GL.GL_ENABLE_BIT
            | GL.GL_TEXTURE_BIT
            | GL.GL_TRANSFORM_BIT
            | GL.GL_VIEWPORT_BIT
            | GL.GL_CURRENT_BIT);

    gl.glEnable(GL.GL_BLEND);
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
    // into the GL projection matrix.
    final Rectangle viewport = dc.getView().getViewport();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    final double maxwh = Math.max(_textureWidth, _textureHeight);
    gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    // Translate and scale
    final float scale = computeScale(viewport);
    final Vec4 locationSW = computeLocation(viewport, scale);
    gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
    // Scale to 0..1 space
    gl.glScalef(scale, scale, 1f);
    gl.glScaled(_textureWidth, _textureHeight, 1d);

    _lastScreenBounds = calculateScreenBounds(viewport, locationSW, scale);

    texture.enable();
    texture.bind();
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);

    gl.glColor4f(1, 1, 1, calculateOpacity());
    dc.drawUnitQuad(texture.getImageTexCoords());

    texture.disable();

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();

    gl.glPopAttrib();
  }