Exemple #1
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   if (w <= h)
     gl.glOrtho(-2.5, 2.5, -2.5 * (float) h / (float) w, 2.5 * (float) h / (float) w, -10.0, 10.0);
   else
     gl.glOrtho(-2.5 * (float) w / (float) h, 2.5 * (float) w / (float) h, -2.5, 2.5, -10.0, 10.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Exemple #2
0
  /* (non-Javadoc)
   * @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable, int, int, int, int)
   */
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    this.width = width;
    this.height = height;
    //        GL gl = drawable.getGL();
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    double ratio = (double) width / (double) height;
    double w = 2;
    double h = 2;
    if (width < height) {
      h = h / ratio;
    } else {
      w = w * ratio;
    }

    int mode = Options.getProjectionMode();
    if (mode == Options.PERSPECTIVE) {
      // 	For Perspective projection
      glu.gluPerspective(45, (double) (width) / (double) (height), 0.001, 1000);
    } else if (mode == Options.ORTHOGRAPHIC) {
      // For Orthogonal projection
      gl.glOrtho(-1 * w, w, -1 * h, h, -10000, 10000);
    }
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    for (Iterator<GLBrush> it = displayList.iterator(); it.hasNext(); ) {
      GLBrush brush = it.next();
      brush.setScreenSize(width, height);
    }
  }
  /*
   * 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);
  }
 @Override
 public void init(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   gl.glClearColor(0, 0, 0, 0); // dene a cor de fundo
   gl.glEnable(GL2.GL_DEPTH_TEST); // remoção de superfície oculta
   gl.glMatrixMode(GL2.GL_PROJECTION); // dene que a matrix é a de projeção
   gl.glLoadIdentity(); // carrega a matrix de identidade
   gl.glOrtho(-5, 5, -5, 5, -5, 5); // dene uma projeção ortográca
 }
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Exemple #6
0
 public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
   width = arg3;
   height = arg4;
   GL2 gl = arg0.getGL().getGL2();
   gl.glViewport(0, 0, width, height);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Exemple #7
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClearColor(0, 0, 0, 0);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    // new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f);
    gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    tr.beginRendering(800, 800);
    tr.draw("die Marktwirtschaft. Da regelt sich � angeblich", 16, 32);
    tr.draw("Hello World! This text is scrambled", 16, 16);
    tr.endRendering();
  }
Exemple #8
0
  protected void beginDrawIcons(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.oglStackHandler.clear();

    int attributeMask =
        GL2.GL_DEPTH_BUFFER_BIT // for depth test, depth mask and depth func
            | GL2.GL_TRANSFORM_BIT // for modelview and perspective
            | GL2.GL_VIEWPORT_BIT // for depth range
            | GL2.GL_CURRENT_BIT // for current color
            | GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, and blend
            | GL2.GL_DEPTH_BUFFER_BIT // for depth func
            | GL2.GL_ENABLE_BIT; // for enable/disable changes
    this.oglStackHandler.pushAttrib(gl, attributeMask);

    // Apply the depth buffer but don't change it.
    if ((!dc.isDeepPickingEnabled())) gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthMask(false);

    // Suppress any fully transparent image pixels
    gl.glEnable(GL2.GL_ALPHA_TEST);
    gl.glAlphaFunc(GL2.GL_GREATER, 0.001f);

    // Load a parallel projection with dimensions (viewportWidth, viewportHeight)
    this.oglStackHandler.pushProjectionIdentity(gl);
    gl.glOrtho(
        0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);

    this.oglStackHandler.pushModelview(gl);
    this.oglStackHandler.pushTexture(gl);

    if (dc.isPickingMode()) {
      this.pickSupport.beginPicking(dc);

      // Set up to replace the non-transparent texture colors with the single pick color.
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_COMBINE);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_SRC0_RGB, GL2.GL_PREVIOUS);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_COMBINE_RGB, GL2.GL_REPLACE);
    } else {
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
    }
  }
Exemple #9
0
  public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    height = (height == 0) ? 1 : height;
    swidth = width; // Set Scissor Width To Window Width
    sheight = height; // Set Scissor Height To Window Height

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); // Select The Projection
    // Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix
    gl.glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f); // Create Ortho 640x480
    // View (0,0 At Top
    // Left)
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); // Select The Modelview
    // Matrix
    gl.glLoadIdentity();
  }
  protected void beginRendering(DrawContext dc, OGLStackHandler stackHandler) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().fine(message);
      throw new IllegalArgumentException(message);
    }

    GL2 gl = dc.getGL();

    int attribMask =
        GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, blend func
            | GL2.GL_CURRENT_BIT // for current color
            | GL2.GL_ENABLE_BIT // for enable/disable
            | GL2.GL_LINE_BIT // for line width
            | GL2.GL_TRANSFORM_BIT; // for matrix mode
    stackHandler.pushAttrib(gl, attribMask);

    stackHandler.pushTextureIdentity(gl);
    stackHandler.pushProjectionIdentity(gl);
    java.awt.Rectangle viewport = dc.getView().getViewport();
    gl.glOrtho(
        viewport.x, viewport.x + viewport.width, viewport.y, viewport.y + viewport.height, -1, 1);
    stackHandler.pushModelviewIdentity(gl);

    // Enable the alpha test.
    gl.glEnable(GL2.GL_ALPHA_TEST);
    gl.glAlphaFunc(GL2.GL_GREATER, 0.0f);

    // Enable blending in premultiplied color mode.
    gl.glEnable(GL2.GL_BLEND);
    OGLUtil.applyBlending(gl, true);

    gl.glDisable(GL2.GL_CULL_FACE);
    gl.glDisable(GL2.GL_DEPTH_TEST);
    gl.glDisable(GL2.GL_LIGHTING);
    gl.glDisable(GL2.GL_TEXTURE_2D);
  }
Exemple #11
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();
  }