예제 #1
0
  // private void pickSquares(GL gl, int button, int state, int x, int y)
  private void pickSquares(GL2 gl) {
    int selectBuf[] = new int[BUFSIZE];
    IntBuffer selectBuffer = IntBuffer.wrap(selectBuf);
    int hits;
    int viewport[] = new int[4];

    // if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return;

    gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0);

    gl.glSelectBuffer(BUFSIZE, selectBuffer);
    gl.glRenderMode(GL2.GL_SELECT);

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

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    /* create 5x5 pixel picking region near cursor location */
    glu.gluPickMatrix(
        (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), 5.0, 5.0, viewport, 0);
    glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0);
    drawSquares(gl, GL2.GL_SELECT);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glFlush();

    hits = gl.glRenderMode(GL2.GL_RENDER);
    selectBuffer.get(selectBuf);
    processHits(hits, selectBuf);
  }
예제 #2
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f);

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, 0.5f, 0.0f);
    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);

    glut.glutSolidTorus(0.275f, 0.85f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, -0.5f, 0.0f);
    gl.glRotatef(270.0f, 1.0f, 0.0f, 0.0f);
    glut.glutSolidCone(1.0f, 2.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.75f, 0.0f, -1.0f);
    glut.glutSolidSphere(1.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPopMatrix();
    gl.glFlush();
  }
예제 #3
0
파일: clip.java 프로젝트: jzy3d/glredbook
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    double eqn[] = {0.0, 1.0, 0.0, 0.0};
    double eqn2[] = {1.0, 0.0, 0.0, 0.0};

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glPushMatrix();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    /* clip lower half -- y < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE0, eqn, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE0);
    /* clip left half -- x < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE1, eqn2, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE1);

    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glut.glutWireSphere(1.0, 20, 16);
    gl.glPopMatrix();

    gl.glFlush();
  }
예제 #4
0
  /*
   * sets up selection mode, name stack, and projection matrix for picking.
   * Then the objects are drawn.
   */
  private void pickRects(GL2 gl) {
    int[] selectBuf = new int[BUFSIZE];
    IntBuffer selectBuffer = GLBuffers.newDirectIntBuffer(BUFSIZE);
    int hits;
    int viewport[] = new int[4];
    // int x, y;

    gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);

    gl.glSelectBuffer(BUFSIZE, selectBuffer);
    gl.glRenderMode(GL2.GL_SELECT);

    gl.glInitNames();
    gl.glPushName(-1);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    /* create 5x5 pixel picking region near cursor location */
    glu.gluPickMatrix(
        (double) pickPoint.x,
        (double) (viewport[3] - pickPoint.y), //
        5.0,
        5.0,
        viewport,
        0);
    gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
    drawRects(gl, GL2.GL_SELECT);
    gl.glPopMatrix();
    gl.glFlush();

    hits = gl.glRenderMode(GL2.GL_RENDER);
    selectBuffer.get(selectBuf);
    processHits(hits, selectBuf);
  }
예제 #5
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (derefMethod == DRAWARRAY) {
      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6);
    } else if (derefMethod == ARRAYELEMENT) {
      gl.glBegin(GL2.GL_TRIANGLES);
      gl.glArrayElement(2);
      gl.glArrayElement(3);
      gl.glArrayElement(5);
      gl.glEnd();
    } else if (derefMethod == DRAWELEMENTS) {
      int indices[] = new int[] {0, 1, 3, 4};
      if (indicesBuf == null) {
        indicesBuf = GLBuffers.newDirectIntBuffer(indices.length);
        indicesBuf.put(indices);
      }
      indicesBuf.rewind();
      gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf);
    }
    gl.glFlush();

    // gl calls from C example's mouse routine are moved here
    if (setupMethod == INTERLEAVED) setupInterleave(gl);
    else if (setupMethod == POINTER) setupPointers(gl);
  }
예제 #6
0
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   pickRects(gl);
   drawRects(gl, GL2.GL_RENDER);
   gl.glFlush();
 }
예제 #7
0
파일: dof.java 프로젝트: jzy3d/glredbook
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    int jitter;
    int viewport[] = new int[4];

    gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
    gl.glClear(GL2.GL_ACCUM_BUFFER_BIT);

    for (jitter = 0; jitter < 8; jitter++) {
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      accPerspective(
          gl,
          45.0,
          (double) viewport[2] / (double) viewport[3],
          1.0,
          15.0,
          0.0,
          0.0,
          0.33 * j8[jitter].x,
          0.33 * j8[jitter].y,
          5.0);

      /* ruby, gold, silver, emerald, and cyan teapots */
      renderTeapot(
          gl, -1.1f, -0.5f, -4.5f, 0.1745f, 0.01175f, 0.01175f, 0.61424f, 0.04136f, 0.04136f,
          0.727811f, 0.626959f, 0.626959f, 0.6f);
      renderTeapot(
          gl, -0.5f, -0.5f, -5.0f, 0.24725f, 0.1995f, 0.0745f, 0.75164f, 0.60648f, 0.22648f,
          0.628281f, 0.555802f, 0.366065f, 0.4f);
      renderTeapot(
          gl, 0.2f, -0.5f, -5.5f, 0.19225f, 0.19225f, 0.19225f, 0.50754f, 0.50754f, 0.50754f,
          0.508273f, 0.508273f, 0.508273f, 0.4f);
      renderTeapot(
          gl, 1.0f, -0.5f, -6.0f, 0.0215f, 0.1745f, 0.0215f, 0.07568f, 0.61424f, 0.07568f, 0.633f,
          0.727811f, 0.633f, 0.6f);
      renderTeapot(
          gl,
          1.8f,
          -0.5f,
          -6.5f,
          0.0f,
          0.1f,
          0.06f,
          0.0f,
          0.50980392f,
          0.50980392f,
          0.50196078f,
          0.50196078f,
          0.50196078f,
          .25f);
      gl.glAccum(GL2.GL_ACCUM, 0.125f);
    }
    gl.glAccum(GL2.GL_RETURN, 1.0f);
    gl.glFlush();
  }
예제 #8
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    if (pickPoint != null) {
      pickSquares(gl);
    }

    drawSquares(gl, GL2.GL_RENDER);

    gl.glFlush();
  }
예제 #9
0
  @Override
  public void display(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    // Fonts draw selves at the current raster position
    gl.glRasterPos2f(right - (right + 2.0f), bottom + 1);
    caption = "Please wait... drawing frames";
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, caption);

    drawByLevel();

    gl.glFlush();
  }
예제 #10
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, currentGenMode);
    gl.glTexGendv(GL2.GL_S, currentPlane, currentCoeff, 0);

    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);
    glut.glutSolidTeapot(2.0f);
    gl.glPopMatrix();
    gl.glFlush();
  }
예제 #11
0
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    GLUT glut = new GLUT();
    // limpa o buer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // dene que a matrix é a de modelo
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glScalef(delta, delta, delta); // faça a escala de todos objetos

    gl.glPushMatrix(); // armazena a matriz corrente
    gl.glTranslatef(-3, 0, 0);
    gl.glRotatef(beta, 0, 1, 0);
    gl.glRotatef(alpha, 1, 0, 0);
    gl.glColor3f(1, 1, 0);
    glut.glutWireSphere(1, 20, 20);

    // desenha um piso sob a esfera
    gl.glTranslatef(0, -1, 0);
    gl.glScalef(4, 0.1f, 4);
    gl.glColor3f(0, 0, 1);
    glut.glutSolidCube(1.0f);

    gl.glPopMatrix(); // restaura a matriz anterior

    gl.glPushMatrix(); // armazena a matriz corrente
    gl.glTranslatef(3, 0, 0);
    gl.glRotatef(beta, 0, 1, 0);
    gl.glRotatef(alpha, 1, 0, 0);
    gl.glColor3f(1, 0, 0);
    glut.glutWireSphere(1, 20, 20);

    // desenha um piso sob a esfera
    gl.glTranslatef(0, -1, 0);
    gl.glScalef(4, 0.1f, 4);
    gl.glColor3f(0, 1, 0);
    glut.glutSolidCube(1.0f);

    gl.glPopMatrix(); // restaura a matriz anterior
    // força o desenho das primitivas
    gl.glFlush();
  }
예제 #12
0
  public void display(GLAutoDrawable drawable) {
    final GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    mats.glMatrixMode(GL2.GL_MODELVIEW);
    mats.glLoadIdentity();
    mats.glTranslatef(0f, 0f, -2.0f);
    // t = t+0.5f;
    t = 40f;
    mats.glRotatef(t, 0f, 1f, 0f);
    mats.glMatrixMode(GL2.GL_PROJECTION);
    mats.glLoadIdentity();
    mats.glFrustumf(-1f, 1f, -1f, 1f, 1f, 100f);
    mats.update();
    gl.glUseProgram(shader.getID());
    gl.glUniformMatrix4fv(uniformMat, 3, false, mats.glGetPMvMviMatrixf());

    obj.display(gl, mats);
    gl.glFlush();
    gl.glUseProgram(0);
  }
예제 #13
0
  /*
   * display() draws a triangle at an angle.
   */
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (key != null)
      switch (key.getKeyChar()) {
        case 'c':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FRAGMENT_DEPTH);
          break;
        case 'C':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FOG_COORDINATE);
          break;

        case 'b':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, -0.25f);
          break;
        case 'f':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, 0.25f);
          break;
        default:
          break;
      }

    gl.glColor3f(1.0f, 0.75f, 0.0f);
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glFogCoordf(f1);
    gl.glVertex3f(2.0f, -2.0f, 0.0f);
    gl.glFogCoordf(f2);
    gl.glVertex3f(-2.0f, 0.0f, -5.0f);
    gl.glFogCoordf(f3);
    gl.glVertex3f(0.0f, 2.0f, -10.0f);
    gl.glEnd();

    gl.glFlush();
  }
예제 #14
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    int cnt = 0; // Local Counter Variable

    gl.glColor3f(1.0f, 0.5f, 0.5f); // Set Color To Bright Red
    glPrint(gl, 50, 16, 1, "Renderer"); // Display Renderer
    glPrint(gl, 80, 48, 1, "Vendor"); // Display Vendor Name
    glPrint(gl, 66, 80, 1, "Version"); // Display Version

    gl.glColor3f(1.0f, 0.7f, 0.4f); // Set Color To Orange
    // Display Renderer
    glPrint(gl, 200, 16, 1, gl.glGetString(GL.GL_RENDERER));
    glPrint(gl, 200, 48, 1, gl.glGetString(GL.GL_VENDOR)); // Display Vendor
    // Name
    glPrint(gl, 200, 80, 1, gl.glGetString(GL.GL_VERSION)); // Display
    // Version

    gl.glColor3f(0.5f, 0.5f, 1.0f); // Set Color To Bright Blue
    glPrint(gl, 192, 432, 1, "NeHe Productions"); // Write NeHe Productions
    // At The Bottom Of The
    // Screen

    gl.glLoadIdentity(); // Reset The ModelView Matrix
    gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color To White
    gl.glBegin(GL.GL_LINE_STRIP); // Start Drawing Line Strips (Something
    // New)
    gl.glVertex2d(639, 417); // Top Right Of Bottom Box
    gl.glVertex2d(0, 417); // Top Left Of Bottom Box
    gl.glVertex2d(0, 480); // Lower Left Of Bottom Box
    gl.glVertex2d(639, 480); // Lower Right Of Bottom Box
    gl.glVertex2d(639, 128); // Up To Bottom Right Of Top Box
    gl.glEnd(); // Done First Line Strip
    gl.glBegin(GL.GL_LINE_STRIP); // Start Drawing Another Line Strip
    gl.glVertex2d(0, 128); // Bottom Left Of Top Box
    gl.glVertex2d(639, 128); // Bottom Right Of Top Box
    gl.glVertex2d(639, 1); // Top Right Of Top Box
    gl.glVertex2d(0, 1); // Top Left Of Top Box
    gl.glVertex2d(0, 417); // Down To Top Left Of Bottom Box
    gl.glEnd(); // Done Second Line Strip

    gl.glScissor(
        1,
        (int) (0.135416f * sheight),
        swidth - 2,
        (int) (0.597916f * sheight)); // Define Scissor Region
    gl.glEnable(GL.GL_SCISSOR_TEST); // Enable Scissor Testing

    String text = gl.glGetString(GL.GL_EXTENSIONS); // Allocate Memory For
    // Our Extension String
    StringTokenizer tokenizer = new StringTokenizer(text);

    while (tokenizer.hasMoreTokens()) { // While The Token Isn't NULL
      cnt++; // Increase The Counter
      if (cnt > maxtokens) { // Is 'maxtokens' Less Than 'cnt'
        maxtokens = cnt; // If So, Set 'maxtokens' Equal To 'cnt'
      }

      gl.glColor3f(0.5f, 1.0f, 0.5f); // Set Color To Bright Green
      glPrint(gl, 0, 96 + (cnt * 32) - scroll, 0, "" + cnt); // Print
      // Current
      // Extension
      // Number
      gl.glColor3f(1.0f, 1.0f, 0.5f); // Set Color To Yellow
      // Print The Current Token (Parsed Extension Name)
      glPrint(gl, 50, 96 + (cnt * 32) - scroll, 0, tokenizer.nextToken());
    }
    gl.glDisable(GL.GL_SCISSOR_TEST); // Disable Scissor Testing
    gl.glFlush(); // Flush The Rendering Pipeline
  }
예제 #15
0
  public void updateSelectedOctant(GL2 gl, GLU glu, float[] mousePosition, float[] pickRectangle) {
    if (visibleLeaves > 0) {
      // Start Picking mode
      int capacity = 1 * 4 * visibleLeaves; // Each object take in maximium : 4 * name stack depth
      IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity);

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

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

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

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

      gl.glMatrixMode(GL2.GL_MODELVIEW);

      // Draw the nodes' cube int the select buffer
      List<Octant> visibleLeaves = new ArrayList<Octant>();
      for (Octant n : leaves) {
        if (n != null && n.visible) {
          int i = visibleLeaves.size() + 1;
          visibleLeaves.add(n);
          gl.glLoadName(i);
          n.displayOctant(gl);
        }
      }

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

      // Returning to normal rendering mode
      int nbRecords = gl.glRenderMode(GL2.GL_RENDER);
      if (vizController.getVizModel().isCulling()) {
        gl.glEnable(GL2.GL_CULL_FACE);
        gl.glCullFace(GL2.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);
      }
    }
  }