Example #1
0
  /*
   * accFrustum() The first 6 arguments are identical to the glFrustum() call.
   * pixdx and pixdy are anti-alias jitter in pixels. Set both equal to 0.0
   * for no anti-alias jitter. eyedx and eyedy are depth-of field jitter in
   * pixels. Set both equal to 0.0 for no depth of field effects. focus is
   * distance from eye to plane in focus. focus must be greater than, but not
   * equal to 0.0. Note that accFrustum() calls glTranslatef(). You will
   * probably want to insure that your ModelView matrix has been initialized
   * to identity before calling accFrustum().
   */
  private void accFrustum(
      GL2 gl,
      double left,
      double right,
      double bottom,
      double top,
      double near,
      double far,
      double pixdx,
      double pixdy,
      double eyedx,
      double eyedy,
      double focus) {
    double xwsize, ywsize;
    double dx, dy;
    int viewport[] = new int[4];

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

    xwsize = right - left;
    ywsize = top - bottom;

    dx = -(pixdx * xwsize / (double) viewport[2] + eyedx * near / focus);
    dy = -(pixdy * ywsize / (double) viewport[3] + eyedy * near / focus);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(left + dx, right + dx, bottom + dy, top + dy, near, far);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef((float) -eyedx, (float) -eyedy, 0.0f);
  }
Example #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);
    }
  }
Example #3
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);
  }
  @Override
  public void reshape(GLAutoDrawable drawable, int arg1, int arg2, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    // Computing the aspect ratio
    float aspect = (float) width / height;

    // Setting the viewport, the area that is displayed, to cover the whole window
    gl.glViewport(0, 0, width, height);

    // Setting the perspective projection with an aspect that matches that of the viewport
    // Choose Projection Matrix
    gl.glMatrixMode(GL_PROJECTION);

    // Resets the Projection Matrix
    gl.glLoadIdentity();

    // gluPerspective(fovy, aspect, zNear, zFar);
    // Instructions taken from http://www.opengl.org/sdk/docs/man2/xhtml/glTranslate.xml
    // fovy : Specifies the field of view angle, in degrees, in the y direction.
    // aspect : Specifies the aspect ratio that determines the field of view in the x direction. The
    // aspect ratio is the ratio of x (width) to y (height).
    // zNear : Specifies the distance from the viewer to the near clipping plane (always positive).
    // zFar : Specifies the distance from the viewer to the far clipping plane (always positive).
    glu.gluPerspective(45.0, aspect, 0.1, 100.0);
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity();
  }
 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   GL2 gl = drawable.getGL().getGL2();
   gl.glMatrixMode(GL2ES1.GL_PROJECTION);
   gl.glLoadIdentity();
   glu.gluOrtho2D(0, 1, 0, 1);
   gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Example #6
0
 @Override
 public void reshape(GLAutoDrawable dr, int x, int y, int width, int height) {
   GL2 gl = dr.getGL().getGL2();
   gl.glViewport(x, y, width, height);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   glu.gluPerspective(45.0f, (float) width / (float) height, 1.0, 100.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Example #7
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();
   glu.gluPerspective(60.0, (float) w / (float) h, 1.0, 20.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Example #8
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();
    glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Example #9
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();
 }
Example #10
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);
 }
Example #11
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();

    glu.gluPerspective(45.0, 1.0, 0.25, 25.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);
  }
Example #12
0
 @Override
 public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
   GL2 gl = gLDrawable.getGL().getGL2();
   final float aspect = (float) width / (float) height;
   gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
   gl.glLoadIdentity();
   final float fh = 0.5f;
   final float fw = fh * aspect;
   gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
   gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Example #13
0
  public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    height = (height == 0) ? 1 : height;

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45, (float) width / height, 1, 1000);
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Example #14
0
	public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width,
			int height) {
		GL2 gl = gLDrawable.getGL().getGL2();
		if (height <= 0) {
			height = 1;
		}
		float h = (float) width / (float) height;
		gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
		gl.glLoadIdentity();
		glu.gluPerspective(50.0f, h, 1.0, 1000.0);
		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
		gl.glLoadIdentity();
	}
Example #15
0
 public void configureGL(GL2 gl) {
   gl.glEnable(GL2.GL_FOG);
   gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_LINEAR);
   gl.glFogf(GL2.GL_FOG_DENSITY, 0.25f);
   gl.glFogf(GL2.GL_FOG_START, Math.max(getNearClippingPlane(), fadeOut * 1.0f));
   gl.glFogf(GL2.GL_FOG_END, Math.max(1.1f, fadeOut * 1.1f * getSpawnDistance()));
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   gl.glFrustumf(-1, 1, -man.vheight(), man.vheight(), getNearClippingPlane(), 128.0f);
   gl.glScalef(2.0f, 2.0f, 1);
   gl.glTranslatef(-0.5f, -man.vheight() / 2.0f, 0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Example #16
0
  public void drawTextureToOffScreenTexture(int texId, int attachment)
        // public void drawTextureToOffScreenTextureUsingShader(Texture tex, int attachment, Program
        // program)
      {
    GL2 gl = getGL();

    // program.bind(gl);

    gl.glBindTexture(GL_TEXTURE_2D, texId);
    // gl.glBindTexture(GL_TEXTURE_2D, tex.getTextureObject());
    // gl.glDrawBuffer(attachment);
    gl.glBindFramebuffer(GL_FRAMEBUFFER, attachment); // think this is the new way...

    gl.glEnable(GL_TEXTURE_2D);
    // gl.glActiveTexture(GL_TEXTURE0);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glViewport(0, 0, fboWidth, fboHeight);

    // gl.glUniform1i(program.uniform("theTexture"), 0);
    // set projection to ortho
    gl.glMatrixMode(GL_PROJECTION);
    gl.glTranslatef(1f, 1f, 1f);

    gl.glPushMatrix();
    {
      gl.glLoadIdentity();
      RenderUtils.getGLU().gluOrtho2D(0, fboWidth, fboHeight, 0);

      gl.glMatrixMode(gl.GL_MODELVIEW);

      gl.glPushMatrix();
      {
        gl.glLoadIdentity();

        gl.glColor4f(1f, 1f, 1f, 1f);
        drawSquare(gl, 0, 0, fboWidth, fboHeight);
      }
      gl.glPopMatrix();

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

    gl.glMatrixMode(gl.GL_MODELVIEW);

    gl.glDisable(GL_TEXTURE_2D);
    // program.unbind(gl);
  }
Example #17
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    gl = drawable.getGL().getGL2();
    if (height < 1) {
      height = 1;
    }
    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(FPCamera.FOV, h, FPCamera.NEAR, FPCamera.FAR);

    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
  @Override
  public void endPoly() {
    super.endPoly();

    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glPopMatrix();
  }
  // in pixels.
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    System.out.println(x + " " + y + " " + width + " " + height);

    GL2 gl = drawable.getGL().getGL2();
    // calculate the aspect ratio of window
    double aspect = 1.0 * width / height;

    // in OpenGL terms, we are changing the 'projection'
    // this will be explained later
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    // Use the GLU library to compute the new projection
    GLU glu = new GLU();

    // We are wider than high!
    if (aspect >= 1) {
      System.out.println("Showing world " + (-aspect) + " to " + (aspect) + " -1 to 1");
      glu.gluOrtho2D(-aspect, aspect, -1.0, 1.0); // left, right, top, bottom
    } else {
      System.out.println("Showing world from -1 to 1 " + (-1.0 / aspect) + " to " + (1.0 / aspect));
      glu.gluOrtho2D(-1, 1, -1.0 / aspect, 1.0 / aspect); // left, right, top, bottom
    }
  }
Example #20
0
  /**
   * Call-back handler for window re-size event. Also called when the drawable is first set to
   * visible.
   */
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    graphicsManager.setGraphics(gl);

    // Set the view port (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
    gl.glLoadIdentity(); // reset projection matrix
    glu.gluOrtho2D(0, realWidth, 0, realHeight);

    // Enable the model-view transform
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity(); // reset
  }
Example #21
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);
  }
  /**
   * Draw the object and all of its descendants recursively.
   *
   * <p>TODO: Complete this method
   *
   * @param gl
   */
  public void draw(GL2 gl) {

    // don't draw if it is not showing
    if (!amShowing) {
      return;
    }

    // TODO: draw the object and all its children recursively
    // setting the model transform appropriately

    // Call drawSelf() to draw the object itself
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    {
      gl.glPushMatrix();
      {
        gl.glTranslated(myTranslation[0], myTranslation[1], 0);
        gl.glScaled(myScale, myScale, 1);
        gl.glRotated(myRotation, 0, 0, 1);
        drawSelf(gl);
        for (GameObject child : myChildren) {
          child.draw(gl);
        }
      }
      gl.glPopMatrix();
    }
  }
 @Override
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   gl.glFrustum(-1, 1, -1, 1, 1, 10);
 }
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    GL2 gl = drawable.getGL().getGL2();
    GLU glu = new GLU();

    // avoid a divide by zero error!
    if (height <= 0) height = 1;

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0f, h, 1.0, 20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Example #25
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();
  }
Example #26
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();
  }
 @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
 }
Example #28
0
  /**
   * Call-back handler for window re-size event. Also called when the drawable is first set to
   * visible.
   */
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context

    if (height == 0) height = 1; // prevent divide by zero
    float aspect = (float) width / height;

    // Set the view port (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
    gl.glLoadIdentity(); // reset projection matrix
    glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar

    // Enable the model-view transform
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity(); // reset
  }
  @Override
  public void beginPoly(int windingRule) {
    /*
     * pen hangs down and to the right. See java.awt.Graphics
     */
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glTranslatef(0.5f, 0.5f, 0);

    super.beginPoly(windingRule);
  }
Example #30
0
  @Override
  public void init(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    glu = new GLU();
    glut = new GLUT();

    gl.glClearColor(0.549f, 0.675f, 0.227f, 0.0f);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(left, right, bottom, top);
    gl.glViewport((int) bottom, (int) left, (int) top, (int) right);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glColor3f(.357f, .184f, .478f);

    maxFrames = 50 * ifsFiles.size() + 1000;
    base = gl.glGenLists(maxFrames);
    currentDrawList = base;

    ifsfile = "CS371/assignments/assignment02/tri.ifs";
    loadifs();
  }