本文整理汇总了Java中android.opengl.GLES20.glUniform3f方法的典型用法代码示例。如果您正苦于以下问题:Java GLES20.glUniform3f方法的具体用法?Java GLES20.glUniform3f怎么用?Java GLES20.glUniform3f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.opengl.GLES20
的用法示例。
在下文中一共展示了GLES20.glUniform3f方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateFloatValue
import android.opengl.GLES20; //导入方法依赖的package包/类
private void updateFloatValue(float... value) {
switch (value.length) {
case 1:
GLES20.glUniform1f(handle(), value[0]);
break;
case 2:
GLES20.glUniform2f(handle(), value[0], value[1]);
break;
case 3:
GLES20.glUniform3f(handle(), value[0], value[1], value[2]);
break;
case 4:
GLES20.glUniform4f(handle(), value[0], value[1], value[2], value[3]);
break;
case 16:
GLES20.glUniformMatrix4fv(handle(), 1, false, value, 0);
default:
break;
}
}
示例2: drawCube
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube() {
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mCubeNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// 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);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例3: drawCube
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube()
{
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mCubeNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// 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);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例4: drawCustomParamsPass
import android.opengl.GLES20; //导入方法依赖的package包/类
private void drawCustomParamsPass() {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[1]);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[1], 0);
GLES20.glClear(0);
GLES20.glUseProgram(toolsShaderProgram);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[0]);
GLES20.glUniform1i(sourceImageHandle, 0);
if (showOriginal) {
GLES20.glUniform1f(shadowsHandle, 1);
GLES20.glUniform1f(highlightsHandle, 1);
GLES20.glUniform1f(exposureHandle, 0);
GLES20.glUniform1f(contrastHandle, 1);
GLES20.glUniform1f(saturationHandle, 1);
GLES20.glUniform1f(warmthHandle, 0);
GLES20.glUniform1f(vignetteHandle, 0);
GLES20.glUniform1f(grainHandle, 0);
GLES20.glUniform1f(fadeAmountHandle, 0);
GLES20.glUniform3f(highlightsTintColorHandle, 0, 0, 0);
GLES20.glUniform1f(highlightsTintIntensityHandle, 0);
GLES20.glUniform3f(shadowsTintColorHandle, 0, 0, 0);
GLES20.glUniform1f(shadowsTintIntensityHandle, 0);
GLES20.glUniform1f(skipToneHandle, 1);
} else {
GLES20.glUniform1f(shadowsHandle, getShadowsValue());
GLES20.glUniform1f(highlightsHandle, getHighlightsValue());
GLES20.glUniform1f(exposureHandle, getExposureValue());
GLES20.glUniform1f(contrastHandle, getContrastValue());
GLES20.glUniform1f(saturationHandle, getSaturationValue());
GLES20.glUniform1f(warmthHandle, getWarmthValue());
GLES20.glUniform1f(vignetteHandle, getVignetteValue());
GLES20.glUniform1f(grainHandle, getGrainValue());
GLES20.glUniform1f(fadeAmountHandle, getFadeValue());
GLES20.glUniform3f(highlightsTintColorHandle, (tintHighlightsColor >> 16 & 0xff) / 255.0f, (tintHighlightsColor >> 8 & 0xff) / 255.0f, (tintHighlightsColor & 0xff) / 255.0f);
GLES20.glUniform1f(highlightsTintIntensityHandle, getTintHighlightsIntensityValue());
GLES20.glUniform3f(shadowsTintColorHandle, (tintShadowsColor >> 16 & 0xff) / 255.0f, (tintShadowsColor >> 8 & 0xff) / 255.0f, (tintShadowsColor & 0xff) / 255.0f);
GLES20.glUniform1f(shadowsTintIntensityHandle, getTintShadowsIntensityValue());
boolean skipTone = curvesToolValue.shouldBeSkipped();
GLES20.glUniform1f(skipToneHandle, skipTone ? 1.0f : 0.0f);
if (!skipTone) {
curvesToolValue.fillBuffer();
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GL10.GL_TEXTURE_2D, curveTextures[0]);
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, 200, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, curvesToolValue.curveBuffer);
GLES20.glUniform1i(curvesImageHandle, 1);
}
}
GLES20.glUniform1f(widthHandle, renderBufferWidth);
GLES20.glUniform1f(heightHandle, renderBufferHeight);
GLES20.glEnableVertexAttribArray(inputTexCoordHandle);
GLES20.glVertexAttribPointer(inputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glVertexAttribPointer(positionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
示例5: draw
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
*
* 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");
}
示例6: drawCube
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube() {
// Pass in the position information.
mCubePositions.position(0);
GLES20.glVertexAttribPointer(
mPositionHandle,
mPositionDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubePositions
);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(
mColorHandle,
mColorDataSize,
GLES20.GL_FLOAT,
false,
0, mCubeColors
);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(
mNormalHandle,
mNormalDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubeNormals
);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// This multiplies the view matrix by the model matrix
// and stores the result the MVP matrix.
// which currently contains model * view.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the model view matrix
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the model view 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);
// Pass in the combined matrix
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例7: onDrawFrame
import android.opengl.GLES20; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Set our per-vertex lighting program.
GLES20.glUseProgram(program);
// Set program handles for cube drawing.
mvpMatrixUniform = GLES20.glGetUniformLocation(program, MVP_MATRIX_UNIFORM);
mvMatrixUniform = GLES20.glGetUniformLocation(program, MV_MATRIX_UNIFORM);
lightPosUniform = GLES20.glGetUniformLocation(program, LIGHT_POSITION_UNIFORM);
positionAttribute = GLES20.glGetAttribLocation(program, POSITION_ATTRIBUTE);
normalAttribute = GLES20.glGetAttribLocation(program, NORMAL_ATTRIBUTE);
colorAttribute = GLES20.glGetAttribLocation(program, COLOR_ATTRIBUTE);
// Calculate position of the light. Push into the distance.
Matrix.setIdentityM(lightModelMatrix, 0);
Matrix.translateM(lightModelMatrix, 0, 0.0f, 7.5f, -8.0f);
Matrix.multiplyMV(lightPosInWorldSpace, 0, lightModelMatrix, 0, lightPosInModelSpace, 0);
Matrix.multiplyMV(lightPosInEyeSpace, 0, viewMatrix, 0, lightPosInWorldSpace, 0);
// Draw the heightmap.
// Translate the heightmap into the screen.
Matrix.setIdentityM(modelMatrix, 0);
Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -12f);
// Set a matrix that contains the current rotation.
Matrix.setIdentityM(currentRotation, 0);
Matrix.rotateM(currentRotation, 0, deltaX, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(currentRotation, 0, deltaY, 1.0f, 0.0f, 0.0f);
deltaX = 0.0f;
deltaY = 0.0f;
// Multiply the current rotation by the accumulated rotation, and then
// set the accumulated rotation to the result.
Matrix.multiplyMM(temporaryMatrix, 0, currentRotation, 0, accumulatedRotation, 0);
System.arraycopy(temporaryMatrix, 0, accumulatedRotation, 0, 16);
// Rotate the cube taking the overall rotation into account.
Matrix.multiplyMM(temporaryMatrix, 0, modelMatrix, 0, accumulatedRotation, 0);
System.arraycopy(temporaryMatrix, 0, modelMatrix, 0, 16);
// This multiplies the view matrix by the model matrix, and stores
// the result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(mvpMatrix, 0, viewMatrix, 0, modelMatrix, 0);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mvMatrixUniform, 1, false, mvpMatrix, 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(temporaryMatrix, 0, projectionMatrix, 0, mvpMatrix, 0);
System.arraycopy(temporaryMatrix, 0, mvpMatrix, 0, 16);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mvpMatrixUniform, 1, false, mvpMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(lightPosUniform, lightPosInEyeSpace[0], lightPosInEyeSpace[1], lightPosInEyeSpace[2]);
// Render the heightmap.
heightMap.render();
}
示例8: drawCube
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube() {
// Pass in the position information.
mCubePositions.position(0);
GLES20.glVertexAttribPointer(
mPositionHandle,
mPositionDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubePositions
);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(
mColorHandle,
mColorDataSize,
GLES20.GL_FLOAT,
false,
0, mCubeColors
);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(
mNormalHandle,
mNormalDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubeNormals
);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// Pass in the texture coordinate information
mCubeTextureCoordinates.position(0);
GLES20.glVertexAttribPointer(
mTextureCoordinateHandle,
mTextureCoordinateDataSize,
GLES20.GL_FLOAT,
false,
0,
mCubeTextureCoordinates
);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
// This multiplies the view matrix by the model matrix
// and stores the result the MVP matrix.
// which currently contains model * view.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the model view matrix
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the model view 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);
// Pass in the combined matrix
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例9: onDrawFrame
import android.opengl.GLES20; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Set our per-vertex lighting program.
GLES20.glUseProgram(mProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
// Calculate position of the light. Push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -1.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// Draw a cube.
// Translate the cube into the screen.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.5f);
// Set a matrix that contains the current rotation.
Matrix.setIdentityM(mCurrentRotation, 0);
Matrix.rotateM(mCurrentRotation, 0, mDeltaX, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, mDeltaY, 1.0f, 0.0f, 0.0f);
mDeltaX = 0.0f;
mDeltaY = 0.0f;
// Multiply the current rotation by the accumulated rotation, and then set the accumulated rotation to the result.
Matrix.multiplyMM(mTemporaryMatrix, 0, mCurrentRotation, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mAccumulatedRotation, 0, 16);
// Rotate the cube taking the overall rotation into account.
Matrix.multiplyMM(mTemporaryMatrix, 0, mModelMatrix, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mModelMatrix, 0, 16);
// 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);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Pass in the texture information
// Set the active texture unit to texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);
// Tell the texture uniform sampler to use this texture in the
// shader by binding to texture unit 0.
GLES20.glUniform1i(mTextureUniformHandle, 0);
if (mCubes != null) {
mCubes.render();
}
}
示例10: drawCube
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube()
{
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
0, mCubeColors);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mCubeNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// 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);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例11: onDrawFrame
import android.opengl.GLES20; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Set our per-vertex lighting program.
GLES20.glUseProgram(program);
// Set program handles for cube drawing.
mvpMatrixUniform = GLES20.glGetUniformLocation(program, MVP_MATRIX_UNIFORM);
mvMatrixUniform = GLES20.glGetUniformLocation(program, MV_MATRIX_UNIFORM);
lightPosUniform = GLES20.glGetUniformLocation(program, LIGHT_POSITION_UNIFORM);
positionAttribute = GLES20.glGetAttribLocation(program, POSITION_ATTRIBUTE);
normalAttribute = GLES20.glGetAttribLocation(program, NORMAL_ATTRIBUTE);
colorAttribute = GLES20.glGetAttribLocation(program, COLOR_ATTRIBUTE);
// Calculate position of the light. Push into the distance.
Matrix.setIdentityM(lightModelMatrix, 0);
Matrix.translateM(lightModelMatrix, 0, 0.0f, 7.5f, -8.0f);
Matrix.multiplyMV(lightPosInWorldSpace, 0, lightModelMatrix, 0, lightPosInModelSpace, 0);
Matrix.multiplyMV(lightPosInEyeSpace, 0, viewMatrix, 0, lightPosInWorldSpace, 0);
// Draw the heightmap.
// Translate the heightmap into the screen.
Matrix.setIdentityM(modelMatrix, 0);
Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -12f);
// Set a matrix that contains the current rotation.
Matrix.setIdentityM(currentRotation, 0);
Matrix.rotateM(currentRotation, 0, deltaX, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(currentRotation, 0, deltaY, 1.0f, 0.0f, 0.0f);
deltaX = 0.0f;
deltaY = 0.0f;
// Multiply the current rotation by the accumulated rotation, and then
// set the accumulated rotation to the result.
Matrix.multiplyMM(temporaryMatrix, 0, currentRotation, 0, accumulatedRotation, 0);
System.arraycopy(temporaryMatrix, 0, accumulatedRotation, 0, 16);
// Rotate the cube taking the overall rotation into account.
Matrix.multiplyMM(temporaryMatrix, 0, modelMatrix, 0, accumulatedRotation, 0);
System.arraycopy(temporaryMatrix, 0, modelMatrix, 0, 16);
// This multiplies the view matrix by the model matrix, and stores
// the result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(mvpMatrix, 0, viewMatrix, 0, modelMatrix, 0);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mvMatrixUniform, 1, false, mvpMatrix, 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(temporaryMatrix, 0, projectionMatrix, 0, mvpMatrix, 0);
System.arraycopy(temporaryMatrix, 0, mvpMatrix, 0, 16);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mvpMatrixUniform, 1, false, mvpMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(lightPosUniform, lightPosInEyeSpace[0], lightPosInEyeSpace[1], lightPosInEyeSpace[2]);
// Render the heightmap.
heightMap.render();
}
示例12: drawCube
import android.opengl.GLES20; //导入方法依赖的package包/类
/**
* Draws a cube.
*/
private void drawCube()
{
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
0, mCubeColors);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mCubeNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// Pass in the texture coordinate information
mCubeTextureCoordinates.position(0);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false,
0, mCubeTextureCoordinates);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
// 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);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
示例13: onDrawFrame
import android.opengl.GLES20; //导入方法依赖的package包/类
@Override
public void onDrawFrame(GL10 glUnused)
{
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Set our per-vertex lighting program.
GLES20.glUseProgram(mProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
// Calculate position of the light. Push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -1.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// Draw a cube.
// Translate the cube into the screen.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.5f);
// Set a matrix that contains the current rotation.
Matrix.setIdentityM(mCurrentRotation, 0);
Matrix.rotateM(mCurrentRotation, 0, mDeltaX, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, mDeltaY, 1.0f, 0.0f, 0.0f);
mDeltaX = 0.0f;
mDeltaY = 0.0f;
// Multiply the current rotation by the accumulated rotation, and then set the accumulated rotation to the result.
Matrix.multiplyMM(mTemporaryMatrix, 0, mCurrentRotation, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mAccumulatedRotation, 0, 16);
// Rotate the cube taking the overall rotation into account.
Matrix.multiplyMM(mTemporaryMatrix, 0, mModelMatrix, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mModelMatrix, 0, 16);
// 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);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Pass in the texture information
// Set the active texture unit to texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);
// Tell the texture uniform sampler to use this texture in the
// shader by binding to texture unit 0.
GLES20.glUniform1i(mTextureUniformHandle, 0);
if (mCubes != null) {
mCubes.render();
}
}