Example #1
0
  public void drawMesh(
      BasicTexture tex, int x, int y, int xyBuffer, int uvBuffer, int indexBuffer, int indexCount) {
    float alpha = mAlpha;
    if (!bindTexture(tex)) return;

    mGLState.setBlendEnabled(mBlendEnabled && (!tex.isOpaque() || alpha < OPAQUE_ALPHA));
    mGLState.setTextureAlpha(alpha);

    // Reset the texture matrix. We will set our own texture coordinates
    // below.
    setTextureCoords(0, 0, 1, 1);

    saveTransform();
    translate(x, y);

    mGL.glLoadMatrixf(mMatrixValues, 0);

    mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, xyBuffer);
    mGL.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);

    mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, uvBuffer);
    mGL.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    mGL.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    mGL.glDrawElements(GL11.GL_TRIANGLE_STRIP, indexCount, GL11.GL_UNSIGNED_BYTE, 0);

    mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    mGL.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
    mGL.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    restoreTransform();
    mCountDrawMesh++;
  }
Example #2
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()
  }
Example #3
0
  public void render(GL10 gl, Texture texture) {
    gl.glEnable(GL10.GL_TEXTURE_2D);
    texture.bind(gl);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    GL11 gl11 = (GL11) gl;
    // draw using hardware buffers
    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexbufferId);
    gl11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);

    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, texturebufferId);
    gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexbufferId);
    gl11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_SHORT, 0);

    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
    gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    //		if (vertexbufferId == 0 || texturebufferId == 0 || indexbufferId == 0 || gl11.glGetError()
    // != 0) {
    //			Log.e("Grid", "VBO Not available: " + gl11.glGetError() + ", " +
    // gl11.glGetString(gl11.glGetError()));
    //		}
  }
Example #4
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);
    }
  }
Example #5
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);
  }
  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);
  }
  public void set(GL10 gl) {
    if (mNumVertices == 0) {
      return;
    }
    mTexCoordBuffer.position(0);

    if (mUseVBO && GLBuffer.canUseVBO()) {
      GL11 gl11 = (GL11) gl;
      mGLBuffer.bind(gl11, mTexCoordBuffer, 4 * mTexCoordBuffer.capacity());
      gl11.glTexCoordPointer(2, GL10.GL_FIXED, 0, 0);
    } else {
      gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, mTexCoordBuffer);
    }
  }
 public synchronized void draw(GL11 gl) {
   super.draw(gl);
   if (fontIndexCount > 0) {
     gl.glBindTexture(GL11.GL_TEXTURE_2D, mFont.id);
     gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, mTextureBuffer);
     gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mVertexBuffer);
     gl.glColorPointer(4, GL11.GL_FIXED, 0, mColorBuffer);
     mIndexBuffer.position(indStart);
     mColorBuffer.position(colorStart);
     mVertexBuffer.position(vertStart);
     mTextureBuffer.position(texStart);
     gl.glDrawElements(GL11.GL_TRIANGLES, fontIndexCount, GL11.GL_UNSIGNED_SHORT, mIndexBuffer);
   }
 }
Example #9
0
  public void beginDrawingStrips(GL10 gl, boolean useTexture) {
    beginDrawing(gl, useTexture);
    if (!mUseHardwareBuffers) {
      gl.glVertexPointer(3, mCoordinateType, 0, mVertexBuffer);

      if (useTexture) {
        gl.glTexCoordPointer(2, mCoordinateType, 0, mTexCoordBuffer);
      }

    } else {
      GL11 gl11 = (GL11) gl;
      // draw using hardware buffers
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex);
      gl11.glVertexPointer(3, mCoordinateType, 0, 0);

      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mTextureCoordBufferIndex);
      gl11.glTexCoordPointer(2, mCoordinateType, 0, 0);

      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferIndex);
    }
  }
  @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();
  }
Example #11
0
 @Override
 public void glTexCoordPointer(int size, int type, int stride, int pointer) {
   gl.glTexCoordPointer(size, type, stride, pointer);
 }
Example #12
0
 public static void texCoordZeroPointer(final GL11 pGL11) {
   pGL11.glTexCoordPointer(2, GL10.GL_FLOAT, 0, 0);
 }
Example #13
-1
  public void draw(GL10 gl, boolean useTexture) {
    if (!mUseHardwareBuffers) {
      gl.glVertexPointer(3, mCoordinateType, 0, mVertexBuffer);

      if (useTexture) {
        gl.glTexCoordPointer(2, mCoordinateType, 0, mTexCoordBuffer);
      }

      gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
    } else {
      GL11 gl11 = (GL11) gl;
      // draw using hardware buffers
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex);
      gl11.glVertexPointer(3, mCoordinateType, 0, 0);

      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mTextureCoordBufferIndex);
      gl11.glTexCoordPointer(2, mCoordinateType, 0, 0);

      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferIndex);
      gl11.glDrawElements(GL11.GL_TRIANGLES, mIndexCount, GL11.GL_UNSIGNED_SHORT, 0);

      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
    }
  }