Пример #1
0
 public void setMatrices(GL10 gl) {
   gl.glMatrixMode(GL10.GL_PROJECTION);
   gl.glLoadIdentity();
   GLU.gluPerspective(gl, fieldOfView, aspectRatio, near, far);
   gl.glMatrixMode(GL10.GL_MODELVIEW);
   gl.glLoadIdentity();
   GLU.gluLookAt(
       gl, position.x, position.y, position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);
 }
Пример #2
0
  /** Some initialization of the OpenGL stuff (that I don't understand...) */
  protected void init() {
    // Much of this code is from GLSurfaceView in the Google API Demos.
    // I encourage those interested to look there for documentation.
    egl = (EGL10) EGLContext.getEGL();
    dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] version = new int[2];
    egl.eglInitialize(dpy, version);

    int[] configSpec = {
      EGL10.EGL_RED_SIZE, 5,
      EGL10.EGL_GREEN_SIZE, 6,
      EGL10.EGL_BLUE_SIZE, 5,
      EGL10.EGL_DEPTH_SIZE, 8,
      EGL10.EGL_NONE
    };

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
    EGLConfig config = configs[0];

    eglContext = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);

    surface = egl.eglCreateWindowSurface(dpy, config, sHolder, null);
    egl.eglMakeCurrent(dpy, surface, surface, eglContext);

    gl = (GL10) eglContext.getGL();

    // Load the buffer and stuff
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearDepthf(1.0f);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    // Resize... whatever?
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, width, height);
    GLU.gluPerspective(gl, 45.0f, ((float) width) / height, 1f, 100f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 5.5f, 0, 0, 0, 0, 1, 0);
    gl.glNormal3f(0, 0, 1);
  }
Пример #3
0
  public void setSize(int width, int height) {
    Utils.assertTrue(width >= 0 && height >= 0);

    if (mTargetTexture == null) {
      mScreenWidth = width;
      mScreenHeight = height;
    }
    mAlpha = 1.0f;

    GL11 gl = mGL;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL11.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluOrtho2D(gl, 0, width, 0, height);

    gl.glMatrixMode(GL11.GL_MODELVIEW);
    gl.glLoadIdentity();

    float matrix[] = mMatrixValues;
    Matrix.setIdentityM(matrix, 0);
    // to match the graphic coordinate system in android, we flip it vertically.
    if (mTargetTexture == null) {
      Matrix.translateM(matrix, 0, 0, height, 0);
      Matrix.scaleM(matrix, 0, 1, -1, 1);
    }
  }
Пример #4
0
  public void onDrawFrame(GL10 gl) {
    // gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // Reset the Modelview Matrix
    gl.glLoadIdentity();

    if (cameraChanged) {
      // square.drawBackground(gl);

      GLU.gluLookAt(
          gl,
          camera.getEyeX(),
          camera.getEyeY(),
          camera.getEyeZ(),
          camera.getCenterX(),
          camera.getCenterY(),
          camera.getCenterZ(),
          camera.getUpX(),
          camera.getUpY(),
          camera.getUpZ());

      // cameraChanged = false;
    }

    square.draw(gl);
  }
Пример #5
0
    // @Override
    public void onDrawFrame(GL10 gl) {
      // 采用平滑着色
      gl.glShadeModel(GL10.GL_SMOOTH);
      // 设置为打开背面剪裁
      gl.glEnable(GL10.GL_CULL_FACE);
      // 清除颜色缓存于深度缓存
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      // 设置当前矩阵为模式矩阵
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      // 设置当前矩阵为单位矩阵
      gl.glLoadIdentity();

      // 设置camera位置
      GLU.gluLookAt(
          gl, cx, // 人眼位置的X
          cy, // 人眼位置的Y
          cz, // 人眼位置的Z
          tx, // 人眼球看的点X
          ty, // 人眼球看的点Y
          tz, // 人眼球看的点Z
          0, 1, 0);

      gl.glPushMatrix();
      gl.glTranslatef(0, -0.1f, 0);
      floor.drawSelf(gl);
      gl.glPopMatrix();

      gl.glPushMatrix();
      for (BallController_2 bfcc : albfc) {
        bfcc.drawSelf(gl);
      }
      gl.glPopMatrix();
    }
Пример #6
0
  @Override
  public void getRay(float x, float y, float z, float[] ray) {

    /*
     *
     * normalised_x = 2 * mouse_x / win_width - 1 normalised_y = 1 - 2 *
     * mouse_y / win_height // note the y pos is inverted, so +y is at the
     * top of the screen
     *
     * unviewMat = (projectionMat * modelViewMat).inverse()
     *
     * near_point = unviewMat * Vec(normalised_x, normalised_y, 0, 1)
     * camera_pos = ray_origin = modelViewMat.inverse().col(4) ray_dir =
     * near_point - camera_pos
     */

    // GLU.gluUnProject(winX, winY, winZ, model, modelOffset, project,
    // projectOffset, view, viewOffset, obj, objOffset)

    GLU.gluUnProject(x, viewport[3] - y, z, modelview, 0, projection, 0, viewport, 0, ray, 0);

    // fix
    if (ray[3] != 0) {
      ray[0] = ray[0] / ray[3];
      ray[1] = ray[1] / ray[3];
      ray[2] = ray[2] / ray[3];
    }

    ray[0] = ray[0] - xEye;
    ray[1] = ray[1] - yEye;
    ray[2] = ray[2] - zEye;

    // 0f jako 4 ta?
  }
Пример #7
0
  public void update(GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    // dopisane
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    // gl.glLoadIdentity();

    // koniec
    if (hasChanged) {
      GLU.gluLookAt(gl, xEye, yEye, zEye, xLook, yLook, zLook, xUp, yUp, zUp);
      hasChanged = false;
    }
    // GL11 gl11 = (GL11) gl;
    // gl11.glGetFloatv(GL10.GL_MODELVIEW, modelview, 0); // wystarczyło
    // dopisać 0 i już
    // traktuje jako
    // float
    // gl11.glGetFloatv(GL10.GL_PROJECTION, projection, 0);

    // NIEPOTRZEBNE BO DZIAła i bez tego
    /*
     * gl.glLoadIdentity(); gl.glFrustumf(-aspect, aspect, -1f, 1f, near,
     * far); gl.glRotatef(xAngle * 10, 1f, 0, 0); gl.glRotatef(yAngle * 10,
     * 0, 1f, 0); gl.glRotatef(zAngle, 0f, 0f, 1f); gl.glTranslatef(xPos,
     * yPos, zPos);
     */

  }
Пример #8
0
  public float snap_cam_z_hud(float eye[], float center[], float up[]) {

    float lookAt[] = new float[16];
    float eye2[] = new float[3];
    for (int a = 0; a < 3; a++) {
      eye2[a] = eye[a];
    }

    for (float ez = 1; ez < 100; ez += 0.05) {
      float cordx = mCanvasW;
      float cordy = 0;

      eye2[2] = ez;
      float win[] = new float[3];
      GMath.lookAtf(lookAt, eye2, center, up);
      if (GLU.gluProject(cordx, cordy, 0.0f, lookAt, 0, mProjectionHud, 0, mViewport, 0, win, 0)
              == GL10.GL_TRUE
          && win[0] > 0
          && win[0] < mViewport[2]) {
        mCameraEyeHud[0] = 0;
        mCameraEyeHud[1] = 0;
        mCameraEyeHud[2] = ez;
        saveLookAtHud(mCameraEyeHud, mCameraLookAtHud, mUpZHud);

        return ez;
      }
    }
    return 0;
  }
Пример #9
0
  /**
   * Called when the GLSurfaceView changes shape or size.
   *
   * @param gl The GL10 instance that the game is using.
   * @param width The new width of the GLSurfaceView.
   * @param height The new height of the GLSurfaceView.
   */
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {

    // Set GL_MODELVIEW transformation mode
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity(); // reset the matrix to its default state

    // When using GL_MODELVIEW, you must set the view point
    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 1000.0f);
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Пример #10
0
  /**
   * Called when the surface is created, and before the first frame is called to be rendered.
   *
   * @param gl The GL10 instance that the game is using.
   * @param config The EGLConfig that we could use if we wanted.
   */
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {

    // Set the look at point.
    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Set up the GL state.
    PerlinTerrainMenu.setupGLState(gl);
  }
Пример #11
0
 public void CheckGLError(String glOperation) {
   int error;
   while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
     Log.e(
         "class Texture :",
         glOperation + " IN CHECKGLERROR() : glError " + GLU.gluErrorString(error));
     throw new RuntimeException(glOperation + ": glError " + error);
   }
 }
 public void setMatrices(GL10 gl) {
   gl.glMatrixMode(GL10.GL_PROJECTION);
   gl.glLoadIdentity();
   GLU.gluPerspective(gl, fieldOfView, aspectRatio, near, far);
   gl.glMatrixMode(GL10.GL_MODELVIEW);
   gl.glLoadIdentity();
   gl.glRotatef(-pitch, 1, 0, 0);
   gl.glRotatef(-yaw, 0, 1, 0);
   gl.glTranslatef(-position.x, -position.y, -position.z);
 }
Пример #13
0
  protected void resize(GL10 gl, int w, int h) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, w, h); // 重置当前的视图窗口,前两个参数指定了视见区域的左下角在窗口中的位置
    //		(一般情况下为(0,0)),后两个参数指定了视图窗口的宽度和高度

    GLU.gluPerspective(gl, 45.0f, ((float) w) / h, 1f, 100f); // 设置透视投影的大小;第一个参数是视野的角度,
    //		其值为0.0~180.0,第二个参数是宽高比,后面两个分别是场景中所能绘制深度的起点和终点

  }
Пример #14
0
  public void onSurfaceChanged(GL10 gl, int width, int height) {

    // ...

    // Define the view frustum
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    float ratio = (float) width / height;
    GLU.gluPerspective(gl, 45.0f, ratio, 1, 100f);
  }
Пример #15
0
 @Override
 public void onSurfaceChanged(GL10 gl, int width, int height) {
   if (height == 0) height = 1;
   float aspect = (float) width / height;
   gl.glViewport(0, 0, width, height);
   gl.glMatrixMode(GL10.GL_PROJECTION);
   gl.glLoadIdentity();
   GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.0f);
   gl.glMatrixMode(GL10.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Пример #16
0
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    // Define the Viewport
    gl.glViewport(0, 0, width, height);
    // Select the projection matrix
    gl.glMatrixMode(GL10.GL_PROJECTION);
    // Reset the projection matrix
    gl.glLoadIdentity();
    // Calculate the aspect ratio of the window
    GLU.gluPerspective(gl, 60.0f, (float) width / (float) height, 0.1f, 100.0f);

    // Select the modelview matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
  }
Пример #17
0
    public void onDrawFrame(GL10 gl) {
      checkGLError(gl);
      if (mContextSupportsCubeMap) {
        gl.glClearColor(0, 0, 1, 0);
      } else {
        // Current context doesn't support cube maps.
        // Indicate this by drawing a red background.
        gl.glClearColor(1, 0, 0, 0);
      }
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      gl.glEnable(GL10.GL_DEPTH_TEST);
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
      gl.glRotatef(mAngle, 0, 1, 0);
      gl.glRotatef(mAngle * 0.25f, 1, 0, 0);

      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

      checkGLError(gl);

      if (mContextSupportsCubeMap) {
        gl.glActiveTexture(GL10.GL_TEXTURE0);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP);
        checkGLError(gl);
        gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, mCubeMapTextureID);
        checkGLError(gl);
        GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
        gl11ep.glTexGeni(
            GL11ExtensionPack.GL_TEXTURE_GEN_STR,
            GL11ExtensionPack.GL_TEXTURE_GEN_MODE,
            GL11ExtensionPack.GL_REFLECTION_MAP);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
        checkGLError(gl);
        gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL);
      }

      checkGLError(gl);
      mGrid.draw(gl);

      if (mContextSupportsCubeMap) {
        gl.glDisable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
      }
      checkGLError(gl);

      mAngle += 1.2f;
    }
Пример #18
0
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) {
      height = 1;
    }

    gl.glViewport(0, 0, width, height); // Reset The Current Viewport
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix

    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity();
  }
  @Override
  protected void onDraw(Canvas canvas) {
    GL11 gl = (GL11) context.getGL();
    int w = getWidth();
    int h = getHeight();

    context.waitNative(canvas, this);

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, w, h);
    GLU.gluPerspective(gl, 45.0f, ((float) w) / h, 1f, 100f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 5, 0, 0, 0, 0, 1, 0);
    gl.glTranslatef(0, 0, -10);
    gl.glRotatef(30.0f, 1, 0, 0);
    // gl.glRotatef(40.0f, 0, 1, 0);

    gl.glVertexPointer(3, GL10.GL_FIXED, 0, vertices[frame_ix]);
    gl.glNormalPointer(GL10.GL_FIXED, 0, normals);
    gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // gl.glColor4f(1,0,0,1);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
    // gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glDrawElements(GL10.GL_TRIANGLES, verts, GL10.GL_UNSIGNED_SHORT, indices);

    frame_ix = (frame_ix + 1) % m.getFrameCount();
    context.waitGL();
  }
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    mWidth = width;
    mHeight = height;

    gl.glViewport(0, 0, width, height); // Reset The Current Viewport

    gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity();
  }
Пример #21
0
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    mViewportWidth = width;
    mViewportHeight = height;

    float ratio = (float) width / height;
    mViewRect.top = 1.0f;
    mViewRect.bottom = -1.0f;
    mViewRect.left = -ratio;
    mViewRect.right = ratio;
    updatePageRects();

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    if (USE_PERSPECTIVE_PROJECTION) {
      GLU.gluPerspective(gl, 20f, (float) width / height, .1f, 100f);
    } else {
      GLU.gluOrtho2D(gl, mViewRect.left, mViewRect.right, mViewRect.bottom, mViewRect.top);
    }

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Пример #22
0
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) {
      height = 1;
    }

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

    //		GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
    GLU.gluOrtho2D(gl, 0, (float) width, -(float) height, 0);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Пример #23
0
  // This is a GLSurfaceView.Renderer callback
  public void onSurfaceChanged(GL10 gl1, int width, int height) {
    Log.v(TAG, "onSurfaceChanged: " + width + "x" + height + ", gl10: " + gl1.toString());
    GL11 gl = (GL11) gl1;
    mGL = gl;
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL11.GL_PROJECTION);
    gl.glLoadIdentity();

    GLU.gluOrtho2D(gl, 0, width, 0, height);
    Matrix matrix = mTransformation.getMatrix();
    matrix.reset();
    matrix.preTranslate(0, getHeight());
    matrix.preScale(1, -1);
  }
Пример #24
0
  /** If the surface changes, reset the view */
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) { // Prevent A Divide By Zero By
      height = 1; // Making Height Equal One
    }

    gl.glViewport(0, 0, width, height); // Reset The Current Viewport
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 500.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity(); // Reset The Modelview Matrix
  }
Пример #25
0
  // Call back after onSurfaceCreated() or whenever the window's size changes
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) height = 1; // To prevent divide by zero
    float aspect = (float) width / height;

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

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select projection matrix
    gl.glLoadIdentity(); // Reset projection matrix
    // Use perspective projection
    GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.f);

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select model-view matrix
    gl.glLoadIdentity(); // Reset
  }
Пример #26
0
  /**
   * Handle changes such as orientation changes. This also happens when the surface is created. <br>
   * <br>
   * This method will set the background color, set the viewport, remove perspective.
   */
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) { // Prevent A Divide By Zero By
      height = 1; // Making Height Equal One
    }

    camwidth = width;
    camheight = height;

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix
    GLU.gluOrtho2D(gl, 0, width, 0, height); // Use orthogonic view. No perspective.

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity();
  }
Пример #27
0
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {

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

    float fovy = 50.0f; // Field of view angle, in degrees, in the Y direction.
    float aspect = (float) width / (float) height;
    float zNear = 0.1f;
    float zFar = 100.0f;
    // Set up a perspective projection matrix
    GLU.gluPerspective(gl, fovy, aspect, zNear, zFar);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Пример #28
0
 @Override
 public void onSurfaceChanged(GL10 gl, int width, int height) {
   Log.d("changed", "surface changed for " + width + "X" + height);
   if (true) return;
   // Sets the current view port to the new size.
   gl.glViewport(0, 0, width, height); // OpenGL docs.
   // Select the projection matrix
   // gl.glMatrixMode(GLES20.GL_PROJECTION);// OpenGL docs.
   // Reset the projection matrix
   gl.glLoadIdentity(); // OpenGL docs.
   // Calculate the aspect ratio of the window
   GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f);
   // Select the modelview matrix
   // gl.glMatrixMode(GLES20.GL_MODELVIEW);// OpenGL docs.
   // Reset the modelview matrix
   gl.glLoadIdentity(); // OpenGL docs.
 }
Пример #29
0
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);

    // Set our projection matrix. This doesn't have to be done each time we draw, but usually a new
    // projection needs to be set when the viewport is resized.

    mScreenAspectRatio = (float) width / height;

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, mFovY_deg, mScreenAspectRatio, mZnear, mZfar);

    // setPerspective(gl, mFovY_deg, mScreenAspectRatio, mZnear, mZfar);

    setCurrentProjection(gl);
    setViewport(gl);
  }
Пример #30
0
  protected void drawSetup() {
    // View frustrum

    if (_scene.camera().frustum.isDirty()) {
      updateViewFrustrum();
    }

    // Camera

    _gl.glMatrixMode(GL10.GL_MODELVIEW);
    _gl.glLoadIdentity();

    GLU.gluLookAt(
        _gl,
        _scene.camera().position.x,
        _scene.camera().position.y,
        _scene.camera().position.z,
        _scene.camera().target.x,
        _scene.camera().target.y,
        _scene.camera().target.z,
        _scene.camera().upAxis.x,
        _scene.camera().upAxis.y,
        _scene.camera().upAxis.z);

    // Background color

    if (_scene.backgroundColor().isDirty()) {
      if (_scene.backgroundTransparent() == true) _gl.glClearColor(0, 0, 0, 0);
      else
        _gl.glClearColor(
            (float) _scene.backgroundColor().r() / 255f,
            (float) _scene.backgroundColor().g() / 255f,
            (float) _scene.backgroundColor().b() / 255f,
            (float) _scene.backgroundColor().a() / 255f);
      _scene.backgroundColor().clearDirtyFlag();
    }

    _gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    drawSetupLights();

    // Always on:
    _gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  }