Java Code Examples for android.opengl.GLES30#glEnableVertexAttribArray()
The following examples show how to use
android.opengl.GLES30#glEnableVertexAttribArray() .
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: HelloTriangleRenderer.java From opengl with Apache License 2.0 | 6 votes |
public void onDrawFrame(GL10 glUnused) { // Set the viewport GLES30.glViewport(0, 0, mWidth, mHeight); // Clear the color buffer, which was set above in glClearColor GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT); // Use the program object GLES30.glUseProgram(mProgramObject); // Load the vertex data GLES30.glVertexAttribPointer(0, 3, GLES30.GL_FLOAT, false, 0, mVertices); //set the starting vertex at 0. GLES30.glEnableVertexAttribArray(0); //actually draw the traingle here GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3); }
Example 2
Source File: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 5 votes |
@Override protected void updateVertices() { if (USE_VBO) { if (mBufVertex <= 0) { pVertex.clear(); mBufVertex = GLHelper.createBuffer(GLES30.GL_ARRAY_BUFFER, pVertex, GLES30.GL_STATIC_DRAW); if (DEBUG) Log.v(TAG, "updateVertices:create buffer object for vertex," + mBufVertex); } if (mBufTexCoord <= 0) { pTexCoord.clear(); mBufTexCoord = GLHelper.createBuffer(GLES30.GL_ARRAY_BUFFER, pTexCoord, GLES30.GL_STATIC_DRAW); if (DEBUG) Log.v(TAG, "updateVertices:create buffer object for tex coord," + mBufTexCoord); } // 頂点座標をセット GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mBufVertex); GLES30.glVertexAttribPointer(maPositionLoc, 2, GLES30.GL_FLOAT, false, 0, 0); GLES30.glEnableVertexAttribArray(maPositionLoc); // テクスチャ座標をセット GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mBufTexCoord); GLES30.glVertexAttribPointer(maTextureCoordLoc, 2, GLES30.GL_FLOAT, false, 0, 0); GLES30.glEnableVertexAttribArray(maTextureCoordLoc); } else { // 頂点座標をセット pVertex.clear(); GLES30.glVertexAttribPointer(maPositionLoc, 2, GLES30.GL_FLOAT, false, VERTEX_SZ, pVertex); GLES30.glEnableVertexAttribArray(maPositionLoc); // テクスチャ座標をセット pTexCoord.clear(); GLES30.glVertexAttribPointer(maTextureCoordLoc, 2, GLES30.GL_FLOAT, false, VERTEX_SZ, pTexCoord); GLES30.glEnableVertexAttribArray(maTextureCoordLoc); } }
Example 3
Source File: LessonOneRenderer.java From opengl with Apache License 2.0 | 5 votes |
/** * Draws a triangle from the given vertex data. * * @param aTriangleBuffer The buffer containing the vertex data. */ private void drawTriangle(final FloatBuffer aTriangleBuffer) { // Pass in the position information aTriangleBuffer.position(mPositionOffset); GLES30.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES30.GL_FLOAT, false, mStrideBytes, aTriangleBuffer); GLES30.glEnableVertexAttribArray(mPositionHandle); // Pass in the color information aTriangleBuffer.position(mColorOffset); GLES30.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES30.GL_FLOAT, false, mStrideBytes, aTriangleBuffer); GLES30.glEnableVertexAttribArray(mColorHandle); // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix // (which currently contains model * view). Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0); // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix // (which now contains model * view * projection). Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3); }
Example 4
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 GLES30.glUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES30.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES30.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES30.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES30.GL_FLOAT, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES30.glUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgram, "uMVPMatrix"); MyGLRenderer.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); MyGLRenderer.checkGlError("glUniformMatrix4fv"); // Draw the square GLES30.glDrawElements( GLES30.GL_TRIANGLES, drawOrder.length, GLES30.GL_UNSIGNED_SHORT, drawListBuffer); // Disable vertex array GLES30.glDisableVertexAttribArray(mPositionHandle); }
Example 5
Source File: Triangle.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 GLES30.glUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES30.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES30.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES30.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES30.GL_FLOAT, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES30.glUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgram, "uMVPMatrix"); MyGLRenderer.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); MyGLRenderer.checkGlError("glUniformMatrix4fv"); // Draw the triangle GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, vertexCount); // Disable vertex array GLES30.glDisableVertexAttribArray(mPositionHandle); }
Example 6
Source File: LessonOneRenderer.java From opengl with Apache License 2.0 | 5 votes |
/** * Draws a triangle from the given vertex data. * * @param aTriangleBuffer The buffer containing the vertex data. */ private void drawTriangle(final FloatBuffer aTriangleBuffer) { // Pass in the position information aTriangleBuffer.position(mPositionOffset); GLES30.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES30.GL_FLOAT, false, mStrideBytes, aTriangleBuffer); GLES30.glEnableVertexAttribArray(mPositionHandle); // Pass in the color information aTriangleBuffer.position(mColorOffset); GLES30.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES30.GL_FLOAT, false, mStrideBytes, aTriangleBuffer); GLES30.glEnableVertexAttribArray(mColorHandle); // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix // (which currently contains model * view). Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0); // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix // (which now contains model * view * projection). Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3); }
Example 7
Source File: GLES30WallpaperRenderer.java From alynx-live-wallpaper with Apache License 2.0 | 4 votes |
@Override public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) { // No depth test for 2D video. GLES30.glDisable(GLES30.GL_DEPTH_TEST); GLES30.glDepthMask(false); GLES30.glDisable(GLES30.GL_CULL_FACE); GLES30.glDisable(GLES30.GL_BLEND); GLES30.glGenTextures(textures.length, textures, 0); GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]); GLES30.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR ); GLES30.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR ); GLES30.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE ); GLES30.glTexParameteri( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE ); program = Utils.linkProgramGLES30( Utils.compileShaderResourceGLES30( context, GLES30.GL_VERTEX_SHADER, R.raw.vertex_30 ), Utils.compileShaderResourceGLES30( context, GLES30.GL_FRAGMENT_SHADER, R.raw.fragment_30 ) ); mvpLocation = GLES30.glGetUniformLocation(program, "mvp"); GLES30.glGenBuffers(buffers.length, buffers, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[0]); GLES30.glBufferData( GLES30.GL_ARRAY_BUFFER, vertices.capacity() * BYTES_PER_FLOAT, vertices, GLES30.GL_STATIC_DRAW ); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[1]); GLES30.glBufferData( GLES30.GL_ARRAY_BUFFER, texCoords.capacity() * BYTES_PER_FLOAT, texCoords, GLES30.GL_STATIC_DRAW ); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, buffers[2]); GLES30.glBufferData( GLES30.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * BYTES_PER_INT, indices, GLES30.GL_STATIC_DRAW ); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0); // Locations are set in shader sources. GLES30.glGenVertexArrays(vertexArrays.length, vertexArrays, 0); GLES30.glBindVertexArray(vertexArrays[0]); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[0]); GLES30.glEnableVertexAttribArray(0); GLES30.glVertexAttribPointer( 0, 2, GLES30.GL_FLOAT, false, 2 * BYTES_PER_FLOAT, 0 ); GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, buffers[1]); GLES30.glEnableVertexAttribArray(1); GLES30.glVertexAttribPointer( 1, 2, GLES30.GL_FLOAT, false, 2 * BYTES_PER_FLOAT, 0 ); GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, buffers[2]); GLES30.glBindVertexArray(0); GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); }
Example 8
Source File: Pyramid.java From opengl with Apache License 2.0 | 4 votes |
public void draw(float[] mvpMatrix) { // Use the program object GLES30.glUseProgram(mProgramObject); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgramObject, "uMVPMatrix"); myRenderer.checkGlError("glGetUniformLocation"); // get handle to fragment shader's vColor member mColorHandle = GLES30.glGetUniformLocation(mProgramObject, "vColor"); // Apply the projection and view transformation GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); myRenderer.checkGlError("glUniformMatrix4fv"); int VERTEX_POS_INDX = 0; mVertices.position(VERTEX_POS_INDX); //just in case. We did it already though. //add all the points to the space, so they can be correct by the transformations. //would need to do this even if there were no transformations actually. GLES30.glVertexAttribPointer(VERTEX_POS_INDX, 3, GLES30.GL_FLOAT, false, 0, mVertices); GLES30.glEnableVertexAttribArray(VERTEX_POS_INDX); //Now we are ready to draw the cube finally. int startPos = 0; int verticesPerface = 3; //draw front face GLES30.glUniform4fv(mColorHandle, 1, colorblue, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw right face GLES30.glUniform4fv(mColorHandle, 1, colorcyan, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw back face GLES30.glUniform4fv(mColorHandle, 1, colorred, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw left face GLES30.glUniform4fv(mColorHandle, 1, colorgray, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw bottom face 1 tri square, so 6 faces. GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw bottom face 2 tri square, so 6 faces. GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //last face, so no need to increment. }
Example 9
Source File: Cube.java From opengl with Apache License 2.0 | 4 votes |
public void draw(float[] mvpMatrix) { // Use the program object GLES30.glUseProgram(mProgramObject); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgramObject, "uMVPMatrix"); myRenderer.checkGlError("glGetUniformLocation"); // get handle to fragment shader's vColor member mColorHandle = GLES30.glGetUniformLocation(mProgramObject, "vColor"); // Apply the projection and view transformation GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); myRenderer.checkGlError("glUniformMatrix4fv"); int VERTEX_POS_INDX = 0; mVertices.position(VERTEX_POS_INDX); //just in case. We did it already though. //add all the points to the space, so they can be correct by the transformations. //would need to do this even if there were no transformations actually. GLES30.glVertexAttribPointer(VERTEX_POS_INDX, 3, GLES30.GL_FLOAT, false, 0, mVertices); GLES30.glEnableVertexAttribArray(VERTEX_POS_INDX); //Now we are ready to draw the cube finally. int startPos =0; int verticesPerface = 6; //draw front face GLES30.glUniform4fv(mColorHandle, 1, colorblue, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw back face GLES30.glUniform4fv(mColorHandle, 1, colorcyan, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw left face GLES30.glUniform4fv(mColorHandle, 1, colorred, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw right face GLES30.glUniform4fv(mColorHandle, 1, colorgray, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw top face GLES30.glUniform4fv(mColorHandle, 1, colorgreen, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw bottom face GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); //last face, so no need to increment. }
Example 10
Source File: Cube.java From opengl with Apache License 2.0 | 4 votes |
public void draw(float[] mvpMatrix) { // Use the program object GLES30.glUseProgram(mProgramObject); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgramObject, "uMVPMatrix"); myRenderer.checkGlError("glGetUniformLocation"); // get handle to fragment shader's vColor member mColorHandle = GLES30.glGetUniformLocation(mProgramObject, "vColor"); // Apply the projection and view transformation GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); myRenderer.checkGlError("glUniformMatrix4fv"); int VERTEX_POS_INDX = 0; mVertices.position(VERTEX_POS_INDX); //just in case. We did it already though. //add all the points to the space, so they can be correct by the transformations. //would need to do this even if there were no transformations actually. GLES30.glVertexAttribPointer(VERTEX_POS_INDX, 3, GLES30.GL_FLOAT, false, 0, mVertices); GLES30.glEnableVertexAttribArray(VERTEX_POS_INDX); //Now we are ready to draw the cube finally. int startPos =0; int verticesPerface = 6; //draw front face GLES30.glUniform4fv(mColorHandle, 1, colorblue, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw back face GLES30.glUniform4fv(mColorHandle, 1, colorcyan, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES, startPos, verticesPerface); startPos += verticesPerface; //draw left face GLES30.glUniform4fv(mColorHandle, 1, colorred, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw right face GLES30.glUniform4fv(mColorHandle, 1, colorgray, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw top face GLES30.glUniform4fv(mColorHandle, 1, colorgreen, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); startPos += verticesPerface; //draw bottom face GLES30.glUniform4fv(mColorHandle, 1, coloryellow, 0); GLES30.glDrawArrays(GLES30.GL_TRIANGLES,startPos,verticesPerface); //last face, so no need to increment. }