Java Code Examples for android.opengl.GLES20#glDrawElements()
The following examples show how to use
android.opengl.GLES20#glDrawElements() .
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: GLBubble.java From Android-AudioRecorder-App with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: MDAbsObject3D.java From MD360Player4Android with Apache License 2.0 | 5 votes |
public void draw() { // Draw if (getIndicesBuffer() != null){ getIndicesBuffer().position(0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, getNumIndices(), GLES20.GL_UNSIGNED_SHORT, getIndicesBuffer()); } else { GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, getNumIndices()); } }
Example 3
Source File: Sphere.java From Fatigue-Detection with MIT License | 5 votes |
public void draw() { if (indexBuffer != null){ indexBuffer.position(0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, mNumIndices, GLES20.GL_UNSIGNED_SHORT, indexBuffer); } else { GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mNumIndices); } }
Example 4
Source File: GLImage.java From AndroidPlayground with MIT License | 5 votes |
public void draw(float[] matrix) { int positionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer); int mTexCoordLoc = GLES20.glGetAttribLocation(mProgram, "a_texCoord"); GLES20.glEnableVertexAttribArray(mTexCoordLoc); GLES20.glVertexAttribPointer(mTexCoordLoc, 2, GLES20.GL_FLOAT, false, 0, uvBuffer); // Get handle to shape's transformation matrix int mtrxhandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, matrix, 0); // Get handle to textures locations int mSamplerLoc = GLES20.glGetUniformLocation(mProgram, "s_texture"); // Set the sampler texture unit to 0, where we have saved the texture. GLES20.glUniform1i(mSamplerLoc, 0); // Draw the triangle GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer); // Disable vertex array GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(mTexCoordLoc); }
Example 5
Source File: OffScreenBlurRenderer.java From HokoBlur with Apache License 2.0 | 5 votes |
private void drawOneDimenBlur(BlurContext blurContext, boolean isHorizontal) { try { GLES20.glUseProgram(mProgram.id()); int positionId = GLES20.glGetAttribLocation(mProgram.id(), "aPosition"); GLES20.glEnableVertexAttribArray(positionId); GLES20.glVertexAttribPointer(positionId, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mVertexBuffer); int texCoordId = GLES20.glGetAttribLocation(mProgram.id(), "aTexCoord"); GLES20.glEnableVertexAttribArray(texCoordId); GLES20.glVertexAttribPointer(texCoordId, 2, GLES20.GL_FLOAT, false, 0, mTexCoordBuffer); if (isHorizontal) { blurContext.getBlurFrameBuffer().bindSelf(); } int textureUniformId = GLES20.glGetUniformLocation(mProgram.id(), "uTexture"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, isHorizontal ? blurContext.getInputTexture().id() : blurContext.getHorizontalTexture().id()); GLES20.glUniform1i(textureUniformId, 0); int radiusId = GLES20.glGetUniformLocation(mProgram.id(), "uRadius"); int widthOffsetId = GLES20.glGetUniformLocation(mProgram.id(), "uWidthOffset"); int heightOffsetId = GLES20.glGetUniformLocation(mProgram.id(), "uHeightOffset"); GLES20.glUniform1i(radiusId, mRadius); GLES20.glUniform1f(widthOffsetId, isHorizontal ? 0 : 1f / blurContext.getBitmap().getWidth()); GLES20.glUniform1f(heightOffsetId, isHorizontal ? 1f / blurContext.getBitmap().getHeight() : 0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, mDrawListBuffer); if (!isHorizontal) { GLES20.glDisableVertexAttribArray(positionId); GLES20.glDisableVertexAttribArray(texCoordId); } } finally { resetAllBuffer(); } }
Example 6
Source File: MDAbsObject3D.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
public void draw() { // Draw if (getIndicesBuffer() != null){ getIndicesBuffer().position(0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, getNumIndices(), GLES20.GL_UNSIGNED_SHORT, getIndicesBuffer()); } else { GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, getNumIndices()); } }
Example 7
Source File: GLWave.java From Android-AudioRecorder-App with Apache License 2.0 | 5 votes |
/** * Draw wave. */ 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.glUniform4fv(colorHandle, 1, getColor(), 0); GLES20.glDrawElements(GLES20.GL_TRIANGLE_FAN, shortBuffer.capacity(), GLES20.GL_UNSIGNED_SHORT, shortBuffer); GLES20.glDisableVertexAttribArray(positionHandle); }
Example 8
Source File: MyShader.java From poly-sample-android with Apache License 2.0 | 5 votes |
public void render(float[] mvpMatrix, int numIndices, int ibo, int positionVbo, int colorsVbo) { GLES20.glUseProgram(program); // Set up to feed positions to shader from positions VBO. GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, positionVbo); GLES20.glVertexAttribPointer(positionHandle, MyGLUtils.COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, /* stride */ 0, /* offset in positionVbo */ 0); // Set up to feed colors to shader from color VBO. GLES20.glEnableVertexAttribArray(colorHandle); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, colorsVbo); GLES20.glVertexAttribPointer(colorHandle, MyGLUtils.NUM_COLOR_COMPONENTS, GLES20.GL_FLOAT, false, /* stride */ 0, /* offset in colorVbo */ 0); // Feed MVP matrix uniform to shader. GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); // Bind IBO and render the triangles. GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo); GLES20.glDrawElements(GLES20.GL_TRIANGLES, numIndices, GLES20.GL_UNSIGNED_SHORT, /* offset in ibo */ 0); MyGLUtils.checkGlError("render"); // Clean up. GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(colorHandle); GLES20.glUseProgram(0); }
Example 9
Source File: Square.java From opengl with Apache License 2.0 | 5 votes |
/** * 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 10
Source File: GLDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 4 votes |
@Override public void onDrawFrame(GL10 unused) { scroller.computeScrollOffset(); if (scroller.isFinished()) { int lastX = scroller.getCurrX(); int modulo = lastX % 90; int snapX = (lastX / 90) * 90; if (modulo >= 45) snapX += 90; if (modulo <- 45) snapX -= 90; if (lastX != snapX) { scroller.startScroll(lastX, 0, snapX - lastX, 0); } } 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, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); Matrix.rotateM(mMVPMatrix, 0, scroller.getCurrX(), 0.f, 1.f, 0.f); Matrix.rotateM(mMVPMatrix, 0, 5.f, 1.f, 0.f, 0.f); GLES20.glUseProgram(shaderProgram); int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition"); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, 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.glDisable(GLES20.GL_DEPTH_TEST); }
Example 11
Source File: GLES20Canvas.java From TurboLauncher with Apache License 2.0 | 4 votes |
@Override public void drawMesh(BasicTexture texture, int x, int y, int xyBuffer, int uvBuffer, int indexBuffer, int indexCount) { prepareTexture(texture, mMeshProgram, mMeshParameters); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, xyBuffer); checkError(); int positionHandle = mMeshParameters[INDEX_POSITION].handle; GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, 0); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, uvBuffer); checkError(); int texCoordHandle = mMeshParameters[INDEX_TEXTURE_COORD].handle; GLES20.glVertexAttribPointer(texCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, 0); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); checkError(); GLES20.glEnableVertexAttribArray(positionHandle); checkError(); GLES20.glEnableVertexAttribArray(texCoordHandle); checkError(); setMatrix(mMeshParameters, x, y, 1, 1); GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_BYTE, 0); checkError(); GLES20.glDisableVertexAttribArray(positionHandle); checkError(); GLES20.glDisableVertexAttribArray(texCoordHandle); checkError(); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); checkError(); mCountDrawMesh++; }
Example 12
Source File: VideoTextureRenderer.java From AndroidOpenGLVideoDemo with Apache License 2.0 | 4 votes |
@Override protected boolean draw() { synchronized (this) { if (frameAvailable) { videoTexture.updateTexImage(); videoTexture.getTransformMatrix(videoTextureTransform); frameAvailable = false; } else { return false; } } if (adjustViewport) adjustViewport(); GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // Draw texture GLES20.glUseProgram(shaderProgram); int textureParamHandle = GLES20.glGetUniformLocation(shaderProgram, "texture"); int textureCoordinateHandle = GLES20.glGetAttribLocation(shaderProgram, "vTexCoordinate"); int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition"); int textureTranformHandle = GLES20.glGetUniformLocation(shaderProgram, "textureTransform"); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 4 * 3, vertexBuffer); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glUniform1i(textureParamHandle, 0); GLES20.glEnableVertexAttribArray(textureCoordinateHandle); GLES20.glVertexAttribPointer(textureCoordinateHandle, 4, GLES20.GL_FLOAT, false, 0, textureBuffer); GLES20.glUniformMatrix4fv(textureTranformHandle, 1, false, videoTextureTransform, 0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, DRAW_ORDER.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer); GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(textureCoordinateHandle); return true; }
Example 13
Source File: GLES20Canvas.java From LB-Launcher with Apache License 2.0 | 4 votes |
@Override public void drawMesh(BasicTexture texture, int x, int y, int xyBuffer, int uvBuffer, int indexBuffer, int indexCount) { prepareTexture(texture, mMeshProgram, mMeshParameters); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, xyBuffer); checkError(); int positionHandle = mMeshParameters[INDEX_POSITION].handle; GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, 0); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, uvBuffer); checkError(); int texCoordHandle = mMeshParameters[INDEX_TEXTURE_COORD].handle; GLES20.glVertexAttribPointer(texCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, 0); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); checkError(); GLES20.glEnableVertexAttribArray(positionHandle); checkError(); GLES20.glEnableVertexAttribArray(texCoordHandle); checkError(); setMatrix(mMeshParameters, x, y, 1, 1); GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_BYTE, 0); checkError(); GLES20.glDisableVertexAttribArray(positionHandle); checkError(); GLES20.glDisableVertexAttribArray(texCoordHandle); checkError(); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); checkError(); mCountDrawMesh++; }
Example 14
Source File: InvertedColorsVideoRenderer.java From opentok-android-sdk-samples with MIT License | 4 votes |
@Override public void onDrawFrame(GL10 gl) { gl.glClearColor(0, 0, 0, 1); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); mFrameLock.lock(); if (mCurrentFrame != null && !mVideoDisabled) { GLES20.glUseProgram(mProgram); if (mTextureWidth != mCurrentFrame.getWidth() || mTextureHeight != mCurrentFrame.getHeight()) { setupTextures(mCurrentFrame); } updateTextures(mCurrentFrame); Matrix.setIdentityM(mScaleMatrix, 0); float scaleX = 1.0f, scaleY = 1.0f; float ratio = (float) mCurrentFrame.getWidth() / mCurrentFrame.getHeight(); float vratio = (float) mViewportWidth / mViewportHeight; if (mVideoFitEnabled) { if (ratio > vratio) { scaleY = vratio / ratio; } else { scaleX = ratio / vratio; } } else { if (ratio < vratio) { scaleY = vratio / ratio; } else { scaleX = ratio / vratio; } } Matrix.scaleM(mScaleMatrix, 0, scaleX * (mCurrentFrame.isMirroredX() ? -1.0f : 1.0f), scaleY, 1); if (metadataListener != null) { metadataListener.onMetadataReady(mCurrentFrame.getMetadata()); } int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mScaleMatrix, 0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, mVertexIndex.length, GLES20.GL_UNSIGNED_SHORT, mDrawListBuffer); } else { //black frame when video is disabled gl.glClearColor(0, 0, 0, 1); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); } mFrameLock.unlock(); }
Example 15
Source File: Quad.java From ShapesInOpenGLES2.0 with MIT License | 4 votes |
/** * 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 16
Source File: PointsMatrix.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 4 votes |
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 17
Source File: GLES20Canvas.java From PhotoMovie with Apache License 2.0 | 4 votes |
@Override public void drawMesh(BasicTexture texture, int x, int y, int xyBuffer, int uvBuffer, int indexBuffer, int indexCount) { prepareTexture(texture, mMeshProgram, mMeshParameters); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, xyBuffer); checkError(); int positionHandle = mMeshParameters[INDEX_POSITION].handle; GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, 0); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, uvBuffer); checkError(); int texCoordHandle = mMeshParameters[INDEX_TEXTURE_COORD].handle; GLES20.glVertexAttribPointer(texCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, 0); checkError(); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); checkError(); GLES20.glEnableVertexAttribArray(positionHandle); checkError(); GLES20.glEnableVertexAttribArray(texCoordHandle); checkError(); setMatrix(mMeshParameters, x, y, 1, 1); GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_BYTE, 0); checkError(); GLES20.glDisableVertexAttribArray(positionHandle); checkError(); GLES20.glDisableVertexAttribArray(texCoordHandle); checkError(); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); checkError(); mCountDrawMesh++; }
Example 18
Source File: CameraMatrix.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 4 votes |
/** * 绘制: * * 我们在 onDrawFrame 回调中执行绘制操作,绘制的过程其实就是为 shader 代码变量赋值,并调用绘制命令的过程: */ public void draw(float[] mtx) { // to program GLES20.glUseProgram(mProgram); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID); // get handle to vertex shader's vPosition member // (顶点着色器的vPosition成员得到处理) int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices(使一个句柄三角形顶点) GLES20.glEnableVertexAttribArray(mPositionHandle); // Prepare the <insert shape here> coordinate data (准备<插入形状这里>坐标数据) GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); int mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate"); GLES20.glEnableVertexAttribArray(mTextureCoordHandle); //照相机镜像 textureVerticesBuffer.clear(); textureVerticesBuffer.put(transformTextureCoordinates(textureVertices, mtx)); textureVerticesBuffer.position(0); GLES20.glVertexAttribPointer(mTextureCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, textureVerticesBuffer); GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer); // 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); // GLES20.glVertexAttribPointer(mPositionHandle, 3, // GLES20.GL_FLOAT, false, 0, fb); // GLES20.glEnableVertexAttribArray(mPositionHandle); // // Draw the point // GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1); // } // } // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mTextureCoordHandle); }
Example 19
Source File: AnchorRenderer.java From justaline-android with Apache License 2.0 | 4 votes |
/** * Encapsulates the OpenGL ES instructions for drawing this shape. */ public void draw(float[] cameraView, float[] cameraPerspective, boolean changeColor) { Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); Matrix.scaleM(mModelViewProjectionMatrix, 0, 0.005f, 0.005f, 0.005f); if (mProgram != 0) { // 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); // Get handle to fragment shader's vColor member int mColor = GLES20.glGetAttribLocation(mProgram, "vColor"); // Enable a handle to the color vertices GLES20.glEnableVertexAttribArray(mColor); // Get handle to shape's transformation matrix int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mModelViewProjectionMatrix, 0); checkGlError("glUniformMatrix4fv"); // Prepare the coordinate data GLES20.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mVertexBuffer); // Prepare the color data if (changeColor) { GLES20.glVertexAttribPointer( mColor, COORDS_PER_COLORS, GLES20.GL_FLOAT, false, COLORS_STRIDE, mColor2Buffer); } else { GLES20.glVertexAttribPointer( mColor, COORDS_PER_COLORS, GLES20.GL_FLOAT, false, COLORS_STRIDE, mColor1Buffer); } // Draw the shape GLES20.glDrawElements( GLES20.GL_TRIANGLES, INDICES.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); // Disable color array GLES20.glDisableVertexAttribArray(mColor); } else { Log.i(TAG, "Bummer"); } }
Example 20
Source File: NoosaScript.java From remixed-dungeon with GNU General Public License v3.0 | 3 votes |
public void drawQuad( FloatBuffer vertices ) { if(vertices.limit()<16){ throw new AssertionError(); } vertices.position( 0 ); aXY.vertexPointer( 2, 4, vertices ); vertices.position( 2 ); aUV.vertexPointer( 2, 4, vertices ); GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE, GLES20.GL_UNSIGNED_SHORT, Quad.getIndices( 1 ) ); }