예제 #1
0
  public void display(GLAutoDrawable drawable) {
    // System.err.println("SceneUIController: display");
    final int width = drawable.getWidth();
    final int height = drawable.getHeight();
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    render(gl, width, height, renderModes, texSize, false);
  }
예제 #2
0
  public UIShape getShape(GLAutoDrawable drawable, int x, int y) {
    final int width = drawable.getWidth();
    final int height = drawable.getHeight();
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    int index = checkSelection(gl, x, y, width, height);
    if (index == -1) return null;
    return shapes.get(index);
  }
예제 #3
0
  /**
   * Setup the viewport correctly in case it was changed.
   *
   * @param drawable the GLAutoDrawable object to access openGL
   */
  @SuppressWarnings("nls")
  private void setupViewport(final GLAutoDrawable drawable) {

    if (drawable.getContext() == null) {
      return;
    }

    boolean releaseContext = false;
    if (GLContext.getCurrent() == null) {
      drawable.getContext().makeCurrent();
      releaseContext = true;
    }
    GL2ES1 gl = null;

    if (drawable.getGLProfile().hasGLSL()) {
      gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
    } else if (drawable.getGLProfile().isGL2ES1()) {
      gl = drawable.getGL().getGL2ES1();
    } else {
      if (releaseContext) {
        drawable.getContext().release();
      }
      throw new GraphicsJOGLException(
          "Invalid GL profile. Failed to setup Viewport.", drawable.getGLProfile());
    }

    gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, drawable.getWidth(), drawable.getHeight(), 0, -9999, 9999);
    //        GLU.createGLU().gluOrtho2D(0, drawable.getWidth(), 0,
    //            drawable.getHeight());
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glLoadIdentity();

    if (releaseContext) {
      drawable.getContext().release();
    }
  }
예제 #4
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   System.err.println(
       Thread.currentThread().getName()
           + ": ** reshape: "
           + reshapeCount
           + ": "
           + width
           + "x"
           + height
           + " - "
           + drawable.getWidth()
           + "x"
           + drawable.getHeight());
   reshapeCount++;
 }
예제 #5
0
 public void display(GLAutoDrawable drawable) {
   final GL gl = drawable.getGL();
   System.err.println(
       Thread.currentThread().getName()
           + ": ** display: "
           + displayCount
           + ": "
           + drawable.getWidth()
           + "x"
           + drawable.getHeight()
           + ", makeShot "
           + makeShot);
   if (makeShot) {
     makeShot = false;
     snapshot(displayCount, null, gl, screenshot, TextureIO.PNG, null);
   }
   displayCount++;
 }
예제 #6
0
 public void printScreen(
     int renderModes, GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha)
     throws GLException, IOException {
   final String modeS = Region.getRenderModeString(renderModes);
   final String bname =
       String.format(
           "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d",
           objName,
           drawable.getChosenGLCapabilities().getNumSamples(),
           TestTextRendererNEWT00.fontSizeFixed,
           drawable.getWidth(),
           drawable.getHeight(),
           modeS,
           vbaaSampleCount[0]);
   final String filename = dir + bname + ".png";
   if (screenshot.readPixels(drawable.getGL(), false)) {
     screenshot.write(new File(filename));
   }
 }
예제 #7
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();
  }
예제 #8
0
 @Override
 public boolean run(GLAutoDrawable drawable) {
   listener.reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight());
   return true;
 }
예제 #9
0
 @Override
 public boolean run(GLAutoDrawable drawable) {
   drawable.getGL().glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
   return true;
 }
예제 #10
0
  @Override
  public void display(GLAutoDrawable a) {
    GL2 gl2 = a.getGL().getGL2();

    this.basicClear(gl2);

    width = a.getWidth();
    height = a.getHeight();

    if (!pause) {
      juliaImaginary += juliaInc;
      if (juliaImaginary >= 0.95f) juliaInc = -juliaInc;
      else if (juliaImaginary <= 0.3f) juliaInc = -juliaInc;
    }

    //      juliaReal += juliaInc2;
    //      if (juliaReal >= 0.38f)
    //         juliaInc2 = -juliaInc2;
    //      else if (juliaImaginary <= 0.35f)
    //         juliaInc2 = -juliaInc2;

    gl2.glMatrixMode(GL2.GL_PROJECTION);
    gl2.glLoadIdentity();
    gl2.glOrtho(0, 1, 0, 1, -1, 1);
    gl2.glMatrixMode(GL2.GL_MODELVIEW);
    gl2.glLoadIdentity();

    gl2.glColor3d(0.5, 0.5, 0);
    shader.bind(gl2);
    // Set shader uniform variables
    if (use64 == true) {
      shader.setUniform1i(gl2, "width", width);
      shader.setUniform1i(gl2, "height", height);
      shader.setUniform1i(gl2, "iter", iteration);

      shader.setUniformf(gl2, "cminX1", (float) dcminx);
      shader.setUniformf(gl2, "cminX2", (float) (dcminx - (double) ((float) dcminx)));

      shader.setUniformf(gl2, "cminY1", (float) dcminy);
      shader.setUniformf(gl2, "cminY2", (float) (dcminy - (double) ((float) dcminy)));

      shader.setUniformf(gl2, "cmaxX1", (float) dcmaxx);
      shader.setUniformf(gl2, "cmaxX2", (float) (dcmaxx - (double) ((float) dcmaxx)));

      shader.setUniformf(gl2, "cmaxY1", (float) dcmaxy);
      shader.setUniformf(gl2, "cmaxY2", (float) (dcmaxy - (double) ((float) dcmaxy)));

      shader.setUniformf(gl2, "juliaImaginary", juliaImaginary);
      shader.setUniformf(gl2, "juliaReal", juliaReal);

    } else {
      shader.setUniform1i(gl2, "width", width);
      shader.setUniform1i(gl2, "height", height);
      shader.setUniform1i(gl2, "iter", iteration);

      shader.setUniformf(gl2, "cminX", cminx);
      shader.setUniformf(gl2, "cminY", cminy);
      shader.setUniformf(gl2, "cmaxX", cmaxx);
      shader.setUniformf(gl2, "cmaxY", cmaxy);

      shader.setUniform1i(gl2, "flag", flag);

      shader.setUniformf(gl2, "juliaImaginary", juliaImaginary);
      shader.setUniformf(gl2, "juliaReal", juliaReal);
    }

    // Draw an empty quad so the fragments can propagate to the fragment shader
    gl2.glBegin(GL2.GL_QUADS);
    gl2.glVertex3d(0, 0, 0);
    gl2.glVertex3d(1, 0, 0);
    gl2.glVertex3d(1, 1, 0);
    gl2.glVertex3d(0, 1, 0);
    gl2.glEnd();
    shader.unbind(gl2);

    // iteration ++;
    // if (iteration >= 64) iteration = 1;

    // canvas.swapBuffers();
  }
예제 #11
0
 @Override
 protected void render(GL2 gl, GLAutoDrawable drawable) {
   renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
   renderer.draw("No time.", 25, 25);
   renderer.endRendering();
 }
예제 #12
0
  /**
   * 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);
    }
  }