Java Code Examples for android.opengl.GLES30#glUseProgram()
The following examples show how to use
android.opengl.GLES30#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: GLES30WallpaperRenderer.java From alynx-live-wallpaper with Apache License 2.0 | 6 votes |
@Override public void onDrawFrame(GL10 gl10) { if (surfaceTexture == null) { return; } if (renderedFrame < updatedFrame) { surfaceTexture.updateTexImage(); ++renderedFrame; // Utils.debug( // TAG, "renderedFrame: " + renderedFrame + " updatedFrame: " + updatedFrame // ); } GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT); GLES30.glUseProgram(program); GLES30.glUniformMatrix4fv(mvpLocation, 1, false, mvp, 0); GLES30.glBindVertexArray(vertexArrays[0]); GLES30.glDrawElements(GLES30.GL_TRIANGLES, 6, GLES30.GL_UNSIGNED_INT, 0); GLES30.glBindVertexArray(0); GLES30.glUseProgram(0); }
Example 2
Source File: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 6 votes |
/** * シェーダープログラム変更時の初期化処理 * glUseProgramが呼ばれた状態で返る */ @Override protected void init() { if (DEBUG) Log.v(TAG, "init:"); GLES30.glUseProgram(hProgram); maPositionLoc = GLES30.glGetAttribLocation(hProgram, "aPosition"); maTextureCoordLoc = GLES30.glGetAttribLocation(hProgram, "aTextureCoord"); muMVPMatrixLoc = GLES30.glGetUniformLocation(hProgram, "uMVPMatrix"); muTexMatrixLoc = GLES30.glGetUniformLocation(hProgram, "uTexMatrix"); // GLES30.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mMvpMatrix, 0); GLES30.glUniformMatrix4fv(muTexMatrixLoc, 1, false, mMvpMatrix, 0); updateVertices(); }
Example 3
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 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: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 4 votes |
@Override protected void finishDraw() { GLES30.glBindTexture(mTexTarget, 0); GLES30.glUseProgram(0); }
Example 7
Source File: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 4 votes |
/** * glUseProgramが呼ばれた状態で返る * IShaderDrawer2dの実装 */ @Override public void glUseProgram() { GLES30.glUseProgram(hProgram); }
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. }
Example 11
Source File: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 2 votes |
/** * アトリビュート変数のロケーションを取得 * glUseProgramが呼ばれた状態で返る * IShaderDrawer2dの実装 * @param name * @return */ @Override public int glGetAttribLocation(@NonNull final String name) { GLES30.glUseProgram(hProgram); return GLES30.glGetAttribLocation(hProgram, name); }
Example 12
Source File: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 2 votes |
/** * ユニフォーム変数のロケーションを取得 * glUseProgramが呼ばれた状態で返る * IShaderDrawer2dの実装 * @param name * @return */ @Override public int glGetUniformLocation(@NonNull final String name) { GLES30.glUseProgram(hProgram); return GLES30.glGetUniformLocation(hProgram, name); }