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

The following examples show how to use android.opengl.GLES20#glUniform4f() . 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: PointCloudRenderer.java    From justaline-android with Apache License 2.0 6 votes vote down vote up
/**
     * Renders the point cloud. ArCore point cloud is given in world space.
     *
     * @param cameraView        the camera view matrix for this frame, typically from {@link
     *                          com.google.ar.core.Camera#getViewMatrix(float[], int)}.
     * @param cameraPerspective the camera projection matrix for this frame, typically from {@link
     *                          com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)}.
     */
    public void draw(float[] cameraView, float[] cameraPerspective) {
        float[] modelViewProjection = new float[16];
        Matrix.multiplyMM(modelViewProjection, 0, cameraPerspective, 0, cameraView, 0);

        ShaderUtil.checkGLError(TAG, "Before draw");
        GLES20.glUseProgram(programName);
        GLES20.glEnableVertexAttribArray(positionAttribute);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
        GLES20.glVertexAttribPointer(positionAttribute, 4, GLES20.GL_FLOAT, false, BYTES_PER_POINT, 0);
//    GLES20.glUniform4f(colorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f);
        GLES20.glUniform4f(colorUniform, 1.0f, 1.0f, 1.0f, 1.0f);
        GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjection, 0);
        GLES20.glUniform1f(pointSizeUniform, 8.0f);

        GLES20.glDrawArrays(GLES20.GL_POINTS, 0, numPoints);
        GLES20.glDisableVertexAttribArray(positionAttribute);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

        ShaderUtil.checkGLError(TAG, "Draw");
    }
 
Example 2
Source File: PointCloudRenderer.java    From react-native-arcore with MIT License 6 votes vote down vote up
/**
 * Renders the point cloud. ArCore point cloud is given in world space.
 *
 * @param cameraView the camera view matrix for this frame, typically from {@link
 *     com.google.ar.core.Camera#getViewMatrix(float[], int)}.
 * @param cameraPerspective the camera projection matrix for this frame, typically from {@link
 *     com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)}.
 */
public void draw(float[] cameraView, float[] cameraPerspective) {
      float[] modelViewProjection = new float[16];
      Matrix.multiplyMM(modelViewProjection, 0, cameraPerspective, 0, cameraView, 0);

      ShaderUtil.checkGLError(TAG, "Before draw");

      GLES20.glUseProgram(mProgramName);
      GLES20.glEnableVertexAttribArray(mPositionAttribute);
      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);
      GLES20.glVertexAttribPointer(
          mPositionAttribute, 4, GLES20.GL_FLOAT, false, BYTES_PER_POINT, 0);
      GLES20.glUniform4f(mColorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f);
      GLES20.glUniformMatrix4fv(mModelViewProjectionUniform, 1, false, modelViewProjection, 0);
      GLES20.glUniform1f(mPointSizeUniform, 5.0f);

      GLES20.glDrawArrays(GLES20.GL_POINTS, 0, mNumPoints);
      GLES20.glDisableVertexAttribArray(mPositionAttribute);
      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

      ShaderUtil.checkGLError(TAG, "Draw");
  }
 
Example 3
Source File: PointCloudRenderer.java    From poly-sample-android with Apache License 2.0 6 votes vote down vote up
/**
 * Renders the point cloud. ARCore point cloud is given in world space.
 *
 * @param cameraView the camera view matrix for this frame, typically from {@link
 *     com.google.ar.core.Camera#getViewMatrix(float[], int)}.
 * @param cameraPerspective the camera projection matrix for this frame, typically from {@link
 *     com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)}.
 */
public void draw(float[] cameraView, float[] cameraPerspective) {
  float[] modelViewProjection = new float[16];
  Matrix.multiplyMM(modelViewProjection, 0, cameraPerspective, 0, cameraView, 0);

  ShaderUtil.checkGLError(TAG, "Before draw");

  GLES20.glUseProgram(programName);
  GLES20.glEnableVertexAttribArray(positionAttribute);
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
  GLES20.glVertexAttribPointer(positionAttribute, 4, GLES20.GL_FLOAT, false, BYTES_PER_POINT, 0);
  GLES20.glUniform4f(colorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f);
  GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjection, 0);
  GLES20.glUniform1f(pointSizeUniform, 5.0f);

  GLES20.glDrawArrays(GLES20.GL_POINTS, 0, numPoints);
  GLES20.glDisableVertexAttribArray(positionAttribute);
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

  ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 4
Source File: Trajectory.java    From ParaViewTangoRecorder with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(float[] viewMatrix, float[] projectionMatrix) {
    GLES20.glUseProgram(mProgram);
    mVertexBuffer.position(0);

    // Compose the model, view, and projection matrices into a single m-v-p
    // matrix
    updateMvpMatrix(viewMatrix, projectionMatrix);

    // Load vertex attribute data
    mPosHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    GLES20.glVertexAttribPointer(mPosHandle, COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, 0, mVertexBuffer);
    GLES20.glEnableVertexAttribArray(mPosHandle);

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

    mColorHandle = GLES20.glGetUniformLocation(mProgram, "aColor");
    GLES20.glUniform4f(mColorHandle, mColor[0], mColor[1], mColor[2],
            mColor[3]);
    GLES20.glLineWidth(mLineWidth);
    GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, mTrajectoryCount);
}
 
Example 5
Source File: Shader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void SetColorUniform(int location, int color) {
    float r = Color.red(color) / 255.0f;
    float g = Color.green(color) / 255.0f;
    float b = Color.blue(color) / 255.0f;
    float a = Color.alpha(color) / 255.0f;

    GLES20.glUniform4f(location, r, g, b, a);
}
 
Example 6
Source File: Shader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void SetColorUniform(int location, int color) {
    float r = Color.red(color) / 255.0f;
    float g = Color.green(color) / 255.0f;
    float b = Color.blue(color) / 255.0f;
    float a = Color.alpha(color) / 255.0f;

    GLES20.glUniform4f(location, r, g, b, a);
}
 
Example 7
Source File: Shader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void SetColorUniform(int location, int color) {
    float r = Color.red(color) / 255.0f;
    float g = Color.green(color) / 255.0f;
    float b = Color.blue(color) / 255.0f;
    float a = Color.alpha(color) / 255.0f;

    GLES20.glUniform4f(location, r, g, b, a);
}
 
Example 8
Source File: GLES20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void draw2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity) {
	boolean changeColor = false;

	float r, g, b, a;
	if(color != null) {
		r = color.red*intensity;
		g = color.green*intensity;
		b = color.blue*intensity;
		a = color.alpha;
	} else {
		r = g = b = intensity;
		a = 1;
	}

	if(texture == null) {
		useProgram(prog_color);
		if(clr != r || clg != g || clb != b || cla != a) {
			clr = r;
			clg = g;
			clb = b;
			cla = a;
			changeColor = true;
		}
	} else {
		bindTexture(texture);
		useProgram(prog_tex);
		if(tlr != r || tlg != g || tlb != b || tla != a) {
			tlr = r;
			tlg = g;
			tlb = b;
			tla = a;
			changeColor = true;
		}
	}

	GLES20.glUniform3fv(lastProgram.ufs[TRANS], 2, new float[] {x, y, z, sx, sy, sz}, 0);

	if(changeColor) {
		GLES20.glUniform4f(lastProgram.ufs[COLOR], r, g, b, a);
	}

	if(gles3) {
		bindFormat(geometry.getInternalFormatId());
	} else {
		bindGeometry(geometry);
		specifyFormat(geometry.getFormat());
	}
	GLES20.glDrawArrays(primitive, offset*vertices, vertices);
}
 
Example 9
Source File: ShaderProgram.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public void setUniformOptional(final String pUniformName, final float pX, final float pY, final float pZ, final float pW) {
	final int location = this.getUniformLocationOptional(pUniformName);
	if(location != ShaderProgramConstants.LOCATION_INVALID) {
		GLES20.glUniform4f(this.getUniformLocationOptional(pUniformName), pX, pY, pZ, pW);
	}
}
 
Example 10
Source File: RRGLProgramColour.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
public void activateColour(final float r, final float g, final float b, final float a) {
	GLES20.glUniform4f(mColorHandle, r, g, b, a);
}
 
Example 11
Source File: GLLabel.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context)
{
  Data data = dataProvider.get();
  Vector3 color = data.colorCoefficients;
  ShaderLabel shader = (ShaderLabel)Shader.getCurrent();

  // get dynamic resources
  Geometry geometryData = GameContext.resources.getGeometry(new LabelGeometrySource(data.value, data.mode, data.charWidth, data.charHeight));

  // build result matrix
  Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0);

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

  // send data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1);

  // set buffer or reset if dynamic
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  switch (geometryData.getMode())
  {
  case Static:
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8);
    break;

  case Dynamic:
    FloatBuffer buffer = geometryData.getData();
    buffer.position(0);
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    buffer.position(2);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    break;
  }

  // enable arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);

  // release dynamic resources
  GameContext.resources.release(geometryData);
}
 
Example 12
Source File: ShaderProgram.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void setUniformOptional(final String pUniformName, final float pX, final float pY, final float pZ, final float pW) {
	final int location = this.getUniformLocationOptional(pUniformName);
	if (location != ShaderProgramConstants.LOCATION_INVALID) {
		GLES20.glUniform4f(this.getUniformLocationOptional(pUniformName), pX, pY, pZ, pW);
	}
}
 
Example 13
Source File: ShaderProgram.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void setUniform(final String pUniformName, final float pX, final float pY, final float pZ, final float pW) {
	GLES20.glUniform4f(this.getUniformLocation(pUniformName), pX, pY, pZ, pW);
}
 
Example 14
Source File: UniformColorSprite.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	GLES20.glUniform4f(PositionTextureCoordinatesUniformColorShaderProgram.sUniformColorLocation, this.mColor.getRed(), this.mColor.getGreen(), this.mColor.getBlue(), this.mColor.getAlpha());
}
 
Example 15
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void uniform4f(int location, float x, float y, float z, float w) {
    GLES20.glUniform4f(location, x, y, z, w);
}
 
Example 16
Source File: Uniform.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public void value4f( float v1, float v2, float v3, float v4 ) {
	GLES20.glUniform4f( location, v1, v2, v3, v4 );
}
 
Example 17
Source File: GLSprite.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context)
{
  Data data = dataProvider.get();
  Vector3 color = data.colorCoefficients;
  ShaderSprite shader = (ShaderSprite)Shader.getCurrent();

  // get dynamic resources
  Image image = GameContext.resources.getImage(new FileImageSource(data.imageName));
  Texture textureData = GameContext.resources.getTexture(new FileTextureSource(image.getTextureName(), false));

  // set texture matrix
  setTextureCoordinates(image.getCoordinates());

  // build result matrix
  Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0);

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

  // send data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix3fv(shader.uniformTextureMatrixHandle, 1, false, textureMatrix.getArray(), 0);
  GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1);

  // set buffer or reset if dynamic
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  switch (geometryData.getMode())
  {
  case Static:
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8);
    break;

  case Dynamic:
    FloatBuffer buffer = geometryData.getData();
    buffer.position(0);
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    buffer.position(2);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    break;
  }

  // enable arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);

  // release dynamic resources
  GameContext.resources.release(image);
  GameContext.resources.release(textureData);
}
 
Example 18
Source File: ColorFilterShaderProgram.java    From Spectaculum with Apache License 2.0 4 votes vote down vote up
public void setColor(float r, float g, float b, float a) {
    use();
    GLES20.glUniform4f(mColorHandle, r, g, b, a);
}
 
Example 19
Source File: PointsMatrix.java    From MegviiFacepp-Android-SDK with Apache License 2.0 4 votes vote down vote up
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");

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

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

		// Apply the projection and view transformation
		GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
		checkGlError("glUniformMatrix4fv");
		// Enable a handle to the triangle vertices
		GLES20.glEnableVertexAttribArray(mPositionHandle);
		// Set color for drawing the triangle
		GLES20.glUniform4fv(mColorHandle, 1, color_rect, 0);

		synchronized (this) {
			for (int i = 0; i < vertexBuffers.size(); i++) {
				FloatBuffer vertexBuffer = vertexBuffers.get(i);
				if (vertexBuffer != null) {
					// Prepare the triangle coordinate data
					GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
							vertexStride, vertexBuffer);
					// Draw the square

					GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT,
							drawListBuffer);
				}
			}
		}

		GLES20.glUniform4fv(mColorHandle, 1, color, 0);

		if (!isFaceCompare&&!isShowFaceRect){    //这里在绘制判断,需要调用api判断
			synchronized (this) {
				for (int i = 0; i < points.size(); i++) {
					ArrayList<FloatBuffer> triangleVBList = points.get(i);
					for (int j = 0; j < triangleVBList.size(); j++) {
						FloatBuffer fb = triangleVBList.get(j);
						if (fb != null) {
							GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, fb);
							// Draw the point
							GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
						}
					}
				}
			}
		}


		synchronized (this) {
			if (bottomVertexBuffer != null) {
				GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
						bottomVertexBuffer);
//				GLES20.glUniform4fv(mColorHandle, 1, color_megvii[1], 0);
//				GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT,
//						drawListBuffer);
//				GLES20.glUniform4fv(mColorHandle, 1, color_megvii[0], 0);
//				GLES20.glDrawElements(GLES20.GL_LINES, drawLineOrder.length, GLES20.GL_UNSIGNED_SHORT,
//						drawLineListBuffer);
				// Draw the square
				GLES20.glLineWidth(4.0f);
				for (int i = 0; i < cubeOrders.length; ++i) {
					GLES20.glUniform4fv(mColorHandle, 1, color_megvii[i + 2], 0);
					GLES20.glDrawElements(GLES20.GL_LINES, cubeOrders[i].length, GLES20.GL_UNSIGNED_SHORT,
							cubeListBuffer[i]);
				}
			}
		}


		synchronized (this){
			if (faceRects != null && faceRects.size()>0){
				GLES20.glLineWidth(4.0f);
				GLES20.glUniform4f(mColorHandle, 1.0f, 0.0f, 0.0f, 1.0f);

				for(int i = 0; i < faceRects.size(); i++){
					FloatBuffer buffer = faceRects.get(i);
					GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, buffer);
					GLES20.glDrawElements(GLES20.GL_LINES, drawFaceRectOrder.length, GLES20.GL_UNSIGNED_SHORT, faceRectListBuffer);

				}
			}
		}



			// Disable vertex array
		GLES20.glDisableVertexAttribArray(mPositionHandle);
	}
 
Example 20
Source File: Uniform.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
public void value4f( float v1, float v2, float v3, float v4 ) {
	GLES20.glUniform4f( location, v1, v2, v3, v4 );
}