Java Code Examples for android.opengl.GLES20#glUniform4fv()

The following examples show how to use android.opengl.GLES20#glUniform4fv() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gles2ColoredTriangleList.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
/** Sends the given MVP matrix, vertex data, and color to OpenGL. */
public void bind(float[] mvpMatrix, FloatBuffer vertexBuffer, float[] color) {
    // Pass the MVP matrix to OpenGL.
    GLES20.glUniformMatrix4fv(mMvpMatrixHandle, 1 /* count */, false /* transpose */,
            mvpMatrix, 0 /* offset */);
    if (CHECK_GL_ERRORS) checkGlError("glUniformMatrix4fv");

    // Pass the VBO with the triangle list's vertices to OpenGL.
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    if (CHECK_GL_ERRORS) checkGlError("glEnableVertexAttribArray");
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT,
            false /* normalized */, VERTEX_STRIDE, vertexBuffer);
    if (CHECK_GL_ERRORS) checkGlError("glVertexAttribPointer");

    // Pass the triangle list's color to OpenGL.
    GLES20.glUniform4fv(mColorHandle, 1 /* count */, color, 0 /* offset */);
    if (CHECK_GL_ERRORS) checkGlError("glUniform4fv");
}
 
Example 2
Source File: Triangle.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
public void draw(float[] mvpMatrix) {
    GLES20.glUseProgram(mProgram);
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle,
            COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false,
            vertexStride, vertexBuffer);
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

    GLES20.glUniform4fv(mColorHandle, 1, color, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 3
Source File: GLES20Canvas.java    From android-openGL-canvas with Apache License 2.0 6 votes vote down vote up
private void prepareDraw(int offset, int color, float lineWidth) {
    GLES20.glUseProgram(mDrawProgram);
    checkError();
    if (lineWidth > 0) {
        GLES20.glLineWidth(lineWidth);
        checkError();
    }
    float[] colorArray = getColor(color);
    enableBlending(true);
    GLES20.glBlendColor(colorArray[0], colorArray[1], colorArray[2], colorArray[3]);
    checkError();

    GLES20.glUniform4fv(mDrawParameters[INDEX_COLOR].handle, 1, colorArray, 0);
    setPosition(mDrawParameters, offset);
    checkError();
}
 
Example 4
Source File: GLES20Canvas.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
private void prepareDraw(int offset, int color, float lineWidth) {
    GLES20.glUseProgram(mDrawProgram);
    checkError();
    if (lineWidth > 0) {
        GLES20.glLineWidth(lineWidth);
        checkError();
    }
    float[] colorArray = getColor(color);
    boolean blendingEnabled = (colorArray[3] < 1f);
    enableBlending(blendingEnabled);
    if (blendingEnabled) {
        GLES20.glBlendColor(colorArray[0], colorArray[1], colorArray[2], colorArray[3]);
        checkError();
    }

    GLES20.glUniform4fv(mDrawParameters[INDEX_COLOR].handle, 1, colorArray, 0);
    setPosition(mDrawParameters, offset);
    checkError();
}
 
Example 5
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
private void prepareDraw(int offset, int color, float lineWidth) {
    GLES20.glUseProgram(mDrawProgram);
    checkError();
    if (lineWidth > 0) {
        GLES20.glLineWidth(lineWidth);
        checkError();
    }
    float[] colorArray = getColor(color);
    boolean blendingEnabled = (colorArray[3] < 1f);
    enableBlending(blendingEnabled);
    if (blendingEnabled) {
        GLES20.glBlendColor(colorArray[0], colorArray[1], colorArray[2], colorArray[3]);
        checkError();
    }

    GLES20.glUniform4fv(mDrawParameters[INDEX_COLOR].handle, 1, colorArray, 0);
    setPosition(mDrawParameters, offset);
    checkError();
}
 
Example 6
Source File: GLBubble.java    From Android-AudioRecorder-App with Apache License 2.0 6 votes vote down vote up
/**
 * Draw bubble.
 */
public void draw() {
  GLES20.glUseProgram(getProgram());
  int positionHandle = GLES20.glGetAttribLocation(getProgram(), VERTEX_POSITION);
  GLES20.glEnableVertexAttribArray(positionHandle);
  GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
      COORDS_PER_VERTEX * SIZE_OF_FLOAT, vertexBuffer);
  int colorHandle = GLES20.glGetUniformLocation(getProgram(), VERTEX_COLOR);
  GLES20.glEnable(GLES20.GL_BLEND);
  GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
  GLES20.glUniform4fv(colorHandle, 1, getColor(), 0);
  GLES20.glDrawElements(GLES20.GL_TRIANGLE_FAN, shortBuffer.capacity(), GLES20.GL_UNSIGNED_SHORT,
      shortBuffer);
  GLES20.glDisableVertexAttribArray(positionHandle);
  GLES20.glDisable(GLES20.GL_BLEND);
}
 
Example 7
Source File: GLES20Canvas.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
private void prepareDraw(int offset, int color, float lineWidth) {
    GLES20.glUseProgram(mDrawProgram);
    checkError();
    if (lineWidth > 0) {
        GLES20.glLineWidth(lineWidth);
        checkError();
    }
    float[] colorArray = getColor(color);
    boolean blendingEnabled = (colorArray[3] < 1f);
    enableBlending(blendingEnabled);
    if (blendingEnabled) {
        GLES20.glBlendColor(colorArray[0], colorArray[1], colorArray[2], colorArray[3]);
        checkError();
    }

    GLES20.glUniform4fv(mDrawParameters[INDEX_COLOR].handle, 1, colorArray, 0);
    setPosition(mDrawParameters, offset);
    checkError();
}
 
Example 8
Source File: MyOSD.java    From myMediaCodecPlayer-for-FPV with MIT License 5 votes vote down vote up
public void draw(float[] viewM){
    Matrix.setIdentityM(mHorizonModelM, 0);
    //left_right
    //angle_left_right=0;
    angle_left_right+=0.1;
    if(angle_left_right>=80){angle_left_right=0;}
    //up_down
    //angle_up_down=1.0f;
    angle_up_down+=0.1;
    if(angle_up_down>=80){angle_up_down=1.0f;}
    //rotating vertically (only for Kopter)
    //angle_vertically=0.0f;
    angle_vertically+=0.1f;
    if(angle_vertically>=80){angle_vertically=0;}
    Matrix.rotateM(mHorizonModelM,0,angle_up_down,1.0f,0.0f,0.0f);
    Matrix.rotateM(mHorizonModelM, 0, angle_left_right, 0.0f, 0.0f, 1.0f);
    Matrix.rotateM(mHorizonModelM, 0, angle_vertically, 0.0f, 1.0f, 0.0f);
    Matrix.multiplyMM(mMVPM, 0, viewM, 0, mHorizonModelM, 0);
    Matrix.multiplyMM(mMVPM, 0, mProjM, 0, mMVPM, 0);

    GLES20.glUseProgram(mProgram);
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, OpenGLHelper.COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false,
            OpenGLHelper.vertexStride, vertexBuffer);
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
    GLES20.glUniform4fv(mColorHandle, 1, OpenGLHelper.color, 0);
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPM, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, OpenGLHelper.vertexCount);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mColorHandle);
    GLES20.glDisableVertexAttribArray(mMVPMatrixHandle);
}
 
Example 9
Source File: MakeupProgramLandmarks.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
@Override
public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgramHandle);

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
            mPositionHandle, Drawable2d.COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false,
            Drawable2d.VERTEXTURE_STRIDE, mDrawable2d.vertexArray());

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvp, 0);

    GLES20.glUniform1f(mPointSizeHandle, mPointSize);

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, mDrawable2d.vertexCount());

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 10
Source File: FlatShadedProgram.java    From FuAgoraDemoDroid with MIT License 5 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix       The 4x4 projection matrix.
 * @param color           A 4-element color vector.
 * @param vertexBuffer    Buffer with vertex data.
 * @param firstVertex     Index of first vertex to use in vertexBuffer.
 * @param vertexCount     Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride    Width, in bytes, of the data for each vertex (often vertexCount *
 *                        sizeof(float)).
 */
public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer,
                 int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the color vector in.
    GLES20.glUniform4fv(muColorLoc, 1, color, 0);
    GlUtil.checkGlError("glUniform4fv ");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
            GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glUseProgram(0);
}
 
Example 11
Source File: FlatShadedProgram.java    From AndroidPlayground with MIT License 5 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param color A 4-element color vector.
 * @param vertexBuffer Buffer with vertex data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the data for each vertex (often vertexCount *
 *        sizeof(float)).
 */
public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer,
        int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the color vector in.
    GLES20.glUniform4fv(muColorLoc, 1, color, 0);
    GlUtil.checkGlError("glUniform4fv ");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glUseProgram(0);
}
 
Example 12
Source File: DrawerImpl.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setColor(Object3DData obj) {

        // get handle to fragment shader's vColor member
        int mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
        GLUtil.checkGlError("glGetUniformLocation");

        // Set color for drawing the triangle
        float[] color = obj.getColor() != null ? obj.getColor() : DEFAULT_COLOR;
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);
        GLUtil.checkGlError("glUniform4fv");
    }
 
Example 13
Source File: Square.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * Encapsulates the OpenGL ES instructions for drawing this shape.
 *
 * @param mvpMatrix - The Model View Project matrix in which to draw
 * this shape.
 */
public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
            mPositionHandle, COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false,
            vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    MyGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    MyGLRenderer.checkGlError("glUniformMatrix4fv");

    // Draw the square
    GLES20.glDrawElements(
            GLES20.GL_TRIANGLES, drawOrder.length,
            GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 14
Source File: FlatShadedProgram.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param color A 4-element color vector.
 * @param vertexBuffer Buffer with vertex data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the data for each vertex (often vertexCount *
 *        sizeof(float)).
 */
public void draw(float[] mvpMatrix, float[] color, FloatBuffer vertexBuffer,
        int firstVertex, int vertexCount, int coordsPerVertex, int vertexStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the color vector in.
    GLES20.glUniform4fv(muColorLoc, 1, color, 0);
    GlUtil.checkGlError("glUniform4fv ");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glUseProgram(0);
}
 
Example 15
Source File: ShaderProgram.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
public void setFloatVec4(final int location, final float[] arrayValue) {
    GLES20.glUniform4fv(location, 1, FloatBuffer.wrap(arrayValue));
}
 
Example 16
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void uniform4fv(int location, int count, float[] v, int offset) {
    GLES20.glUniform4fv(location, count, v, offset);
}
 
Example 17
Source File: ShaderTextureAmbiant.java    From smartGL with Apache License 2.0 4 votes vote down vote up
@Override
    public void onPreRender(OpenGLRenderer renderer, RenderObject object, Face3D face) {
        float[] ambiant = renderer.getLightAmbiant();
//        GLES20.glUniform4f(mLightAmbiantId, 1, 0, 0, 0.3f); // r,v,b,a
        GLES20.glUniform4fv(mLightAmbiantId, 1, ambiant, 0);
    }
 
Example 18
Source File: Cube.java    From Eye-blink-detector with MIT License 4 votes vote down vote up
public void draw(float[] mvpMatrix) {
    ByteBuffer bb = ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);
    // Add program to OpenGL ES environment
    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,GLES20.GL_FLOAT,false, vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

    // Disable vertex array
    //GLES20.glDisableVertexAttribArray(mPositionHandle);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");

    // Pass the projection and view transformation to the shader
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0,15);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 19
Source File: GLRenderer.java    From bombsquad-remote-android with Apache License 2.0 4 votes vote down vote up
void draw(float[] mvpMatrix, float r, float g, float b, float a, int tex) {
  // Add program to OpenGL environment
  GLES20.glUseProgram(mProgram);

  // get handle to vertex shader's vPosition member
  int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

  // Enable a handle to the triangle vertices
  GLES20.glEnableVertexAttribArray(mPositionHandle);

  // Prepare the triangle coordinate data
  int vertexStride = COORDS_PER_VERTEX * 4;
  GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
      GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

  // get handle to vertex shader's vPosition member
  int mUVHandle = GLES20.glGetAttribLocation(mProgram, "uv");
  GLRenderer.checkGlError("glGetUniformLocation");

  // Enable a handle to the triangle vertices
  GLES20.glEnableVertexAttribArray(mUVHandle);

  // Prepare the triangle coordinate data
  int uvStride = COORDS_PER_UV * 4;
  GLES20
      .glVertexAttribPointer(mUVHandle, COORDS_PER_UV, GLES20.GL_FLOAT, false,
          uvStride, uvBuffer);

  // get handle to fragment shader's vColor member
  int mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
  GLRenderer.checkGlError("glGetUniformLocation");

  // Set color for drawing the triangle
  float[] color = {r, g, b, a};
  GLES20.glUniform4fv(mColorHandle, 1, color, 0);

  int mTexHandle = GLES20.glGetUniformLocation(mProgram, "tex");
  GLRenderer.checkGlError("glGetUniformLocation");
  GLES20.glUniform1i(mTexHandle, 0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
  GLRenderer.checkGlError("glBindTexture");

  // get handle to shape's transformation matrix
  int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
  GLRenderer.checkGlError("glGetUniformLocation");
  // Apply the projection and view transformation
  GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
  GLRenderer.checkGlError("glUniformMatrix4fv");

  // Draw the square
  GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
      GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

  // Disable vertex array
  GLES20.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 20
Source File: GLParticles.java    From Tanks with MIT License 4 votes vote down vote up
@Override
protected void draw(RendererContext context, Data data)
{
  if (isEnabled())
    particles.update();

  ShaderParticles shader = (ShaderParticles) Shader.getCurrent();

  // build result matrix
  Matrix.multiplyMM(modelProjectionViewMatrix, 0, context.getProjectionViewMatrix(), 0, modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send data to shader
  float life = count * updateTimeout;
  GLES20.glUniform2f(shader.uniformLifeTimeHandle, life, particles.getTime());
  GLES20.glUniformMatrix4fv(shader.uniformMatrixHandle, 1, false, modelProjectionViewMatrix, 0);
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniform2f(shader.uniformPointSize, startPointSize, endPointSize);
  GLES20.glUniform4fv(shader.uniformStartColor, 1, startColor.getRaw(), 0);
  GLES20.glUniform4fv(shader.uniformEndColor, 1, endColor.getRaw(), 0);

  // reset array buffer
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

  // set offsets to arrays for buffer
  FloatBuffer buffer = particles.getBuffer();
  buffer.position(0);
  GLES20.glVertexAttribPointer(shader.attributeDirectionVectorHandle, 3, GLES20.GL_FLOAT, false, 16, buffer);
  buffer.position(3);
  GLES20.glVertexAttribPointer(shader.attributeStartTimeHandle, 1, GLES20.GL_FLOAT, false, 16, buffer);

  // enable attribute arrays
  GLES20.glEnableVertexAttribArray(shader.attributeDirectionVectorHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeStartTimeHandle);

  // validating if debug
  shader.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_POINTS, 0, particles.getCount());

  // disable attribute arrays
  GLES20.glDisableVertexAttribArray(shader.attributeDirectionVectorHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeStartTimeHandle);

  // auto unbind if max time reached
  if (maxTime > 0 && particles.getTime() > maxTime && !unbinded)
  {
    unbinded = true;
    unbind();
  }
}