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

The following examples show how to use android.opengl.GLES20#glDisable() . 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: MovieEightRects.java    From pause-resume-video-recording with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a frame of data using GL commands.  We have an 8-frame animation
 * sequence that wraps around.  It looks like this:
 * <pre>
 *   0 1 2 3
 *   7 6 5 4
 * </pre>
 * We draw one of the eight rectangles and leave the rest set to the clear color.
 */
private void generateFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
        // (0,0) is bottom-left in GL
        startX = frameIndex * (WIDTH / 4);
        startY = HEIGHT / 2;
    } else {
        startX = (7 - frameIndex) * (WIDTH / 4);
        startY = 0;
    }

    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, WIDTH / 4, HEIGHT / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 3
Source File: PreviewRenderer.java    From retroboy with MIT License 6 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
	// Turn off unneeded features 
	GLES20.glDisable(GLES20.GL_BLEND);
	GLES20.glDisable(GLES20.GL_CULL_FACE);
	GLES20.glDisable(GLES20.GL_DITHER);
	GLES20.glDisable(GLES20.GL_DEPTH_TEST);
	GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
	GLES20.glDisable(GLES20.GL_STENCIL_TEST);
	GLES20.glDepthMask(false);

	// Background color
	GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	
	_program = new ShaderProgram(_context, PreviewShader.SHADER_SOURCE_ID, AtkinsonShader.SHADER_SOURCE_ID);
}
 
Example 4
Source File: GLState.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * @return the previous state.
 */
public boolean disableBlend() {
	if (!this.mBlendEnabled) {
		return false;
	}

	this.mBlendEnabled = false;
	GLES20.glDisable(GLES20.GL_BLEND);
	return true;
}
 
Example 5
Source File: MagicBaseView.java    From TikTok with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glDisable(GL10.GL_DITHER);
    GLES20.glClearColor(0,0, 0, 0);
    GLES20.glEnable(GL10.GL_CULL_FACE);
    GLES20.glEnable(GL10.GL_DEPTH_TEST);
}
 
Example 6
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 7
Source File: WaterMarkFilter.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostDraw() {
    super.onPostDraw();
    GLES20.glDisable(GLES20.GL_BLEND);
    // reset view port to origin.
    GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);
}
 
Example 8
Source File: ShaderRenderer.java    From ShaderEditor with MIT License 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	GLES20.glDisable(GLES20.GL_CULL_FACE);
	GLES20.glDisable(GLES20.GL_BLEND);
	GLES20.glDisable(GLES20.GL_DEPTH_TEST);

	GLES20.glClearColor(0f, 0f, 0f, 1f);

	if (surfaceProgram != 0) {
		// Don't glDeleteProgram(surfaceProgram) because
		// GLSurfaceView::onPause() destroys the GL context
		// what also deletes all programs.
		// With glDeleteProgram():
		// <core_glDeleteProgram:594>: GL_INVALID_VALUE
		surfaceProgram = 0;
	}

	if (program != 0) {
		// Don't glDeleteProgram(program);
		// same as above
		program = 0;
		deleteTargets();
	}

	if (fragmentShader != null && fragmentShader.length() > 0) {
		resetFps();
		createTextures();
		loadPrograms();
		indexLocations();
		enableAttribArrays();
		registerListeners();
	}
}
 
Example 9
Source File: MDMultiFishEyePlugin.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
private void drawConverter(int width, int height){
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    glCheck("MDMultiFisheyeConvertLinePipe glClear");

    int itemWidth = width / 2;
    for (int index = 0; index < 2; index++){
        GLES20.glViewport(itemWidth * index, 0, itemWidth, height);
        GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
        GLES20.glScissor(itemWidth * index, 0, itemWidth, height);

        mProgram.use();
        mTexture.texture(mProgram);

        mFixedDirector.setViewport(itemWidth, height);
        mConverterObject3D.uploadVerticesBufferIfNeed(mProgram, index);
        mConverterObject3D.uploadTexCoordinateBufferIfNeed(mProgram, index);

        // Pass in the combined matrix.
        mFixedDirector.beforeShot();
        mFixedDirector.shot(mProgram, MDPosition.getOriginalPosition());

        mConverterObject3D.draw();

        GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    }

}
 
Example 10
Source File: TextureRenderer.java    From ImageEffects with Eclipse Public License 1.0 5 votes vote down vote up
public void renderTexture(int texId) {
    // Bind default FBO
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    // Use our shader program
    GLES20.glUseProgram(mProgram);
    GLToolbox.checkGlError("glUseProgram");

    // Set viewport
    GLES20.glViewport(0, 0, mViewWidth, mViewHeight);
    GLToolbox.checkGlError("glViewport");

    // Disable blending
    GLES20.glDisable(GLES20.GL_BLEND);

    // Set the vertex attributes
    GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false,
            0, mTexVertices);
    GLES20.glEnableVertexAttribArray(mTexCoordHandle);
    GLES20.glVertexAttribPointer(mPosCoordHandle, 2, GLES20.GL_FLOAT, false,
            0, mPosVertices);
    GLES20.glEnableVertexAttribArray(mPosCoordHandle);
    GLToolbox.checkGlError("vertex attribute setup");

    // Set the input texture
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLToolbox.checkGlError("glActiveTexture");
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);
    GLToolbox.checkGlError("glBindTexture");
    GLES20.glUniform1i(mTexSamplerHandle, 0);

    // Draw
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
 
Example 11
Source File: TextureMovieEncoder.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a box, with position offset.
 */
private void drawBox(int posn) {
    final int width = mInputWindowSurface.getWidth();
    int xpos = (posn * 4) % (width - 50);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(xpos, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 12
Source File: GSYVideoGLViewCustomRender.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) {
    super.onDrawFrame(glUnused);

    //curProgram = createProgram(getVertexShader(), mBitmapEffect.getShader(mSurfaceView));

    GLES20.glUseProgram(curProgram);
    checkGlError("glUseProgram");

    //绑定注入bitmap
    int mFilterInputTextureUniform2 = GLES20.glGetUniformLocation(curProgram, "sTexture2");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesBitmap[0]);
    GLES20.glUniform1i(mFilterInputTextureUniform2, mTexturesBitmap[0]);

    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT,
            false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
            mTriangleVertices);
    checkGlError("glVertexAttribPointer maPosition");
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    checkGlError("glEnableVertexAttribArray maPositionHandle");

    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT,
            false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
            mTriangleVertices);
    checkGlError("glVertexAttribPointer maTextureHandle");
    GLES20.glEnableVertexAttribArray(maTextureHandle);
    checkGlError("glEnableVertexAttribArray maTextureHandle");

    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);


    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    //水印透明
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

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

    GLES20.glFinish();
    GLES20.glDisable(GLES20.GL_BLEND);
}
 
Example 13
Source File: Quad.java    From ShapesInOpenGLES2.0 with MIT License 4 votes vote down vote up
/**
     * draws Quad shape object.
     * @param aMVPMatrix
     * @param texture
     */
    public void render(float[] aMVPMatrix, final int texture) {
//        // Use culling to remove back faces.
        GLES20.glDisable(GLES20.GL_CULL_FACE);

        // Set our per-vertex lighting program.
        GLES20.glUseProgram(aQuadProgramHandle);

        // Set program handles for cube drawing.
        aMVPMatrixHandle = GLES20.glGetUniformLocation(aQuadProgramHandle, "u_MVPMatrix");
        aPositionHandle = GLES20.glGetAttribLocation(aQuadProgramHandle, "a_Position");
        aColorHandle = GLES20.glGetAttribLocation(aQuadProgramHandle, "a_Color");
        aTextureCoordinateHandle = GLES20.glGetAttribLocation(aQuadProgramHandle, "a_TexCoordinate");
        aTextureUniformHandle = GLES20.glGetUniformLocation(aQuadProgramHandle, "u_Texture");

        // Pass in the combined matrix.
        GLES20.glUniformMatrix4fv(aMVPMatrixHandle, 1, false, aMVPMatrix, 0);

        if (qvbo[0] > 0 && qibo[0] > 0) {
            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, qvbo[0]);

            // Bind Attributes
            GLES20.glVertexAttribPointer(aPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false,
                    STRIDE, 0);
            GLES20.glEnableVertexAttribArray(aPositionHandle);

            GLES20.glVertexAttribPointer(aColorHandle, COLOR_DATA_SIZE, GLES20.GL_FLOAT, false,
                    STRIDE, (POSITION_DATA_SIZE) * BYTES_PER_FLOAT);
            GLES20.glEnableVertexAttribArray(aColorHandle);

            GLES20.glVertexAttribPointer(aTextureCoordinateHandle, UV_DATA_SIZE, GLES20.GL_FLOAT, false,
                    STRIDE, (POSITION_DATA_SIZE + COLOR_DATA_SIZE) * BYTES_PER_FLOAT);
            GLES20.glEnableVertexAttribArray(aTextureCoordinateHandle);

            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
            GLES20.glUniform1f(aTextureUniformHandle, 0);

            // Draw
            GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, qibo[0]);
            GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_SHORT, 0);

            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
            GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
        }

//        // Use culling to remove back faces.
//        GLES20.glEnable(GLES20.GL_CULL_FACE);
    }
 
Example 14
Source File: CanvasOverlayEffect.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
@Override
public int applyEffect(int fbo, int textureIdIn) {
    clearCanvas();

    drawCanvas(mCanvas);

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

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture);

    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mCanvasBitmap, 0);

    mRender.drawTexture(mTexture, fbo);

    GLES20.glDisable(GLES20.GL_BLEND);

    return textureIdIn;
}
 
Example 15
Source File: MultiSurfaceActivity.java    From pause-resume-video-recording with Apache License 2.0 4 votes vote down vote up
/**
 * Clears the surface, then draws some alpha-blended rectangles with GL.
 * <p>
 * Creates a temporary EGL context just for the duration of the call.
 */
private void drawRectSurface(Surface surface, int left, int top, int width, int height) {
    EglCore eglCore = new EglCore();
    WindowSurface win = new WindowSurface(eglCore, surface, false);
    win.makeCurrent();
    GLES20.glClearColor(0, 0, 0, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    for (int i = 0; i < 4; i++) {
        int x, y, w, h;
        if (width < height) {
            // vertical
            w = width / 4;
            h = height;
            x = left + w * i;
            y = top;
        } else {
            // horizontal
            w = width;
            h = height / 4;
            x = left;
            y = top + h * i;
        }
        GLES20.glScissor(x, y, w, h);
        switch (i) {
            case 0:     // 50% blue at 25% alpha, pre-multiplied
                GLES20.glClearColor(0.0f, 0.0f, 0.125f, 0.25f);
                break;
            case 1:     // 100% blue at 25% alpha, pre-multiplied
                GLES20.glClearColor(0.0f, 0.0f, 0.25f, 0.25f);
                break;
            case 2:     // 200% blue at 25% alpha, pre-multiplied (should get clipped)
                GLES20.glClearColor(0.0f, 0.0f, 0.5f, 0.25f);
                break;
            case 3:     // 100% white at 25% alpha, pre-multiplied
                GLES20.glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
                break;
        }
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

    win.swapBuffers();
    win.release();
    eglCore.release();
}
 
Example 16
Source File: BackgroundRenderer.java    From react-native-arcore with MIT License 4 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)}
 * and {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects.
 * This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
    // If display rotation changed (also includes view size change), we need to re-query the uv
    // coordinates for the screen rect, as they may have changed as well.
    if (frame.hasDisplayGeometryChanged()) {
        frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
    }

    // No need to test or write depth, the screen quad has arbitrary depth, and is expected
    // to be drawn first.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

    // Set the vertex positions.
    GLES20.glVertexAttribPointer(
        mQuadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mQuadVertices);

    // Set the texture coordinates.
    GLES20.glVertexAttribPointer(mQuadTexCoordParam, TEXCOORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, 0, mQuadTexCoordTransformed);

    // Enable vertex arrays
    GLES20.glEnableVertexAttribArray(mQuadPositionParam);
    GLES20.glEnableVertexAttribArray(mQuadTexCoordParam);

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

    // Disable vertex arrays
    GLES20.glDisableVertexAttribArray(mQuadPositionParam);
    GLES20.glDisableVertexAttribArray(mQuadTexCoordParam);

    // Restore the depth state for further drawing.
    GLES20.glDepthMask(true);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 17
Source File: GLDrawer.java    From Building-Android-UIs-with-Custom-Views with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    angle = ((float) SystemClock.elapsedRealtime() - startTime) * 0.02f;
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    Matrix.setLookAtM(mViewMatrix, 0,
            0, 0, -4,
            0f, 0f, 0f,
            0f, 1.0f, 0.0f);

    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
    Matrix.rotateM(mMVPMatrix, 0, angle, 1.f, 1.f, 1.f);

    GLES20.glUseProgram(shaderProgram);

    int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");

    GLES20.glVertexAttribPointer(positionHandle, 3,
            GLES20.GL_FLOAT, false,
            3 * 4, vertexBuffer);

    int colorHandle = GLES20.glGetAttribLocation(shaderProgram, "aColor");
    GLES20.glVertexAttribPointer(colorHandle, 4,
            GLES20.GL_FLOAT, false,
            4 * 4, colorBuffer);

    int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnableVertexAttribArray(colorHandle);
    GLES20.glEnableVertexAttribArray(positionHandle);
    GLES20.glDrawElements(
            GLES20.GL_TRIANGLES, index.length,
            GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    GLES20.glDisableVertexAttribArray(positionHandle);
    GLES20.glDisableVertexAttribArray(colorHandle);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
}
 
Example 18
Source File: TwoTextureMovieFilter.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
@Override
public void drawFrame(PhotoMovie photoMovie, int elapsedTime, FboTexture inputTexture) {
    if (!mIsInitialized) {
        return;
    }
    GLHelper.checkGlError();
    if (!GLES20.glIsProgram(mProgId)) {
        initShader();
        GlUtil.checkGlError("initShader");
    }
    GLES20.glUseProgram(mProgId);

    loadBitmap();
    onPreDraw(photoMovie, elapsedTime, inputTexture);

    FloatBuffer cubeBuffer = mCubeBuffer;
    FloatBuffer textureCubeBuffer = mTextureCubeBuffer;
    ;

    if (mIsOpaque) {
        GLES20.glDisable(GLES20.GL_BLEND);
    } else {
        GLES20.glEnable(GLES20.GL_BLEND);
    }

    cubeBuffer.position(0);
    GLES20.glVertexAttribPointer(mAttribPosition, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer);
    GLES20.glEnableVertexAttribArray(mAttribPosition);

    textureCubeBuffer.position(0);
    GLES20.glVertexAttribPointer(mAttribTexCoord, 2, GLES20.GL_FLOAT, false, 0,
            textureCubeBuffer);
    GLES20.glEnableVertexAttribArray(mAttribTexCoord);

    int glTextureId = inputTexture.getId();
    if (glTextureId != GLHelper.NO_TEXTURE) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, glTextureId);
        GLES20.glUniform1i(mUniformTexture, 0);
    }
    //加载第二纹理
    if (mTexture2CoordinateAttribute >= 0) {
        GLES20.glEnableVertexAttribArray(mTexture2CoordinateAttribute);
        mTexture2CoordinatesBuffer.position(0);
        GLES20.glVertexAttribPointer(mTexture2CoordinateAttribute, 2, GLES20.GL_FLOAT, false, 0, mTexture2CoordinatesBuffer);
    }

    if (mTexture2Id >= 0) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture2Id);
        GLES20.glUniform1i(mTexture2Uniform2, 3);
    }


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

    GLES20.glDisableVertexAttribArray(mAttribPosition);
    GLES20.glDisableVertexAttribArray(mAttribTexCoord);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    GLES20.glDisable(GLES20.GL_BLEND);
}
 
Example 19
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void disable(int cap) {
    GLES20.glDisable(cap);

}
 
Example 20
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");
}