示例#1
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);
    }
  }
示例#2
0
 private void setTextureCoords(float left, float top, float right, float bottom) {
   mGL.glMatrixMode(GL11.GL_TEXTURE);
   mTextureMatrixValues[0] = right - left;
   mTextureMatrixValues[5] = bottom - top;
   mTextureMatrixValues[10] = 1;
   mTextureMatrixValues[12] = left;
   mTextureMatrixValues[13] = top;
   mTextureMatrixValues[15] = 1;
   mGL.glLoadMatrixf(mTextureMatrixValues, 0);
   mGL.glMatrixMode(GL11.GL_MODELVIEW);
 }
  public void onDrawFrame(GL10 gl10, boolean fpsTimeElapsed) {
    GL11 gl = (GL11) gl10;

    updateWithDelta(1.0f / MAXIMUM_UPDATE_RATE);

    synchronized (transforms) {
      if (fpsTimeElapsed) {
        onTransform();
      }
    }
    sourcePosition.x = x;
    sourcePosition.y = y;

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

    gl.glEnableClientState(GL11.GL_COLOR_ARRAY);

    // unbind all buffers
    gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
    gl.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, verticesID[0]);

    // Using glBufferSubData means that a copy is done from the quads array to the buffer rather
    // than recreating the buffer which
    // would be an allocation and copy. The copy also only takes over the number of live particles.
    // This provides a nice performance
    // boost.
    quadsBuffer.put(quads);
    quadsBuffer.position(0);

    gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, 0, 128 * particleIndex, quadsBuffer);

    // Configure the vertex pointer which will use the currently bound VBO for its data
    gl.glVertexPointer(2, GL11.GL_FLOAT, 32, 0);
    gl.glColorPointer(4, GL11.GL_FLOAT, 32, (4 * 4));
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 32, (4 * 2));

    if (hasTexture) {
      gl.glEnable(GL11.GL_TEXTURE_2D);
      gl.glBindTexture(GL11.GL_TEXTURE_2D, getTexture().getTextureId());
    }

    gl.glBlendFunc(srcBlendFactor, dstBlendFactor);

    gl.glDrawElements(GL11.GL_TRIANGLES, particleIndex * 6, GL11.GL_UNSIGNED_SHORT, indicesBuffer);

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
    gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);

    gl.glDisableClientState(GL11.GL_COLOR_ARRAY);
  }
  @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();
  }
示例#5
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);
  }
示例#6
0
 private void setTextureCoords(float[] mTextureTransform) {
   mGL.glMatrixMode(GL11.GL_TEXTURE);
   mGL.glLoadMatrixf(mTextureTransform, 0);
   mGL.glMatrixMode(GL11.GL_MODELVIEW);
 }