Java Examples for android.opengl.GLES20.glViewport
The following java examples will help you to understand the usage of android.opengl.GLES20.glViewport. These source code samples are taken from different open source projects.
Example 1
| Project: FxCameraApp-master File: GlImageTexture.java View source code |
protected final void attachToTexture(final Bitmap bitmap) {
if (bitmap == null) {
throw new IllegalArgumentException("Bitmap must not be null");
}
if (bitmap.isRecycled()) {
throw new IllegalStateException("Bitmap is recycled");
}
final int[] saveFramebuffer = new int[1];
glGetIntegerv(GL_FRAMEBUFFER_BINDING, saveFramebuffer, 0);
final int[] saveViewport = new int[4];
glGetIntegerv(GL_VIEWPORT, saveViewport, 0);
final int[] saveTexName = new int[1];
glGetIntegerv(GL_TEXTURE_BINDING_2D, saveTexName, 0);
final GLES20FlipVerticalShader shader = new GLES20FlipVerticalShader();
final int[] textures = new int[1];
try {
glGenTextures(textures.length, textures, 0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
OpenGlUtils.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);
OpenGlUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
mFramebufferObject.setup(bitmap.getWidth(), bitmap.getHeight());
shader.setup();
shader.setFrameSize(mFramebufferObject.getWidth(), mFramebufferObject.getHeight());
mFramebufferObject.enable();
glViewport(0, 0, mFramebufferObject.getWidth(), mFramebufferObject.getHeight());
glClear(GL_COLOR_BUFFER_BIT);
shader.draw(textures[0], null);
} catch (final RuntimeException e) {
mFramebufferObject.release();
throw e;
} finally {
glDeleteTextures(textures.length, textures, 0);
shader.release();
glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer[0]);
glViewport(saveViewport[0], saveViewport[1], saveViewport[2], saveViewport[3]);
glBindTexture(GL_TEXTURE_2D, saveTexName[0]);
}
}Example 2
| Project: VirtualArt-master File: ImageRenderer.java View source code |
public void onSurfaceChanged(GL10 gl, int w, int h) {
glViewport(0, 0, w, h);
/*
* Set our projection matrix. This doesn't have to be done
* each time we draw, but usually a new projection needs to
* be set when the viewport is resized.
*/
float ratio = (float) w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustumf(-ratio, ratio, -1, 1, 3, 7);
}Example 3
| Project: AndroidOpenTextbook-master File: Chapter02_03.java View source code |
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
glViewport(0, 0, width, height);
}Example 4
| Project: GoogleCardboardPhotoSphere-VR--master File: MainActivity.java View source code |
@Override
public void onSurfaceChanged(int width, int height) {
glViewport(0, 0, width, height);
MatrixHelper.perspectiveM(mProjectionMatrix, 90, (float) width / (float) height, 1f, 10f);
Log.i(TAG, "onSurfaceChanged");
}Example 5
| Project: android-PageFlip-master File: PageFlip.java View source code |
/**
* Handle surface changing event
*
* @param width surface width
* @param height surface height
* @throws PageFlipException if failed to compile and link OpenGL shader
*/
public void onSurfaceChanged(int width, int height) throws PageFlipException {
mViewRect.set(width, height);
glViewport(0, 0, width, height);
mVertexProgram.initMatrix(-mViewRect.halfW, mViewRect.halfW, -mViewRect.halfH, mViewRect.halfH);
computeMaxMeshCount();
createPages();
}