Graphics Programs Reference
In-Depth Information
Note We used the glClear method in almost all applications so
far, but the argument we usually passed (like, in GL SURFACE
application) was different from what we discussed in this topic.
This was done intentionally, so you get into the habit of using
the code snippet shown in Listing 3-7 ; there would be no change
in
the
output
if
we
removed
the
extra
part
( |
GLES20.GL_DEPTH_BUFFER_BIT ) from the argument.
Listing 3-7. GL SURFACE CHANGED/src/com/apress/android/glsur-
facechanged/GLES20Renderer.java
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT |
GLES20.GL_DEPTH_BUFFER_BIT);
Setting the Viewport
When the display device accesses “front” color buffer to display a final image of the
graphics rendered using OpenGL ES, it needs to know about the viewport - that is,
the area on the display screen on which this image is to be mapped.
We set the viewport using the glViewport(int x, int y, int width,
int height) method, where (x, y) is a position on the display screen, meas-
ured from its bottom-left corner (in pixels). The rest of the arguments are for setting
the size of viewport in pixels. To ensure the viewport is visible, (x, y) should lie
within the bottom-left (x=0, y=0) and top-right (x=width, y=height) corners of the
display screen.
We typically want the viewport to be the same size as the display screen ( Figure 3-4 ) .
So, while setting the size of the viewport, we make use of the int width and int
height arguments of the onSurfaceChanged method. These arguments store
the width and height of the display screen in any orientation. For this reason, we
need to call the glViewport method inside the onSurfaceChanged method.
Whenever the orientation of the device changes, the onSurfaceChanged method
helps keep track of the new width and height of the display screen in landscape or
portrait orientations.
 
 
 
Search WWH ::




Custom Search