Java Code Examples for android.opengl.GLES20#glViewport()
The following examples show how to use
android.opengl.GLES20#glViewport() .
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: GLRender.java From In77Camera with MIT License | 6 votes |
@Override public void onSurfaceChanged(GL10 glUnused, int width, int height) { Log.d(TAG, "onSurfaceChanged: "+width+" "+height); this.surfaceWidth=width; this.surfaceHeight=height; GLES20.glViewport(0,0,width,height); filterGroup.onFilterChanged(width,height); fbo=FBO.newInstance().create(surfaceWidth,surfaceHeight); if(cameraEngine.isCameraOpened()){ cameraEngine.stopPreview(); cameraEngine.releaseCamera(); } cameraEngine.setTexture(oesFilter.getGlOESTexture().getTextureId()); cameraEngine.openCamera(isCameraFacingFront); cameraEngine.startPreview(); }
Example 2
Source File: LessonOneRenderer.java From opengl with Apache License 2.0 | 6 votes |
@Override public void onSurfaceChanged(GL10 glUnused, int width, int height) { // Set the OpenGL viewport to the same size as the surface. GLES20.glViewport(0, 0, width, height); // Create a new perspective projection matrix. The height will stay the same // while the width will vary as per aspect ratio. final float ratio = (float) width / height; final float left = -ratio; final float right = ratio; final float bottom = -1.0f; final float top = 1.0f; final float near = 1.0f; final float far = 10.0f; Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far); }
Example 3
Source File: VideoTextureRenderer.java From AndroidOpenGLVideoDemo with Apache License 2.0 | 6 votes |
private void adjustViewport() { float surfaceAspect = height / (float)width; float videoAspect = videoHeight / (float)videoWidth; if (surfaceAspect > videoAspect) { float heightRatio = height / (float)videoHeight; int newWidth = (int)(width * heightRatio); int xOffset = (newWidth - width) / 2; GLES20.glViewport(-xOffset, 0, newWidth, height); } else { float widthRatio = width / (float)videoWidth; int newHeight = (int)(height * widthRatio); int yOffset = (newHeight - height) / 2; GLES20.glViewport(0, -yOffset, width, newHeight); } adjustViewport = false; }
Example 4
Source File: OESFilter.java From Fatigue-Detection with MIT License | 5 votes |
@Override public void onDrawFrame(int textureId) { onPreDrawElements(); TextureUtils.bindTextureOES(textureId, GLES20.GL_TEXTURE0,glOESProgram.getUTextureSamplerHandle(),0); GLES20.glViewport(0,0,surfaceWidth,surfaceHeight); plane.draw(); }
Example 5
Source File: RenderTexture.java From tilt-game-android with MIT License | 5 votes |
/** * @see {@link #end(GLState)}, * {@link #end(GLState, boolean, boolean}}. */ public void begin(final GLState pGLState, final boolean pFlipX, final boolean pFlipY) { this.savePreviousViewport(); GLES20.glViewport(0, 0, this.mWidth, this.mHeight); pGLState.pushProjectionGLMatrix(); final float left; final float right; final float bottom; final float top; if (pFlipX) { left = this.mWidth; right = 0; } else { left = 0; right = this.mWidth; } if (pFlipY) { top = 0; bottom = this.mHeight; } else { top = this.mHeight; bottom = 0; } pGLState.orthoProjectionGLMatrixf(left, right, bottom, top, -1, 1); this.savePreviousFramebufferObjectID(pGLState); pGLState.bindFramebuffer(this.mFramebufferObjectID); pGLState.pushModelViewGLMatrix(); pGLState.loadModelViewGLMatrixIdentity(); }
Example 6
Source File: CameraGLRendererBase.java From OpenCvFaceDetect with Apache License 2.0 | 5 votes |
private void drawTex(int tex, boolean isOES, int fbo) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo); if(fbo == 0) GLES20.glViewport(0, 0, mView.getWidth(), mView.getHeight()); else GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if(isOES) { GLES20.glUseProgram(progOES); GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTCOES, 2, GLES20.GL_FLOAT, false, 4*2, texOES); } else { GLES20.glUseProgram(prog2D); GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTC2D, 2, GLES20.GL_FLOAT, false, 4*2, tex2D); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if(isOES) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 7
Source File: WaterMarkFilter.java From SimpleVideoEditor with Apache License 2.0 | 5 votes |
@Override protected void onPostDraw() { super.onPostDraw(); GLES20.glDisable(GLES20.GL_BLEND); // reset view port to origin. GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); }
Example 8
Source File: CameraGLRendererBase.java From SimpleDocumentScanner-Android with MIT License | 5 votes |
private void drawTex(int tex, boolean isOES, int fbo) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo); if(fbo == 0) GLES20.glViewport(0, 0, mView.getWidth(), mView.getHeight()); else GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if(isOES) { GLES20.glUseProgram(progOES); GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTCOES, 2, GLES20.GL_FLOAT, false, 4*2, texOES); } else { GLES20.glUseProgram(prog2D); GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTC2D, 2, GLES20.GL_FLOAT, false, 4*2, tex2D); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if(isOES) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 9
Source File: MxFaceBeautyFilter.java From In77Camera with MIT License | 5 votes |
@Override public void onDrawFrame(int textureId) { onPreDrawElements(); setUniform1f(glSimpleProgram.getProgramId(),"stepSizeX",1.0f/surfaceWidth); setUniform1f(glSimpleProgram.getProgramId(),"stepSizeY",1.0f/surfaceHeight); TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSimpleProgram.getTextureSamplerHandle(),0); GLES20.glViewport(0,0,surfaceWidth,surfaceHeight); plane.draw(); }
Example 10
Source File: RenderBuffer.java From MusicVisualization with Apache License 2.0 | 5 votes |
public void bind() { GLES20.glViewport(0, 0, width, height); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texId, 0); GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderBufferId); }
Example 11
Source File: PCRenderer.java From tango with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { GLES20.glViewport(0, 0, width, height); mCameraAspect = (float) width / height; Matrix.perspectiveM(mProjectionMatrix, 0, CAMERA_FOV, mCameraAspect, CAMERA_NEAR, CAMERA_FAR); }
Example 12
Source File: CameraGLRendererBase.java From OpenCV-android with Apache License 2.0 | 5 votes |
private void drawTex(int tex, boolean isOES, int fbo) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo); if(fbo == 0) GLES20.glViewport(0, 0, mView.getWidth(), mView.getHeight()); else GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if(isOES) { GLES20.glUseProgram(progOES); GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTCOES, 2, GLES20.GL_FLOAT, false, 4*2, texOES); } else { GLES20.glUseProgram(prog2D); GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert); GLES20.glVertexAttribPointer(vTC2D, 2, GLES20.GL_FLOAT, false, 4*2, tex2D); } GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if(isOES) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0); } GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 13
Source File: TextureRenderer.java From PhotoEditor with MIT License | 5 votes |
void renderTexture(int texId) { // Bind default FBO GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); // Use our shader program GLES20.glUseProgram(mProgram); GLToolbox.checkGlError("glUseProgram"); // Set viewport GLES20.glViewport(0, 0, mViewWidth, mViewHeight); GLToolbox.checkGlError("glViewport"); // Disable blending GLES20.glDisable(GLES20.GL_BLEND); // Set the vertex attributes GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTexVertices); GLES20.glEnableVertexAttribArray(mTexCoordHandle); GLES20.glVertexAttribPointer(mPosCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mPosVertices); GLES20.glEnableVertexAttribArray(mPosCoordHandle); GLToolbox.checkGlError("vertex attribute setup"); // Set the input texture GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLToolbox.checkGlError("glActiveTexture"); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId); GLToolbox.checkGlError("glBindTexture"); GLES20.glUniform1i(mTexSamplerHandle, 0); // Draw GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); }
Example 14
Source File: Game.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { GLES20.glViewport(0, 0, width, height); //GLog.i("viewport: %d %d",width, height ); Game.width(width); Game.height(height); setNeedSceneRestart(true); }
Example 15
Source File: Painting.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public PaintingData getPaintingData(RectF rect, boolean undo) { int minX = (int) rect.left; int minY = (int) rect.top; int width = (int) rect.width(); int height = (int) rect.height(); GLES20.glGenFramebuffers(1, buffers, 0); int framebuffer = buffers[0]; GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer); GLES20.glGenTextures(1, buffers, 0); int texture = buffers[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture); 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, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture, 0); GLES20.glViewport(0, 0, (int) size.width, (int) size.height); if (shaders == null) { return null; } Shader shader = shaders.get(undo ? "nonPremultipliedBlit" : "blit"); if (shader == null) { return null; } GLES20.glUseProgram(shader.program); Matrix translate = new Matrix(); translate.preTranslate(-minX, -minY); float effective[] = GLMatrix.LoadGraphicsMatrix(translate); float finalProjection[] = GLMatrix.MultiplyMat4f(projection, effective); GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(finalProjection)); if (undo) { GLES20.glUniform1i(shader.getUniform("texture"), 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture()); } else { GLES20.glUniform1i(shader.getUniform("texture"), 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, bitmapTexture.texture()); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture()); } GLES20.glClearColor(0, 0, 0, 0); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer); GLES20.glEnableVertexAttribArray(0); GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 8, textureBuffer); GLES20.glEnableVertexAttribArray(1); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); dataBuffer.limit(width * height * 4); GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, dataBuffer); PaintingData data; if (undo) { data = new PaintingData(null, dataBuffer); } else { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(dataBuffer); data = new PaintingData(bitmap, null); } buffers[0] = framebuffer; GLES20.glDeleteFramebuffers(1, buffers, 0); buffers[0] = texture; GLES20.glDeleteTextures(1, buffers, 0); return data; }
Example 16
Source File: GLSurfaceMovieRenderer.java From PhotoMovie with Apache License 2.0 | 4 votes |
public void setViewport(int width, int height) { GLES20.glViewport(0, 0, width, height); mPainter.setSize(width, height); setMovieViewport(0, 0, width, height); }
Example 17
Source File: ColorFade.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private boolean captureScreenshotTextureAndSetViewport() { if (!attachEglContext()) { return false; } try { if (!mTexNamesGenerated) { GLES20.glGenTextures(1, mTexNames, 0); if (checkGlErrors("glGenTextures")) { return false; } mTexNamesGenerated = true; } final SurfaceTexture st = new SurfaceTexture(mTexNames[0]); final Surface s = new Surface(st); try { SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay( SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s); st.updateTexImage(); st.getTransformMatrix(mTexMatrix); } finally { s.release(); st.release(); } // Set up texture coordinates for a quad. // We might need to change this if the texture ends up being // a different size from the display for some reason. mTexCoordBuffer.put(0, 0f); mTexCoordBuffer.put(1, 0f); mTexCoordBuffer.put(2, 0f); mTexCoordBuffer.put(3, 1f); mTexCoordBuffer.put(4, 1f); mTexCoordBuffer.put(5, 1f); mTexCoordBuffer.put(6, 1f); mTexCoordBuffer.put(7, 0f); // Set up our viewport. GLES20.glViewport(0, 0, mDisplayWidth, mDisplayHeight); ortho(0, mDisplayWidth, 0, mDisplayHeight, -1, 1); } finally { detachEglContext(); } return true; }
Example 18
Source File: GlRectDrawer.java From sealrtc-android with MIT License | 4 votes |
private void drawRectangle(int x, int y, int width, int height) { // Draw quad. GLES20.glViewport(x, y, width, height); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); }
Example 19
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 4 votes |
@Override public void onDrawFrame(GL10 gl) { if (surfaceTexture == null) return; GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); surfaceTexture.updateTexImage(); float matrix[] = new float[16]; surfaceTexture.getTransformMatrix(matrix); // camTextureId->fboTexureId GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo[0]); GLES20.glViewport(0, 0, textureWidth, textureHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(progCam2FBO); GLES20.glVertexAttribPointer(vcCam2FBO, 2, GLES20.GL_FLOAT, false, 4 * 2, vertexCoordsBuffer); textureCoordsBuffer.clear(); textureCoordsBuffer.put(transformTextureCoordinates(textureCoords, matrix)); textureCoordsBuffer.position(0); GLES20.glVertexAttribPointer(tcCam2FBO, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoordsBuffer); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, camTextureId[0]); GLES20.glUniform1i(GLES20.glGetUniformLocation(progCam2FBO, "sTexture"), 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); // Check if the draw texture is set int targetTexureId = fboTexureId[0]; if (onTextureChangedListener != null) { boolean modified = onTextureChangedListener.onTextureChanged(fboTexureId[0], drawTexureId[0], textureWidth, textureHeight); if (modified) { targetTexureId = drawTexureId[0]; } } // fboTexureId/drawTexureId->Screen GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(progTex2Screen); GLES20.glVertexAttribPointer(vcTex2Screen, 2, GLES20.GL_FLOAT, false, 4 * 2, vertexCoordsBuffer); textureCoordsBuffer.clear(); textureCoordsBuffer.put(textureCoords); textureCoordsBuffer.position(0); GLES20.glVertexAttribPointer(tcTex2Screen, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoordsBuffer); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, targetTexureId); GLES20.glUniform1i(GLES20.glGetUniformLocation(progTex2Screen, "sTexture"), 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLES20.glFlush(); }
Example 20
Source File: TwoPassFilter.java From AndroidFastImageProcessing with MIT License | votes |
@Override protected void drawFrame() { currentPass = 1; if(firstPassFrameBuffer == null) { if(getWidth() != 0 && getHeight() != 0) { initFBO(); } else { return; } } GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, firstPassFrameBuffer[0]); if(texture_in == 0) { return; } GLES20.glViewport(0, 0, getWidth(), getHeight()); GLES20.glUseProgram(programHandle); GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); GLES20.glClearColor(getBackgroundRed(), getBackgroundGreen(), getBackgroundBlue(), getBackgroundAlpha()); passShaderValues(); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); texture_in = firstPassTextureOut[0]; GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); currentPass = 2; super.drawFrame(); }