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

The following examples show how to use android.opengl.GLES20#glBlendFunc() . 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: WaterMarkFilter.java    From AAVT with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw() {
    //todo change blend and viewport
    super.onDraw();
    if(markTextureId!=-1){
        GLES20.glGetIntegerv(GLES20.GL_VIEWPORT,viewPort,0);
        GLES20.glViewport(markPort[0],mHeight-markPort[3]-markPort[1],markPort[2],markPort[3]);

        GLES20.glEnable(GLES20.GL_BLEND);
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,GLES20.GL_ONE_MINUS_SRC_ALPHA);
        GLES20.glBlendEquation(GLES20.GL_FUNC_ADD);
        mark.draw(markTextureId);
        GLES20.glDisable(GLES20.GL_BLEND);

        GLES20.glViewport(viewPort[0],viewPort[1],viewPort[2],viewPort[3]);
    }
    //todo reset blend and view port
}
 
Example 2
Source File: DrawImageFilter.java    From Fatigue-Detection with MIT License 6 votes vote down vote up
@Override
public void onDrawFrame(int textureId) {
    super.onDrawFrame(textureId);

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    TextureUtils.bindTexture2D(bitmapTexture.getImageTextureId(), GLES20.GL_TEXTURE0,glPassThroughProgram.getTextureSamplerHandle(),0);
    imagePlane.uploadTexCoordinateBuffer(glPassThroughProgram.getTextureCoordinateHandle());
    imagePlane.uploadVerticesBuffer(glPassThroughProgram.getPositionHandle());
    MatrixUtils.updateProjectionFit(
            bitmapTexture.getImageWidth(),
            bitmapTexture.getImageHeight(),
            surfaceWidth,
            surfaceHeight,
            projectionMatrix);
    GLES20.glUniformMatrix4fv(glPassThroughProgram.getMVPMatrixHandle(), 1, false, projectionMatrix, 0);
    imagePlane.draw();
    GLES20.glDisable(GLES20.GL_BLEND);
}
 
Example 3
Source File: GLES20Canvas.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
public GLES20Canvas() {
    Matrix.setIdentityM(mTempTextureMatrix, 0);
    Matrix.setIdentityM(mMatrices, mCurrentMatrixIndex);
    mAlphas[mCurrentAlphaIndex] = 1f;
    mTargetTextures.add(null);

    FloatBuffer boxBuffer = createBuffer(BOX_COORDINATES);
    mBoxCoordinates = uploadBuffer(boxBuffer);

    int drawVertexShader = loadShader(GLES20.GL_VERTEX_SHADER, DRAW_VERTEX_SHADER);
    int textureVertexShader = loadShader(GLES20.GL_VERTEX_SHADER, TEXTURE_VERTEX_SHADER);
    int meshVertexShader = loadShader(GLES20.GL_VERTEX_SHADER, MESH_VERTEX_SHADER);
    int drawFragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, DRAW_FRAGMENT_SHADER);
    int textureFragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, TEXTURE_FRAGMENT_SHADER);
    int oesTextureFragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,
            OES_TEXTURE_FRAGMENT_SHADER);

    mDrawProgram = assembleProgram(drawVertexShader, drawFragmentShader, mDrawParameters);
    mTextureProgram = assembleProgram(textureVertexShader, textureFragmentShader,
            mTextureParameters);
    mOesTextureProgram = assembleProgram(textureVertexShader, oesTextureFragmentShader,
            mOesTextureParameters);
    mMeshProgram = assembleProgram(meshVertexShader, textureFragmentShader, mMeshParameters);
    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    checkError();
}
 
Example 4
Source File: Painting.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void renderBlit() {
    Shader shader = shaders.get("blit");
    if (shader == null) {
        return;
    }

    GLES20.glUseProgram(shader.program);

    GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(renderProjection));
    GLES20.glUniform1i(shader.getUniform("texture"), 0);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture());

    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer);
    GLES20.glEnableVertexAttribArray(0);
    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
    GLES20.glEnableVertexAttribArray(1);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    Utils.HasGLError();
}
 
Example 5
Source File: ModelRenderer.java    From react-native-3d-model-view with MIT License 6 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
	// Set the background frame color
	float[] backgroundColor = main.getModelActivity().getBackgroundColor();
	GLES20.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);

	// Use culling to remove back faces.
	// Don't remove back faces so we can see them
	// GLES20.glEnable(GLES20.GL_CULL_FACE);

	// Enable depth testing for hidden-surface elimination.
	GLES20.glEnable(GLES20.GL_DEPTH_TEST);

	// Enable blending for combining colors when there is transparency
	GLES20.glEnable(GLES20.GL_BLEND);
	GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

	// Lets create our 3D world components
	camera = new Camera();

	// This component will draw the actual models using OpenGL
	drawer = new Object3DBuilder();
}
 
Example 6
Source File: VideoEncodeRender.java    From AudioVideoCodec with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated() {

    //启用透明
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    program = ShaderUtils.createProgram(context.getResources(), "vertex_shader_screen.glsl",
            "fragment_shader_screen.glsl");

    if (program > 0) {
        //获取顶点坐标字段
        avPosition = GLES20.glGetAttribLocation(program, "av_Position");
        //获取纹理坐标字段
        afPosition = GLES20.glGetAttribLocation(program, "af_Position");
        //获取纹理字段
        texture = GLES20.glGetUniformLocation(program, "sTexture");

        //滤镜传入类型
        changeType = GLES20.glGetUniformLocation(program, "vChangeType");
        //对应滤镜需要的颜色
        changeColor = GLES20.glGetUniformLocation(program, "vChangeColor");

        //创建vbo
        createVBO();

        //创建水印纹理
        createWaterTextureId();
    }
}
 
Example 7
Source File: GLState.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public void blendFunction(final int pSourceBlendMode, final int pDestinationBlendMode) {
	if(this.mCurrentSourceBlendMode != pSourceBlendMode || this.mCurrentDestinationBlendMode != pDestinationBlendMode) {
		this.mCurrentSourceBlendMode = pSourceBlendMode;
		this.mCurrentDestinationBlendMode = pDestinationBlendMode;
		GLES20.glBlendFunc(pSourceBlendMode, pDestinationBlendMode);
	}
}
 
Example 8
Source File: Game.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSurfaceCreated( GL10 gl, EGLConfig config ) {
	GLES20.glEnable( GL10.GL_BLEND );
	// For premultiplied alpha:
	// GLES20.glBlendFunc( GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA );
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
	
	GLES20.glEnable( GL10.GL_SCISSOR_TEST );
	
	TextureCache.reload();
}
 
Example 9
Source File: RenderView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if (!initialized || shuttingDown) {
        return;
    }

    setCurrentContext();

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glViewport(0, 0, bufferWidth, bufferHeight);

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    painting.render();

    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    egl10.eglSwapBuffers(eglDisplay, eglSurface);
    if (!firstDrawSent) {
        firstDrawSent = true;
        AndroidUtilities.runOnUIThread(() -> delegate.onFirstDraw());
    }

    if (!ready) {
        queue.postRunnable(() -> ready = true, 200);
    }
}
 
Example 10
Source File: BaseRenderer.java    From VidEffects with Apache License 2.0 5 votes vote down vote up
protected void init() {
    GLES20.glGenBuffers(2, bufferHandles, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferHandles[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, Utils.VERTICES.length * FLOAT_SIZE_BYTES, Utils.getVertexBuffer(), GLES20.GL_DYNAMIC_DRAW);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufferHandles[1]);
    GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, Utils.INDICES.length * FLOAT_SIZE_BYTES, Utils.getIndicesBuffer(), GLES20.GL_DYNAMIC_DRAW);
    GLES20.glGenTextures(2, textureHandles, 0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureHandles[0]);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
}
 
Example 11
Source File: PixelScene.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw() {
	if (light) {
		GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
		super.draw();
		GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
	} else {
		super.draw();
	}
}
 
Example 12
Source File: Game.java    From PD-classes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSurfaceCreated( GL10 gl, EGLConfig config ) {
	GLES20.glEnable( GL10.GL_BLEND );
	// For premultiplied alpha:
	// GLES20.glBlendFunc( GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA );
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
	
	GLES20.glEnable( GL10.GL_SCISSOR_TEST );
	
	TextureCache.reload();
}
 
Example 13
Source File: Flare.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw() {
	
	super.draw();
	
	if (lightMode) {
		GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
		drawRays();
		GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
	} else {
		drawRays();
	}
}
 
Example 14
Source File: HardwareScalerActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the scene.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    // Clear to a non-black color to make the content easily differentiable from
    // the pillar-/letter-boxing.
    GLES20.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Textures may include alpha, so turn blending on.
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    if (mUseFlatShading) {
        mTri.draw(mFlatProgram, mDisplayProjectionMatrix);
        mRect.draw(mFlatProgram, mDisplayProjectionMatrix);
    } else {
        mTri.draw(mTexProgram, mDisplayProjectionMatrix);
        mRect.draw(mTexProgram, mDisplayProjectionMatrix);
    }
    GLES20.glDisable(GLES20.GL_BLEND);

    for (int i = 0; i < 4; i++) {
        mEdges[i].draw(mFlatProgram, mDisplayProjectionMatrix);
    }

    GlUtil.checkGlError("draw done");
}
 
Example 15
Source File: ObjectRenderer.java    From poly-sample-android with Apache License 2.0 4 votes vote down vote up
public void draw(
    float[] cameraView,
    float[] cameraPerspective,
    float[] colorCorrectionRgba,
    float[] objColor) {

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

  // Build the ModelView and ModelViewProjection matrices
  // for calculating object position and light.
  Matrix.multiplyMM(modelViewMatrix, 0, cameraView, 0, modelMatrix, 0);
  Matrix.multiplyMM(modelViewProjectionMatrix, 0, cameraPerspective, 0, modelViewMatrix, 0);

  GLES20.glUseProgram(program);

  // Set the lighting environment properties.
  Matrix.multiplyMV(viewLightDirection, 0, modelViewMatrix, 0, LIGHT_DIRECTION, 0);
  normalizeVec3(viewLightDirection);
  GLES20.glUniform4f(
      lightingParametersUniform,
      viewLightDirection[0],
      viewLightDirection[1],
      viewLightDirection[2],
      1.f);
  GLES20.glUniform4fv(colorCorrectionParameterUniform, 1, colorCorrectionRgba, 0);

  // Set the object color property.
  GLES20.glUniform4fv(colorUniform, 1, objColor, 0);

  // Set the object material properties.
  GLES20.glUniform4f(materialParametersUniform, ambient, diffuse, specular, specularPower);

  // Attach the object texture.
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
  GLES20.glUniform1i(textureUniform, 0);

  // Set the vertex attributes.
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferId);

  GLES20.glVertexAttribPointer(
      positionAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, verticesBaseAddress);
  GLES20.glVertexAttribPointer(normalAttribute, 3, GLES20.GL_FLOAT, false, 0, normalsBaseAddress);
  GLES20.glVertexAttribPointer(
      texCoordAttribute, 2, GLES20.GL_FLOAT, false, 0, texCoordsBaseAddress);

  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

  // Set the ModelViewProjection matrix in the shader.
  GLES20.glUniformMatrix4fv(modelViewUniform, 1, false, modelViewMatrix, 0);
  GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjectionMatrix, 0);

  // Enable vertex arrays
  GLES20.glEnableVertexAttribArray(positionAttribute);
  GLES20.glEnableVertexAttribArray(normalAttribute);
  GLES20.glEnableVertexAttribArray(texCoordAttribute);

  if (blendMode != null) {
    GLES20.glDepthMask(false);
    GLES20.glEnable(GLES20.GL_BLEND);
    switch (blendMode) {
      case Shadow:
        // Multiplicative blending function for Shadow.
        GLES20.glBlendFunc(GLES20.GL_ZERO, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        break;
      case Grid:
        // Grid, additive blending function.
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        break;
    }
  }

  GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBufferId);
  GLES20.glDrawElements(GLES20.GL_TRIANGLES, indexCount, GLES20.GL_UNSIGNED_SHORT, 0);
  GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

  if (blendMode != null) {
    GLES20.glDisable(GLES20.GL_BLEND);
    GLES20.glDepthMask(true);
  }

  // Disable vertex arrays
  GLES20.glDisableVertexAttribArray(positionAttribute);
  GLES20.glDisableVertexAttribArray(normalAttribute);
  GLES20.glDisableVertexAttribArray(texCoordAttribute);

  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

  ShaderUtil.checkGLError(TAG, "After draw");
}
 
Example 16
Source File: Degradation.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw() {
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
	super.draw();
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
}
 
Example 17
Source File: Lightning.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw() {
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
	super.draw();
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
}
 
Example 18
Source File: HallsLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw() {
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
	super.draw();
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
}
 
Example 19
Source File: Fireball.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw() {
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
	super.draw();
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
}
 
Example 20
Source File: Identification.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw() {
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
	super.draw();
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
}