コード例 #1
0
ファイル: PMVMatrix.java プロジェクト: hanjoyo/jogl
 public final void gluPerspective(
     final float fovy, final float aspect, final float zNear, final float zFar) {
   float top = (float) Math.tan(fovy * ((float) Math.PI) / 360.0f) * zNear;
   float bottom = -1.0f * top;
   float left = aspect * bottom;
   float right = aspect * top;
   glFrustumf(left, right, bottom, top, zNear, zFar);
 }
コード例 #2
0
ファイル: SimpleExample.java プロジェクト: keekun/homework
  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);
  }
コード例 #3
0
ファイル: RedSquareES2.java プロジェクト: Karlqu/jogl
  void reshapeImpl(
      final GL2ES2 gl,
      final int tileX,
      final int tileY,
      final int tileWidth,
      final int tileHeight,
      final int imageWidth,
      final int imageHeight) {
    System.err.println(
        Thread.currentThread()
            + " RedSquareES2.reshape "
            + tileX
            + "/"
            + tileY
            + " "
            + tileWidth
            + "x"
            + tileHeight
            + " of "
            + imageWidth
            + "x"
            + imageHeight
            + ", swapInterval "
            + swapInterval
            + ", drawable 0x"
            + Long.toHexString(gl.getContext().getGLDrawable().getHandle())
            + ", tileRendererInUse "
            + tileRendererInUse);
    // Thread.dumpStack();
    if (!gl.hasGLSL()) {
      return;
    }

    st.useProgram(gl, true);
    // Set location in front of camera
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();

    // compute projection parameters 'normal' perspective
    final float fovy = 45f;
    final float aspect2 = ((float) imageWidth / (float) imageHeight) / aspect;
    final float zNear = 1f;
    final float zFar = 100f;

    // compute projection parameters 'normal' frustum
    final float top = (float) Math.tan(fovy * ((float) Math.PI) / 360.0f) * zNear;
    final float bottom = -1.0f * top;
    final float left = aspect2 * bottom;
    final float right = aspect2 * top;
    final float w = right - left;
    final float h = top - bottom;

    // compute projection parameters 'tiled'
    final float l = left + tileX * w / imageWidth;
    final float r = l + tileWidth * w / imageWidth;
    final float b = bottom + tileY * h / imageHeight;
    final float t = b + tileHeight * h / imageHeight;

    pmvMatrix.glFrustumf(l, r, b, t, zNear, zFar);
    // pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
    st.uniform(gl, pmvMatrixUniform);
    st.useProgram(gl, false);

    System.err.println(Thread.currentThread() + " RedSquareES2.reshape FIN");
  }