Ejemplo n.º 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);
 }
 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);
 }
Ejemplo n.º 3
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,第二个参数是宽高比,后面两个分别是场景中所能绘制深度的起点和终点

  }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
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);
  }
Ejemplo n.º 6
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);
  }
Ejemplo n.º 7
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);
  }
Ejemplo n.º 8
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();
  }
Ejemplo n.º 9
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
  }
Ejemplo n.º 10
0
  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();
  }
Ejemplo n.º 11
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
  }
Ejemplo n.º 12
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();
  }
Ejemplo n.º 13
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.
 }
Ejemplo n.º 14
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();
  }
Ejemplo n.º 15
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);
  }
Ejemplo n.º 16
0
    public void initGL() {
      int width = sv.getWidth();
      int height = sv.getHeight();
      mGL.glViewport(0, 0, width, height);
      mGL.glMatrixMode(GL10.GL_PROJECTION);
      mGL.glLoadIdentity();
      float aspect = (float) width / height;
      GLU.gluPerspective(mGL, 45.0f, aspect, 1.0f, 30.0f);
      mGL.glClearColor(0.5f, 0.5f, 0.5f, 1);
      mGL.glClearDepthf(1.0f);

      // light
      mGL.glEnable(GL10.GL_LIGHTING);

      // the first light
      mGL.glEnable(GL10.GL_LIGHT0);

      // ambient values
      mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] {0.1f, 0.1f, 0.1f, 1f}, 0);

      // light that reflects in all directions
      mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] {1f, 1f, 1f, 1f}, 0);

      // place it in projection space
      mGL.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] {10f, 0f, 10f, 1}, 0);

      // allow our object colors to create the diffuse/ambient material setting
      mGL.glEnable(GL10.GL_COLOR_MATERIAL);

      // some rendering options
      mGL.glShadeModel(GL10.GL_SMOOTH);

      mGL.glEnable(GL10.GL_DEPTH_TEST);
      // mGL.glDepthFunc(GL10.GL_LEQUAL);
      mGL.glEnable(GL10.GL_CULL_FACE);

      mGL.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

      // the only way to draw primitives with OpenGL ES
      mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY);

      Log.i("GL", "GL initialized");
    }
  @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();
  }
Ejemplo n.º 18
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();
  }
 @Override
 public void onSurfaceChanged(GL10 gl, int width, int 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.
    */
   gl.glViewport(0, 0, width, height);
   // 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
   // Select projection matrix.
   gl.glMatrixMode(GL10.GL_PROJECTION);
   // Reset projection matrix.
   gl.glLoadIdentity();
   // Use perspective projection.
   GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.f);
   // Select model-view matrix.
   gl.glMatrixMode(GL10.GL_MODELVIEW);
   // Reset.
   gl.glLoadIdentity();
 }
    @Override
    public void onDrawFrame(GL10 gl) {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      GL11 gl11 = (GL11) gl;

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

      // perspective
      GLU.gluPerspective(gl11, 45, aspect, 0.01f, 100f);
      GLU.gluLookAt(
          gl,
          (float) (Math.cos(angle) * eyeDistance),
          0,
          (float) (Math.sin(angle) * eyeDistance),
          0,
          0,
          0.0f,
          0.0f,
          1.0f,
          0.0f);

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

      // set render status
      gl.glEnable(GL10.GL_TEXTURE_2D);
      gl.glEnable(GL10.GL_ALPHA_TEST);
      gl.glAlphaFunc(GL10.GL_EQUAL, 1.0f);
      // gl.glColor4f(1, 1, 1, 1);

      // bind
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture);
      vbo.bind(gl11);

      // left
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(-1, 0, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // right
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(1, 0, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // up
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(0, -1, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // down
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(0, 1, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // unbind
      vbo.unbind(gl11);
      gl.glDisable(GL10.GL_TEXTURE_2D);

      angle += (float) (1f / 180f * Math.PI);
    }