Java Code Examples for android.opengl.GLES20#glUseProgram()
The following examples show how to use
android.opengl.GLES20#glUseProgram() .
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: BaseOverlayGlFilter.java From LiTr with BSD 2-Clause "Simplified" License | 6 votes |
void renderOverlayTexture(int textureId) { // Switch to overlay texture GLES20.glUseProgram(glOverlayProgram); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glUniformMatrix4fv(overlayMvpMatrixHandle, 1, false, mvpMatrix, mvpMatrixOffset); GLES20.glUniformMatrix4fv(overlayUstMatrixHandle, 1, false, stMatrix, 0); // Enable blending GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); // Call OpenGL to draw GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GlRenderUtils.checkGlError("glDrawArrays"); GLES20.glDisable(GLES20.GL_BLEND); }
Example 2
Source File: CameraDrawer.java From CameraDemo with Apache License 2.0 | 6 votes |
public void draw(int texture, boolean isFrontCamera) { GLES20.glUseProgram(mProgram); // 指定使用的program GLES20.glEnable(GLES20.GL_CULL_FACE); // 启动剔除 GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture); // 绑定纹理 GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, VERTEX_SIZE, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mVertexBuffer); GLES20.glEnableVertexAttribArray(mTextureHandle); if (isFrontCamera) { GLES20.glVertexAttribPointer(mTextureHandle, VERTEX_SIZE, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mFrontTextureBuffer); } else { GLES20.glVertexAttribPointer(mTextureHandle, VERTEX_SIZE, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mBackTextureBuffer); } // 真正绘制的操作 GLES20.glDrawElements(GLES20.GL_TRIANGLE_FAN, VERTEX_ORDER.length, GLES20.GL_UNSIGNED_BYTE, mDrawListBuffer); GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mTextureHandle); }
Example 3
Source File: ZebraFilterRender.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 6 votes |
@Override protected void drawFilter() { GLES20.glUseProgram(program); squareVertex.position(SQUARE_VERTEX_DATA_POS_OFFSET); GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false, SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex); GLES20.glEnableVertexAttribArray(aPositionHandle); squareVertex.position(SQUARE_VERTEX_DATA_UV_OFFSET); GLES20.glVertexAttribPointer(aTextureHandle, 2, GLES20.GL_FLOAT, false, SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex); GLES20.glEnableVertexAttribArray(aTextureHandle); GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, MVPMatrix, 0); GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, STMatrix, 0); float time = ((float) (System.currentTimeMillis() - START_TIME)) / 1000.0f; GLES20.glUniform1f(uTimeHandle, time); GLES20.glUniform1f(uLevelsHandle, levels); GLES20.glUniform1i(uSamplerHandle, 4); GLES20.glActiveTexture(GLES20.GL_TEXTURE4); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, previousTexId); }
Example 4
Source File: GLES20Canvas.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
private void prepareTexture(BasicTexture texture, int program, ShaderParameter[] params) { GLES20.glUseProgram(program); checkError(); enableBlending(!texture.isOpaque() || getAlpha() < OPAQUE_ALPHA); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); checkError(); texture.onBind(this); GLES20.glBindTexture(texture.getTarget(), texture.getId()); checkError(); GLES20.glUniform1i(params[INDEX_TEXTURE_SAMPLER].handle, 0); checkError(); GLES20.glUniform1f(params[INDEX_ALPHA].handle, getAlpha()); checkError(); }
Example 5
Source File: FlatShadedProgram.java From cineio-broadcast-android with MIT License | 5 votes |
/** * 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 6
Source File: CameraGLRendererBase.java From MOAAP with MIT License | 5 votes |
private void drawTex(int tex, boolean isOES, int fbo) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo); if(fbo == 0) GLES20.glViewport(0, 0, mView.getWidth(), mView.getHeight()); else GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if(isOES) { GLES20.glUseProgram(progOES); GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTCOES, 2, GLES20.GL_FLOAT, false, 4*2, texOES); } else { GLES20.glUseProgram(prog2D); GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTC2D, 2, GLES20.GL_FLOAT, false, 4*2, tex2D); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if(isOES) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 7
Source File: Program.java From HokoBlur with Apache License 2.0 | 5 votes |
@Override public void delete() { if (id != 0) { GLES20.glUseProgram(0); GLES20.glDeleteProgram(id); } }
Example 8
Source File: MediaEffectDrawer.java From libcommon with Apache License 2.0 | 5 votes |
public void release() { GLES20.glUseProgram(0); if (hProgram >= 0) { GLES20.glDeleteProgram(hProgram); } hProgram = -1; }
Example 9
Source File: AnnotationRenderer.java From ARCore-Location with MIT License | 5 votes |
public void draw(float[] cameraView, float[] cameraPerspective) { ShaderUtil.checkGLError(TAG, "Before draw"); Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); GLES20.glUseProgram(mQuadProgram); // Attach the object texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glBlendColor(0,0,0,0); GLES20.glUniform1i(mTextureUniform, 0); GLES20.glUniformMatrix4fv(mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0); // 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, mQuadTexCoord); // 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); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); ShaderUtil.checkGLError(TAG, "After draw"); }
Example 10
Source File: FlatShadedProgram.java From mobile-ar-sensor-logger with GNU General Public License v3.0 | 5 votes |
/** * 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: AnnotationRenderer.java From ARCore-Location with MIT License | 4 votes |
@Override public void draw(float[] cameraView, float[] cameraPerspective, float lightIntensity) { ShaderUtil.checkGLError(TAG, "Before draw"); Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); GLES20.glUseProgram(mQuadProgram); // Attach the object texture. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glBlendColor(0,0,0,0); GLES20.glUniform1i(mTextureUniform, 0); GLES20.glUniformMatrix4fv(mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0); // 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, mQuadTexCoord); // 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); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); ShaderUtil.checkGLError(TAG, "After draw"); }
Example 12
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 4 votes |
@Override public void onDrawFrame(GL10 gl) { if (surfaceTexture == null) return; GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); surfaceTexture.updateTexImage(); float matrix[] = new float[16]; surfaceTexture.getTransformMatrix(matrix); // camTextureId->fboTexureId GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo[0]); GLES20.glViewport(0, 0, textureWidth, textureHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(progCam2FBO); GLES20.glVertexAttribPointer(vcCam2FBO, 2, GLES20.GL_FLOAT, false, 4 * 2, vertexCoordsBuffer); textureCoordsBuffer.clear(); textureCoordsBuffer.put(transformTextureCoordinates(textureCoords, matrix)); textureCoordsBuffer.position(0); GLES20.glVertexAttribPointer(tcCam2FBO, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoordsBuffer); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, camTextureId[0]); GLES20.glUniform1i(GLES20.glGetUniformLocation(progCam2FBO, "sTexture"), 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); // Check if the draw texture is set int targetTexureId = fboTexureId[0]; if (onTextureChangedListener != null) { boolean modified = onTextureChangedListener.onTextureChanged(fboTexureId[0], drawTexureId[0], textureWidth, textureHeight); if (modified) { targetTexureId = drawTexureId[0]; } } // fboTexureId/drawTexureId->Screen GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(progTex2Screen); GLES20.glVertexAttribPointer(vcTex2Screen, 2, GLES20.GL_FLOAT, false, 4 * 2, vertexCoordsBuffer); textureCoordsBuffer.clear(); textureCoordsBuffer.put(textureCoords); textureCoordsBuffer.position(0); GLES20.glVertexAttribPointer(tcTex2Screen, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoordsBuffer); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, targetTexureId); GLES20.glUniform1i(GLES20.glGetUniformLocation(progTex2Screen, "sTexture"), 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 13
Source File: GLDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 4 votes |
@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, 0, vertexBuffer); int texCoordHandle = GLES20.glGetAttribLocation(shaderProgram, "aTex"); GLES20.glVertexAttribPointer(texCoordHandle, 2, GLES20.GL_FLOAT, false, 0, texBuffer); int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix"); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); int texHandle = GLES20.glGetUniformLocation(shaderProgram, "sTex"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glUniform1i(texHandle, 0); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnableVertexAttribArray(texHandle); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glDrawElements( GLES20.GL_TRIANGLES, index.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer); GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(texHandle); GLES20.glDisable(GLES20.GL_DEPTH_TEST); }
Example 14
Source File: Cubes.java From ShapesInOpenGLES2.0 with MIT License | 4 votes |
/** * draws cube shape objects * @param aMVPMatrix * @param texture */ public void render(float[] aMVPMatrix, int texture) { // Set our per-vertex lighting program. GLES20.glUseProgram(aCubesProgramHandle); // Set program handles for cube drawing. aMVPMatrixHandle = GLES20.glGetUniformLocation(aCubesProgramHandle, "u_MVPMatrix"); aMVMatrixHandle = GLES20.glGetUniformLocation(aCubesProgramHandle, "u_MVMatrix"); aLightPosHandle = GLES20.glGetUniformLocation(aCubesProgramHandle, "u_LightPos"); int aColorHandle = GLES20.glGetAttribLocation(aCubesProgramHandle, "a_Color"); int aUseColorHandle = GLES20.glGetUniformLocation(aCubesProgramHandle, "u_UseColor"); aTextureUniformHandle = GLES20.glGetUniformLocation(aCubesProgramHandle, "u_Texture"); aPositionHandle = GLES20.glGetAttribLocation(aCubesProgramHandle, "a_Position"); aNormalHandle = GLES20.glGetAttribLocation(aCubesProgramHandle, "a_Normal"); aTextureCoordinateHandle = GLES20.glGetAttribLocation(aCubesProgramHandle, "a_TexCoordinate"); // Pass in the position information GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aCubePositionsBufferIdx); GLES20.glEnableVertexAttribArray(aPositionHandle); GLES20.glVertexAttribPointer(aPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0); // Pass in the normal information GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aCubeColorBufferIdx); GLES20.glEnableVertexAttribArray(aColorHandle); GLES20.glVertexAttribPointer(aColorHandle, COLOR_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0); // Pass in the normal information GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aCubeNormalsBufferIdx); GLES20.glEnableVertexAttribArray(aNormalHandle); GLES20.glVertexAttribPointer(aNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0); // Pass in the texture information GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aCubeTexCoordsBufferIdx); GLES20.glEnableVertexAttribArray(aTextureCoordinateHandle); GLES20.glVertexAttribPointer(aTextureCoordinateHandle, TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture); GLES20.glUniform1f(aTextureUniformHandle, 0); // Pass in the modelview matrix. GLES20.glUniformMatrix4fv(aMVMatrixHandle, 1, false, aMVPMatrix, 0); // Pass in the combined matrix. GLES20.glUniformMatrix4fv(aMVPMatrixHandle, 1, false, aMVPMatrix, 0); GLES20.glUniform1f(aUseColorHandle, 0.0f); // Pass in the color . // GLES20.glUniform4f(aColorHandle, Color.red(color), Color.green(color), Color.blue(color), 1); // Clear the currently bound buffer (so future OpenGL calls do not use this buffer). GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); // Draw the cubes. GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); }
Example 15
Source File: LineShaderRenderer.java From ar-drawing-java with Apache License 2.0 | 4 votes |
/** * * This method takes in the current CameraView Matrix and the Camera's Projection Matrix, the * current position and pose of the device, uses those to calculate the ModelViewMatrix and * ModelViewProjectionMatrix. It binds the VBO, enables the custom attribute locations, * binds and uploads the shader uniforms, calls our single DrawArray call, and finally disables * and unbinds the shader attributes and VBO. * * @param cameraView * @param cameraPerspective * @param screenWidth * @param screenHeight * @param nearClip * @param farClip */ public void draw(float[] cameraView, float[] cameraPerspective, float screenWidth, float screenHeight, float nearClip, float farClip) { Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); ShaderUtil.checkGLError(TAG, "Before draw"); GLES20.glUseProgram(mProgramName); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo); GLES20.glVertexAttribPointer( mPositionAttribute, FLOATS_PER_POINT, GLES20.GL_FLOAT, false, BYTES_PER_POINT, mPositionAddress); GLES20.glVertexAttribPointer( mPreviousAttribute, FLOATS_PER_POINT, GLES20.GL_FLOAT, false, BYTES_PER_POINT, mPreviousAddress); GLES20.glVertexAttribPointer( mNextAttribute, FLOATS_PER_POINT, GLES20.GL_FLOAT, false, BYTES_PER_POINT, mNextAddress); GLES20.glVertexAttribPointer( mSideAttribute, 1, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT, mSideAddress); GLES20.glVertexAttribPointer( mWidthAttribte, 1, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT, mWidthAddress); GLES20.glVertexAttribPointer( mCountersAttribute, 1, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT, mCounterAddress); GLES20.glUniformMatrix4fv( mModelViewUniform, 1, false, mModelViewMatrix, 0); GLES20.glUniformMatrix4fv( mProjectionUniform, 1, false, cameraPerspective, 0); GLES20.glUniform2f(mResolutionUniform, screenWidth, screenHeight); GLES20.glUniform1f(mLineWidthUniform, 0.01f); GLES20.glUniform3f(mColorUniform, mColor.x, mColor.y, mColor.z); GLES20.glUniform1f(mOpacityUniform, 1.0f); GLES20.glUniform1f(mNearUniform, nearClip); GLES20.glUniform1f(mFarUniform, farClip); GLES20.glUniform1f(mSizeAttenuationUniform, 1.0f); GLES20.glUniform1f(mVisibility, 1.0f); GLES20.glUniform1f(mAlphaTest, 1.0f); GLES20.glUniform1f(mDrawModeUniform, mDrawMode?1.0f:0.0f); GLES20.glUniform1f(mNearCutoffUniform, mDrawDistance - 0.0075f); GLES20.glUniform1f(mFarCutoffUniform, mDrawDistance + 0.0075f); GLES20.glUniform1f(mLineDepthScaleUniform, mLineDepthScale); GLES20.glEnableVertexAttribArray(mPositionAttribute); GLES20.glEnableVertexAttribArray(mPreviousAttribute); GLES20.glEnableVertexAttribArray(mNextAttribute); GLES20.glEnableVertexAttribArray(mSideAttribute); GLES20.glEnableVertexAttribArray(mWidthAttribte); GLES20.glEnableVertexAttribArray(mCountersAttribute); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mNumBytes); GLES20.glDisableVertexAttribArray(mCountersAttribute); GLES20.glDisableVertexAttribArray(mWidthAttribte); GLES20.glDisableVertexAttribArray(mSideAttribute); GLES20.glDisableVertexAttribArray(mNextAttribute); GLES20.glDisableVertexAttribArray(mPreviousAttribute); GLES20.glDisableVertexAttribArray(mPositionAttribute); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); ShaderUtil.checkGLError(TAG, "Draw"); }
Example 16
Source File: Cube.java From TraceByAmap with MIT License | 4 votes |
public void drawES20(float[] mvp) { GLES20.glUseProgram(shader.program); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnableVertexAttribArray(shader.aVertex); //顶点指针 GLES20.glVertexAttribPointer(shader.aVertex, 3, GLES20.GL_FLOAT, false, 0, vertextBuffer); //颜色指针 GLES20.glEnableVertexAttribArray(shader.aColor); GLES20.glVertexAttribPointer(shader.aColor,4, GLES20.GL_FLOAT,false,0,colorBuffer); GLES20.glUniformMatrix4fv(shader.aMVPMatrix,1,false,mvp,0); //开始画 GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer); GLES20.glDisableVertexAttribArray(shader.aVertex); GLES20.glDisable(GLES20.GL_DEPTH_TEST); }
Example 17
Source File: GlFilter.java From CameraRecorder-android with MIT License | 4 votes |
protected final void useProgram() { GLES20.glUseProgram(program); }
Example 18
Source File: TextureKernelShaderProgram.java From Spectaculum with Apache License 2.0 | 4 votes |
public void setKernel(Kernel kernel) { GLES20.glUseProgram(getHandle()); GLES20.glUniform1fv(mKernelHandle, 9, kernel.mKernel, 0); }
Example 19
Source File: GLTextureRect.java From GLES2_AUDIO_VIDEO_RECODE with Apache License 2.0 | 4 votes |
/** * 绘制 * * @param texId 纹理id * @param mMvpMatrix 最终变换矩阵 */ public void draw(final int texId, float[] mMvpMatrix) { // ---------注:这里直接用最终变换矩阵进行绘制,不要再进行其他的矩阵变换----------- //制定使用某套着色器程序 GLES20.glUseProgram(mProgram); //矩阵传入着色器程序 GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMvpMatrix, 0); // 将顶点坐标数据传入渲染管线 GLES20.glVertexAttribPointer ( maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer ); // 将顶点纹理坐标数据传入渲染管线 GLES20.glVertexAttribPointer ( maTexCoorHandle, 2, GLES20.GL_FLOAT, false, 2 * 4, mTexCoorBuffer ); // 启用顶点位置数据 GLES20.glEnableVertexAttribArray(maPositionHandle); GLES20.glEnableVertexAttribArray(maTexCoorHandle); //绑定纹理 GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texId); // 绘制三角形 GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, VERTEX_NUM); }
Example 20
Source File: Painting.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public PaintingData getPaintingData(RectF rect, boolean undo) { int minX = (int) rect.left; int minY = (int) rect.top; int width = (int) rect.width(); int height = (int) rect.height(); GLES20.glGenFramebuffers(1, buffers, 0); int framebuffer = buffers[0]; GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer); GLES20.glGenTextures(1, buffers, 0); int texture = buffers[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture, 0); GLES20.glViewport(0, 0, (int) size.width, (int) size.height); if (shaders == null) { return null; } Shader shader = shaders.get(undo ? "nonPremultipliedBlit" : "blit"); if (shader == null) { return null; } GLES20.glUseProgram(shader.program); Matrix translate = new Matrix(); translate.preTranslate(-minX, -minY); float effective[] = GLMatrix.LoadGraphicsMatrix(translate); float finalProjection[] = GLMatrix.MultiplyMat4f(projection, effective); GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(finalProjection)); if (undo) { GLES20.glUniform1i(shader.getUniform("texture"), 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture()); } else { GLES20.glUniform1i(shader.getUniform("texture"), 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, bitmapTexture.texture()); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture()); } GLES20.glClearColor(0, 0, 0, 0); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 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); dataBuffer.limit(width * height * 4); GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, dataBuffer); PaintingData data; if (undo) { data = new PaintingData(null, dataBuffer); } else { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(dataBuffer); data = new PaintingData(bitmap, null); } buffers[0] = framebuffer; GLES20.glDeleteFramebuffers(1, buffers, 0); buffers[0] = texture; GLES20.glDeleteTextures(1, buffers, 0); return data; }