Java Code Examples for android.opengl.Matrix#setLookAtM()
The following examples show how to use
android.opengl.Matrix#setLookAtM() .
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: Renderer.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
/** * Update the view matrix of the Renderer to follow the position of the * device in the current perspective. */ public void updateViewMatrix() { mDevicePosition = mModelMatCalculator.getTranslation(); switch (viewId) { case FIRST_PERSON: float[] invertModelMat = new float[MATRIX_4X4]; Matrix.setIdentityM(invertModelMat, 0); float[] temporaryMatrix = new float[MATRIX_4X4]; Matrix.setIdentityM(temporaryMatrix, 0); Matrix.setIdentityM(mViewMatrix, 0); Matrix.invertM(invertModelMat, 0, mModelMatCalculator.getModelMatrix(), 0); Matrix.multiplyMM(temporaryMatrix, 0, mViewMatrix, 0, invertModelMat, 0); System.arraycopy(temporaryMatrix, 0, mViewMatrix, 0, 16); break; case THIRD_PERSON: Matrix.setLookAtM(mViewMatrix, 0, mDevicePosition[0] + mCameraPosition[0], mCameraPosition[1] + mDevicePosition[1], mCameraPosition[2] + mDevicePosition[2], mDevicePosition[0], mDevicePosition[1], mDevicePosition[2], 0f, 1f, 0f); break; case TOP_DOWN: // Matrix.setIdentityM(mViewMatrix, 0); Matrix.setLookAtM(mViewMatrix, 0, mDevicePosition[0] + mCameraPosition[0], mCameraPosition[1], mCameraPosition[2] + mDevicePosition[2], mDevicePosition[0] + mCameraPosition[0], mCameraPosition[1] - 5, mCameraPosition[2] + mDevicePosition[2], 0f, 0f, -1f); break; default: viewId = THIRD_PERSON; return; } }
Example 2
Source File: HyperspaceScreen.java From Alite with GNU General Public License v3.0 | 5 votes |
private static void lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) { float[] scratch = sScratch; Matrix.setLookAtM(scratch, 0, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); GLES11.glMultMatrixf(scratch, 0); }
Example 3
Source File: MyGLRenderer.java From opengl with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame(GL10 unused) { float[] scratch = new float[16]; // Draw background color GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // Set the camera position (View matrix) Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); // Draw square mSquare.draw(mMVPMatrix); // Create a rotation for the triangle // Use the following code to generate constant rotation. // Leave this code out when using TouchEvents. // long time = SystemClock.uptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, 1.0f); // Combine the rotation matrix with the projection and camera view // Note that the mMVPMatrix factor *must be first* in order // for the matrix multiplication product to be correct. Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0); // Draw triangle mTriangle.draw(scratch); }
Example 4
Source File: MainActivity.java From AndroidPlayground with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 unused, int width, int height) { mWidth = width; mHeight = height; mProgram = GLES20.glCreateProgram(); int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER); int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER); GLES20.glAttachShader(mProgram, vertexShader); GLES20.glAttachShader(mProgram, fragmentShader); GLES20.glLinkProgram(mProgram); mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); mTexCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_texCoord"); mMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); mTexSamplerHandle = GLES20.glGetUniformLocation(mProgram, "s_texture"); mTexNames = new int[1]; GLES20.glGenTextures(1, mTexNames, 0); Bitmap bitmap = BitmapFactory.decodeResource(mResources, R.drawable.p_300px); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexNames[0]); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); bitmap.recycle(); float ratio = (float) height / width; Matrix.frustumM(mProjectionMatrix, 0, -1, 1, -ratio, ratio, 3, 7); Matrix.setLookAtM(mCameraMatrix, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mCameraMatrix, 0); }
Example 5
Source File: RendererContext.java From Tanks with MIT License | 5 votes |
public void setCamera(Camera.Data value) { float eyeX = value.eye.getX(); float eyeY = value.eye.getY(); float eyeZ = value.eye.getZ(); float targetX = value.target.getX(); float targetY = value.target.getY(); float targetZ = value.target.getZ(); Matrix.setLookAtM(viewMatrix, 0, eyeX, eyeY, eyeZ, targetX, targetY, targetZ, 0.0f, 0.0f, 1.0f); Matrix.perspectiveM(projectionMatrix, 0, 60.0f, Renderer.getAspect(), 0.1f, 200.0f); Matrix.multiplyMM(projectionViewMatrix, 0, projectionMatrix, 0, viewMatrix, 0); }
Example 6
Source File: ShapeRenderer.java From ShapesInOpenGLES2.0 with MIT License | 5 votes |
@Override public void onSurfaceCreated(GL10 glUnused, javax.microedition.khronos.egl.EGLConfig config) { aTexture = TextureHelper.loadTexture(aShapeActivity, R.drawable.stone_wall_public_domain , false); generatePlots(aShapeNumber); // Set the background clear color to black. GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Use culling to remove back faces. GLES20.glEnable(GLES20.GL_CULL_FACE); // Enable depth testing GLES20.glEnable(GLES20.GL_DEPTH_TEST); // Position the eye in front of the origin. final float eyeX = 0.0f; final float eyeY = 0.0f; final float eyeZ = -0.0f; // We are looking toward the distance final float lookX = 0.0f; final float lookY = 0.0f; final float lookZ = -5.0f; // Set our up vector. This is where our head would be pointing were we holding the camera. final float upX = 0.0f; final float upY = 1.0f; final float upZ = 0.0f; // Set the view matrix. This matrix can be said to represent the camera position. // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose. Matrix.setLookAtM(aViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); //aAndroidDataHandle = a[0]; // Initialize the accumulated rotation matrix Matrix.setIdentityM(aAccumulatedRotation, 0); }
Example 7
Source File: MainActivity.java From Android-9-Development-Cookbook with MIT License | 5 votes |
public void onDrawFrame(GL10 unused) { Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); float[] tempMatrix = new float[16]; long time = SystemClock.uptimeMillis() % 4000L; float angle = 0.090f * ((int) time); Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, -1.0f); Matrix.multiplyMM(tempMatrix, 0, mMVPMatrix, 0, mRotationMatrix, 0); mTriangle.draw(tempMatrix); }
Example 8
Source File: myRenderer.java From opengl with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame(GL10 glUnused) { // Clear the color buffer set above by glClearColor. GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT); //need this otherwise, it will over right stuff and the cube will look wrong! GLES30.glEnable(GLES30.GL_DEPTH_TEST); // Set the camera position (View matrix) note Matrix is an include, not a declared method. Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // Create a rotation and translation for the cube Matrix.setIdentityM(mRotationMatrix, 0); //move the cube up/down and left/right Matrix.translateM(mRotationMatrix, 0, mTransX, mTransY, 0); //mangle is how fast, x,y,z which directions it rotates. Matrix.rotateM(mRotationMatrix, 0, mAngle, 0.4f, 1.0f, 0.6f); // combine the model with the view matrix Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mRotationMatrix, 0); // combine the model-view with the projection matrix Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); mPyramid.draw(mMVPMatrix); //change the angle, so the cube will spin. mAngle+=.4; }
Example 9
Source File: MyGLRenderer.java From opengl with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame(GL10 unused) { float[] scratch = new float[16]; // Draw background color GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT); // Set the camera position (View matrix) Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); // Draw square mSquare.draw(mMVPMatrix); // Create a rotation for the triangle // Use the following code to generate constant rotation. // Leave this code out when using TouchEvents. // long time = SystemClock.uptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, 1.0f); // Combine the rotation matrix with the projection and camera view // Note that the mMVPMatrix factor *must be first* in order // for the matrix multiplication product to be correct. Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0); // Draw triangle mTriangle.draw(scratch); }
Example 10
Source File: OpenglActivity.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame(GL10 gl) { final long actionTime = System.currentTimeMillis(); // Log.w("ceshi", "onDrawFrame==="); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);// 清除屏幕和深度缓存 float[] mtx = new float[16]; mSurface.getTransformMatrix(mtx); mCameraMatrix.draw(mtx); // Set the camera position (View matrix) Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1f, 0f); // Calculate the projection and view transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); mPointsMatrix.draw(mMVPMatrix); if (isDebug) { runOnUiThread(new Runnable() { @Override public void run() { final long endTime = System.currentTimeMillis() - actionTime; debugPrinttext.setText("printTime: " + endTime); } }); } mSurface.updateTexImage();// 更新image,会调用onFrameAvailable方法 if (isStartRecorder) { flip = !flip; if (flip) { // ~30fps synchronized (this) { // mMediaHelper.frameAvailable(mtx); mMediaHelper.frameAvailable(mtx); } } } }
Example 11
Source File: SphereReflector.java From In77Camera with MIT License | 5 votes |
private void initMatrix() { Matrix.setIdentityM(modelMatrix,0); Matrix.rotateM(modelMatrix,0,90.0f,0f,1f,0f); Matrix.setIdentityM(projectionMatrix,0); Matrix.setIdentityM(viewMatrix, 0); Matrix.setLookAtM(viewMatrix, 0, 0f,10f,10f, 0.0f, 0.0f,-1.0f, 0.0f, 1.0f, 0.0f); }
Example 12
Source File: GLDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 4 votes |
@Override public void onDrawFrame(GL10 unused) { angle = ((float) SystemClock.elapsedRealtime() - startTime) * 0.02f; 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, -4, 0f, 0f, 0f, 0f, 1.0f, 0.0f); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); Matrix.rotateM(mMVPMatrix, 0, angle, 1.f, 1.f, 1.f); GLES20.glUseProgram(shaderProgram); int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition"); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer); int texCoordHandle = GLES20.glGetAttribLocation(shaderProgram, "aTex"); GLES20.glVertexAttribPointer(texCoordHandle, 2, GLES20.GL_FLOAT, false, 0, texBuffer); int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix"); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); int texHandle = GLES20.glGetUniformLocation(shaderProgram, "sTex"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glUniform1i(texHandle, 0); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnableVertexAttribArray(texHandle); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glDrawElements( GLES20.GL_TRIANGLES, index.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer); GLES20.glDisableVertexAttribArray(positionHandle); GLES20.glDisableVertexAttribArray(texHandle); GLES20.glDisable(GLES20.GL_DEPTH_TEST); }
Example 13
Source File: CN1Matrix4f.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void setCamera(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) { Matrix.setLookAtM(data, 0, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); type = TYPE_UNKNOWN; }
Example 14
Source File: GlSceneRenderer.java From ParticlesDrawable with Apache License 2.0 | 4 votes |
public void setDimensions(final int width, final int height) { GLES20.glViewport(0, 0, width, height); Arrays.fill(projectionMatrix, 0); Arrays.fill(mvpSourceMatrix, 0); Matrix.orthoM(projectionMatrix, 0, 0f, width, 0f, height, 1, -1); Matrix.setLookAtM(viewMatrix, 0, 0f, 0f, 0f, 0f, 0f, -1f, 0f, 1f, 0f); Matrix.multiplyMM(mvpSourceMatrix, 0, projectionMatrix, 0, viewMatrix, 0); System.arraycopy(mvpSourceMatrix, 0, mvpTranslatedBackgroundMatrix, 0, mvpSourceMatrix.length); System.arraycopy(mvpSourceMatrix, 0, mvpTranslatedForegroundMatrix, 0, mvpSourceMatrix.length); Matrix.translateM(mvpTranslatedBackgroundMatrix, 0, mvpSourceMatrix, 0, backgroundTranslationX, 0, 0); Matrix.translateM(mvpTranslatedForegroundMatrix, 0, mvpSourceMatrix, 0, foregroundTranslationX, 0, 0); background.setDimensions(width, height); }
Example 15
Source File: PreviewShader.java From retroboy with MIT License | 4 votes |
/** * @param program Shader program built from SHADER_SOURCE_ID * @param size Size of camera preview frames */ public PreviewShader(ShaderProgram program, Camera.Size previewSize, int surfaceWidth, int surfaceHeight) { _program = program; _cRatio = (float)previewSize.width / previewSize.height; // Allocate buffer to hold vertices _vertexbuf = ByteBuffer.allocateDirect(_vertices.length * FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer(); _vertexbuf.put(_vertices).position(0); // Find handles to shader parameters maPositionHandle = _program.getAttributeLocation("aPosition"); maTextureCoordHandle = _program.getAttributeLocation("aTextureCoord"); muMVPMatrixHandle = _program.getUniformLocation("uMVPMatrix"); muSTMatrixHandle = _program.getUniformLocation("uSTMatrix"); muCRatioHandle = _program.getUniformLocation("uCRatio"); _previewTextureLocation = _program.getUniformLocation("sTexture"); // Create the external texture which the camera preview is written to int[] textures = new int[1]; GLES20.glGenTextures(textures.length, textures, 0); _previewTextureHandle = textures[0]; _previewTexture = new SurfaceTexture(_previewTextureHandle); _previewTexture.setOnFrameAvailableListener(this); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, _previewTextureHandle); checkGlError("glBindTexture"); // No mip-mapping with camera source GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); // Clamp to edge is only option GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); /* Bitmap bm = BitmapFactory.decodeResource(_context.getResources(), R.raw.david); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bm, 0); */ // Set the viewpoint Matrix.setLookAtM(mVMatrix, 0, 0, 0, 1.45f, 0f, 0f, 0f, 0f, 1.0f, 0.0f); Matrix.setIdentityM(mSTMatrix, 0); // Set the screen ratio projection float ratio = (float)surfaceWidth / surfaceHeight; Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 1f, 10); // Apply the screen ratio projection Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); }
Example 16
Source File: AccelerometerGLRenderer.java From secureit with MIT License | 4 votes |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { // Set the background clear color to black. GLES20.glClearColor(0.906f, 0.906f, 0.906f, 1.0f); // Use culling to remove back faces. GLES20.glEnable(GLES20.GL_CULL_FACE); // Enable depth testing GLES20.glEnable(GLES20.GL_DEPTH_TEST); // The below glEnable() call is a holdover from OpenGL ES 1, and is not needed in OpenGL ES 2. // Enable texture mapping // GLES20.glEnable(GLES20.GL_TEXTURE_2D); // Position the eye in front of the origin. final float eyeX = 0.0f; final float eyeY = 0.0f; final float eyeZ = -0.5f; // We are looking toward the distance final float lookX = 0.0f; final float lookY = 0.0f; final float lookZ = -5.0f; // Set our up vector. This is where our head would be pointing were we holding the camera. final float upX = 0.0f; final float upY = 1.0f; final float upZ = 0.0f; // Set the view matrix. This matrix can be said to represent the camera position. // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose. Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); final String vertexShader = getVertexShader(); final String fragmentShader = getFragmentShader(); final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader); final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader); mProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, new String[] {"a_Position", "a_Color", "a_Normal", "a_TexCoordinate"}); // Define a simple shader program for our point. final String pointVertexShader = RawResourceReader.readTextFileFromRawResource(mActivityContext, R.raw.per_pixel_vertex_shader); final String pointFragmentShader = RawResourceReader.readTextFileFromRawResource(mActivityContext, R.raw.per_pixel_fragment_shader); final int pointVertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, pointVertexShader); final int pointFragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, pointFragmentShader); mPointProgramHandle = ShaderHelper.createAndLinkProgram(pointVertexShaderHandle, pointFragmentShaderHandle, new String[] {"a_Position"}); // Load the texture mTextureDataHandle = TextureHelper.loadTexture(mActivityContext, R.drawable.fronttx); }
Example 17
Source File: GPUPlayerRenderer.java From GPUVideo-android with MIT License | 4 votes |
@Override public void onSurfaceCreated(final EGLConfig config) { GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); final int[] args = new int[1]; GLES20.glGenTextures(args.length, args, 0); texName = args[0]; previewTexture = new GlSurfaceTexture(texName); previewTexture.setOnFrameAvailableListener(this); GLES20.glBindTexture(previewTexture.getTextureTarget(), texName); // GL_TEXTURE_EXTERNAL_OES EglUtil.setupSampler(previewTexture.getTextureTarget(), GL_LINEAR, GL_NEAREST); GLES20.glBindTexture(GL_TEXTURE_2D, 0); filterFramebufferObject = new GlFramebufferObject(); // GL_TEXTURE_EXTERNAL_OES previewFilter = new GlPreviewFilter(previewTexture.getTextureTarget()); previewFilter.setup(); Surface surface = new Surface(previewTexture.getSurfaceTexture()); this.simpleExoPlayer.setVideoSurface(surface); Matrix.setLookAtM(VMatrix, 0, 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f ); synchronized (this) { updateSurface = false; } if (glFilter != null) { isNewFilter = true; } GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0); }
Example 18
Source File: OpenGLWatchFaceService.java From wear-os-samples with Apache License 2.0 | 4 votes |
@Override public void onGlContextCreated() { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onGlContextCreated"); } super.onGlContextCreated(); // Create program for drawing triangles. Gles2ColoredTriangleList.Program triangleProgram = new Gles2ColoredTriangleList.Program(); // We only draw triangles which all use the same program so we don't need to switch // programs mid-frame. This means we can tell OpenGL to use this program only once // rather than having to do so for each frame. This makes OpenGL draw faster. triangleProgram.use(); // Create triangles for the ticks. mMajorTickTriangles = createMajorTicks(triangleProgram); mMinorTickTriangles = createMinorTicks(triangleProgram); // Create triangles for the hands. mSecondHandTriangle = createHand( triangleProgram, 0.02f /* width */, 1.0f /* height */, new float[]{ 1.0f /* red */, 0.0f /* green */, 0.0f /* blue */, 1.0f /* alpha */ } ); mMinuteHandTriangle = createHand( triangleProgram, 0.06f /* width */, 1f /* height */, new float[]{ 0.7f /* red */, 0.7f /* green */, 0.7f /* blue */, 1.0f /* alpha */ } ); mHourHandTriangle = createHand( triangleProgram, 0.1f /* width */, 0.6f /* height */, new float[]{ 0.9f /* red */, 0.9f /* green */, 0.9f /* blue */, 1.0f /* alpha */ } ); // Precompute the clock angles. for (int i = 0; i < mModelMatrices.length; ++i) { Matrix.setRotateM(mModelMatrices[i], 0, i, 0, 0, 1); } // Precompute the camera angles. for (int i = 0; i < mNumCameraAngles; ++i) { // Set the camera position (View matrix). When active, move the eye around to show // off that this is 3D. final float cameraAngle = (float) (((float) i) / mNumCameraAngles * 2 * Math.PI); final float eyeX = (float) Math.cos(cameraAngle); final float eyeY = (float) Math.sin(cameraAngle); Matrix.setLookAtM(mViewMatrices[i], 0, // dest index eyeX, eyeY, EYE_Z, // eye 0, 0, 0, // center 0, 1, 0); // up vector } Matrix.setLookAtM(mAmbientViewMatrix, 0, // dest index 0, 0, EYE_Z, // eye 0, 0, 0, // center 0, 1, 0); // up vector }
Example 19
Source File: StarWarsRenderer.java From StarWars.Android with MIT License | 4 votes |
@Override public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) { GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // Use culling to remove back faces. GLES20.glEnable(GLES20.GL_CULL_FACE); GLES20.glFrontFace(GLES20.GL_CW); // Enable depth testing GLES20.glEnable(GLES20.GL_DEPTH_TEST); // Position the eye in front of the origin. final float eyeX = 0.0f; final float eyeY = 0.0f; final float eyeZ = 0.0f; // We are looking toward the distance final float lookX = 0.0f; final float lookY = 0.0f; final float lookZ = 1.0f; // Set our up vector. This is where our head would be pointing were we holding the camera. final float upX = 0.0f; final float upY = 1.0f; final float upZ = 0.0f; Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); final String vertexShader = RawResourceReader.readTextFileFromRawResource(mGlSurfaceView.getContext(), R.raw.tiles_vert); final String fragmentShader = RawResourceReader.readTextFileFromRawResource(mGlSurfaceView.getContext(), R.raw.tiles_frag); final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader); final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader); programHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, new String[]{"a_Position", "a_Normal", "a_TexCoordinate"}); // Initialize the accumulated rotation matrix Matrix.setIdentityM(mAccumulatedRotation, 0); }
Example 20
Source File: GLES20TriangleRenderer.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { // Ignore the passed-in GL10 interface, and use the GLES20 // class's static methods instead. mProgram = createProgram(mVertexShader, mFragmentShader); if (mProgram == 0) { return; } maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition"); checkGlError("glGetAttribLocation aPosition"); if (maPositionHandle == -1) { throw new RuntimeException("Could not get attrib location for aPosition"); } maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord"); checkGlError("glGetAttribLocation aTextureCoord"); if (maTextureHandle == -1) { throw new RuntimeException("Could not get attrib location for aTextureCoord"); } muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); checkGlError("glGetUniformLocation uMVPMatrix"); if (muMVPMatrixHandle == -1) { throw new RuntimeException("Could not get attrib location for uMVPMatrix"); } /* * Create our texture. This has to be done each time the * surface is created. */ int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); mTextureID = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); InputStream is = mContext.getResources() .openRawResource(R.raw.robot); Bitmap bitmap; try { bitmap = BitmapFactory.decodeStream(is); } finally { try { is.close(); } catch(IOException e) { // Ignore. } } GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); bitmap.recycle(); Matrix.setLookAtM(mVMatrix, 0, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); }