예제 #1
0
    public GLState(GL11 gl) {
      mGL = gl;

      // Disable unused state
      gl.glDisable(GL11.GL_LIGHTING);

      // Enable used features
      gl.glEnable(GL11.GL_DITHER);

      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
      gl.glEnable(GL11.GL_TEXTURE_2D);

      gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);

      // Set the background color
      gl.glClearColor(0f, 0f, 0f, 0f);
      gl.glClearStencil(0);

      gl.glEnable(GL11.GL_BLEND);
      gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);

      // We use 565 or 8888 format, so set the alignment to 2 bytes/pixel.
      gl.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 2);
    }
예제 #2
0
  public void bind() {
    GL11 gl = (GL11) glGraphics.getGL();

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, vboHandle);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, vertexSize, 0);

    if (hasColor) {
      gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
      gl.glColorPointer(4, GL10.GL_FLOAT, vertexSize, 3 * 4);
    }

    if (hasTexCoords) {
      gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
      gl.glTexCoordPointer(2, GL10.GL_FLOAT, vertexSize, (hasColor ? 7 : 3) * 4);
    }

    if (hasNormals) {
      gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
      int offset = 3;
      if (hasColor) offset += 4;
      if (hasTexCoords) offset += 2;
      gl.glNormalPointer(GL10.GL_FLOAT, vertexSize, offset * 4);
    }
  }
예제 #3
0
  // This is a GLSurfaceView.Renderer callback
  public void onSurfaceCreated(GL10 gl1, EGLConfig config) {
    GL11 gl = (GL11) gl1;
    if (mGL != null) {
      // The GL Object has changed
      Log.i(TAG, "GLObject has changed from " + mGL + " to " + gl);
    }
    mGL = gl;

    if (!ENABLE_FPS_TEST) {
      setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    } else {
      setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }

    // Disable unused state
    gl.glDisable(GL11.GL_LIGHTING);

    // Enable used features
    gl.glEnable(GL11.GL_BLEND);
    gl.glEnable(GL11.GL_SCISSOR_TEST);
    gl.glEnable(GL11.GL_STENCIL_TEST);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL11.GL_TEXTURE_2D);
    mTexture2DEnabled = true;

    gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);

    // Set the background color
    gl.glClearColor(0f, 0f, 0f, 0f);
    gl.glClearStencil(0);

    gl.glVertexPointer(2, GL11.GL_FLOAT, 0, mXyPointer);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, mUvPointer);
  }
예제 #4
0
  private void initialize() {
    GL11 gl = mGL;

    // First create an nio buffer, then create a VBO from it.
    int size = BOX_COORDINATES.length * Float.SIZE / Byte.SIZE;
    FloatBuffer xyBuffer = allocateDirectNativeOrderBuffer(size).asFloatBuffer();
    xyBuffer.put(BOX_COORDINATES, 0, BOX_COORDINATES.length).position(0);

    int[] name = new int[1];
    GLId.glGenBuffers(1, name, 0);
    mBoxCoords = name[0];

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    gl.glBufferData(
        GL11.GL_ARRAY_BUFFER,
        xyBuffer.capacity() * (Float.SIZE / Byte.SIZE),
        xyBuffer,
        GL11.GL_STATIC_DRAW);

    gl.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    // Enable the texture coordinate array for Texture 1
    gl.glClientActiveTexture(GL11.GL_TEXTURE1);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
    gl.glClientActiveTexture(GL11.GL_TEXTURE0);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // mMatrixValues and mAlpha will be initialized in setSize()
  }
  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();
  }