List of usage examples for android.opengl GLES20 glVertexAttribPointer
public static void glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, java.nio.Buffer ptr)
From source file:Triangle.java
public void draw() { GLES20.glUseProgram(mProgram);/*www . j a v a 2 s .co m*/ mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); GLES20.glUniform4fv(mColorHandle, 1, color, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); GLES20.glDisableVertexAttribArray(mPositionHandle); }
From source file:Triangle.java
public void draw(float[] mvpMatrix) { GLES20.glUseProgram(mProgram);//from ww w . ja v a2 s . c o m mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); GLES20.glUniform4fv(mColorHandle, 1, color, 0); mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); GLES20.glDisableVertexAttribArray(mPositionHandle); }
From source file:com.kentdisplays.synccardboarddemo.Page.java
/** * Encapsulates the OpenGL ES instructions for drawing this page. * * @param perspective//w w w . jav a 2 s . c om * @param view */ public void draw(float[] perspective, float[] view) { mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position"); mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal"); mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color"); mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP"); mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor"); mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model"); mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix"); // This is not the floor! GLES20.glUniform1f(mIsFloorParam, 0f); // Set the Model in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModel, 0); // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. float[] modelView = new float[16]; float[] modelViewProjection = new float[16]; Matrix.multiplyMM(modelView, 0, view, 0, mModel, 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); // Set the ModelView in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, modelView, 0); // Set the position of the cube GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mPageVertices); // Set the ModelViewProjection matrix in the shader. GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, modelViewProjection, 0); // Set the normal positions of the cube, again for shading GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mPageNormals); GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mPageColors); // Animate over all the paths every 30 seconds. long time = SystemClock.uptimeMillis() % 30000L; int numberOfPathsToDraw = Math.round(mNumberOfPaths / 30000.0f * time); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, numberOfPathsToDraw * 6); }
From source file:com.kentdisplays.synccardboarddemo.MainActivity.java
/** * Draw the floor. This feeds in data for the floor into the shader. Note that this doesn't * feed in data about position of the light, so if we rewrite our code to draw the floor first, * the lighting might look strange./*from w ww.ja v a 2 s . c o m*/ */ public void drawFloor(float[] perspective) { // This is the floor! GLES20.glUniform1f(mIsFloorParam, 1f); // Set ModelView, MVP, position, normals, and color GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelFloor, 0); GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0); GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0); GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mFloorVertices); GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mFloorNormals); GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mFloorColors); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); checkGLError("drawing floor"); }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Draw the cube./* w w w . j a v a 2s .co m*/ * * <p>We've set all of our transformation matrices. Now we simply pass them into the shader. */ public void drawCube() { GLES20.glUseProgram(cubeProgram); GLES20.glUniform3fv(cubeLightPosParam, 1, lightPosInEyeSpace, 0); // Set the Model in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(cubeModelParam, 1, false, modelCube, 0); // Set the ModelView in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(cubeModelViewParam, 1, false, modelView, 0); // Set the position of the cube GLES20.glVertexAttribPointer(cubePositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, cubeVertices); // Set the ModelViewProjection matrix in the shader. GLES20.glUniformMatrix4fv(cubeModelViewProjectionParam, 1, false, modelViewProjection, 0); // Set the normal positions of the cube, again for shading GLES20.glVertexAttribPointer(cubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, cubeNormals); GLES20.glVertexAttribPointer(cubeColorParam, 4, GLES20.GL_FLOAT, false, 0, isLookingAtObject() ? cubeFoundColors : cubeColors); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36); checkGLError("Drawing cube"); }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
/** * Draw the rect. We've set all of our transformation matrices. Now we simply pass them into * the shader./*from w ww . ja v a2 s. c om*/ */ public void drawRect(int texIndex) { if (mRectTextureIds[texIndex] < INVALID_TEXTURE) { // can't draw this rectangle return; } // This is not the floor! GLES20.glUniform1f(mIsFloorParam, 0f); // Set the active texture unit GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texIndex); // Bind the texture to this unit. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mRectTextureIds[texIndex]); // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0. GLES20.glUniform1i(mRectTextureUniformParam, texIndex); // Set the Model in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelRect[texIndex], 0); // Set the ModelView in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0); // Set the position of the rect GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mRectVertices); // Set the ModelViewProjection matrix in the shader. GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0); // Set the normal positions of the rect, again for shading GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mRectNormals); // Connect texBuffer to "aTextureCoord". GLES20.glVertexAttribPointer(mRectTextureCoordinateParam, 2, GLES20.GL_FLOAT, false, 0, mRectTexCoords); // Enable the "aTextureCoord" vertex attribute. GLES20.glEnableVertexAttribArray(mRectTextureCoordinateParam); if (texIndex == mSelectedTexIndex || isLookingAtObject(texIndex)) { GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mRectFoundColors); } else { GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mRectColors); } GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, WorldLayoutData.RECT_COORDS.length / 3); // 3 b/c triangles checkGLError("Drawing rect"); }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
public void drawMiniCube() { GLES20.glUseProgram(miniCubeProgram); GLES20.glUniform3fv(miniCubeLightPosParam, 1, lightPosInEyeSpace, 0); // Set the Model in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(miniCubeModelParam, 1, false, modelMiniCube, 0); // Set the ModelView in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(miniCubeModelViewParam, 1, false, modelView, 0); // Set the position of the miniCube GLES20.glVertexAttribPointer(miniCubePositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, miniCubeVertices);/*from w w w . j a va 2s .c om*/ // Set the ModelViewProjection matrix in the shader. GLES20.glUniformMatrix4fv(miniCubeModelViewProjectionParam, 1, false, modelViewProjection, 0); // Set the normal positions of the miniCube, again for shading GLES20.glVertexAttribPointer(miniCubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, miniCubeNormals); GLES20.glVertexAttribPointer(miniCubeColorParam, 4, GLES20.GL_FLOAT, false, 0, miniCubeColors); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36); checkGLError("Drawing miniCube"); }
From source file:com.sveder.cardboardpassthrough.MainActivity.java
/** * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as * a parameter.// www.j a v a2s. com * @param transform The transformations to apply to render this eye. */ @Override public void onDrawEye(EyeTransform transform) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glUseProgram(mProgram); GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES); GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture); mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position"); GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate"); GLES20.glEnableVertexAttribArray(mTextureCoordHandle); GLES20.glVertexAttribPointer(mTextureCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, textureVerticesBuffer); mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture"); GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mTextureCoordHandle); Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0); // mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position"); // mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal"); // mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color"); // // GLES20.glEnableVertexAttribArray(mPositionParam); // GLES20.glEnableVertexAttribArray(mNormalParam); // GLES20.glEnableVertexAttribArray(mColorParam); // checkGLError("mColorParam"); // // // Apply the eye transformation to the camera. // Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0); // // // Set the position of the light // Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0); // GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], // mLightPosInEyeSpace[2]); // // // Build the ModelView and ModelViewProjection matrices // // for calculating cube position and light. // Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0); // Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0); // drawCube(); // // // Set mModelView for the floor, so we draw floor in the correct location // Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0); // Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, // mModelView, 0); // drawFloor(transform.getPerspective()); }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
/** * Draw the floor. This feeds in data for the floor into the shader. Note that this doesn't * feed in data about position of the light, so if we rewrite our code to draw the floor first, * the lighting might look strange./*ww w. j a v a 2s . co m*/ */ @SuppressWarnings("UnusedParameters") public void drawFloor(float[] perspective) { // This is the floor! GLES20.glUniform1f(mIsFloorParam, 1f); // Set ModelView, MVP, position, normals, and color GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelFloor, 0); GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0); GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0); GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mFloorVertices); GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mFloorNormals); GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mFloorColors); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); checkGLError("drawing floor"); }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Draw the floor.// w w w .j av a2 s . c om * * <p>This feeds in data for the floor into the shader. Note that this doesn't feed in data about * position of the light, so if we rewrite our code to draw the floor first, the lighting might * look strange. */ public void drawFloor() { GLES20.glUseProgram(floorProgram); // Set ModelView, MVP, position, normals, and color. GLES20.glUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0); GLES20.glUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0); GLES20.glUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0); GLES20.glUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0); GLES20.glVertexAttribPointer(floorPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, floorVertices); GLES20.glVertexAttribPointer(floorNormalParam, 3, GLES20.GL_FLOAT, false, 0, floorNormals); GLES20.glVertexAttribPointer(floorColorParam, 4, GLES20.GL_FLOAT, false, 0, floorColors); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); checkGLError("drawing floor"); }