1page.title=OpenGL 2parent.title=Graphics 3parent.link=index.html 4@jd:body 5 6<div id="qv-wrapper"> 7 <div id="qv"> 8 <h2>In this document</h2> 9 10 <ol> 11 <li><a href="#basics">The Basics</a> 12 <ol> 13 <li><a href="#packages">OpenGL packages</a></li> 14 </ol> 15 <li><a href="#manifest">Declaring OpenGL Requirements</a></li> 16 </li> 17 <li><a href="#coordinate-mapping">Mapping Coordinates for Drawn Objects</a> 18 <ol> 19 <li><a href="#proj-es1">Projection and camera in ES 1.0</a></li> 20 <li><a href="#proj-es1">Projection and camera in ES 2.0</a></li> 21 </ol> 22 </li> 23 <li><a href="#faces-winding">Shape Faces and Winding</li> 24 <li><a href="#compatibility">OpenGL Versions and Device Compatibility</a> 25 <ol> 26 <li><a href="#textures">Texture compression support</a></li> 27 <li><a href="#gl-extension-query">Determining OpenGL Extensions</a></li> 28 </ol> 29 </li> 30 <li><a href="#choosing-version">Choosing an OpenGL API Version</a></li> 31 </ol> 32 <h2>Key classes</h2> 33 <ol> 34 <li>{@link android.opengl.GLSurfaceView}</li> 35 <li>{@link android.opengl.GLSurfaceView.Renderer}</li> 36 </ol> 37 <h2>Related samples</h2> 38 <ol> 39 <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/GLSurfaceViewActivity.html">GLSurfaceViewActivity</a></li> 40 <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/GLES20Activity.html">GLES20Activity</a></li> 41 <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchRotateActivity.html">TouchRotateActivity</a></li> 42 <li><a 43href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/CompressedTextureActivity.html">Compressed Textures</a></li> 44 </ol> 45 <h2>See also</h2> 46 <ol> 47 <li><a href="{@docRoot}training/graphics/opengl/index.html"> 48 Displaying Graphics with OpenGL ES</a></li> 49 <li><a href="http://www.khronos.org/opengles/">OpenGL ES</a></li> 50 <li><a href="http://www.khronos.org/opengles/1_X/">OpenGL ES 1.x Specification</a></li> 51 <li><a href="http://www.khronos.org/opengles/2_X/">OpenGL ES 2.x specification</a></li> 52 </ol> 53 </div> 54</div> 55 56<p>Android includes support for high performance 2D and 3D graphics with the Open Graphics Library 57(OpenGL), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a 58standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL 59specification intended for embedded devices. The OpenGL ES 1.0 and 1.1 API specifications have been 60supported since Android 1.0. Beginning with Android 2.2 (API Level 8), the framework supports the 61OpenGL ES 2.0 API specification.</p> 62 63<p class="note"><b>Note:</b> The specific API provided by the Android framework is similar to the 64 J2ME JSR239 OpenGL ES API, but is not identical. If you are familiar with J2ME JSR239 65 specification, be alert for variations.</p> 66 67 68<h2 id="basics">The Basics</h2> 69 70<p>Android supports OpenGL both through its framework API and the Native Development 71Kit (NDK). This topic focuses on the Android framework interfaces. For more information about the 72NDK, see the <a href="{@docRoot}tools/sdk/ndk/index.html">Android NDK</a>. 73 74<p>There are two foundational classes in the Android framework that let you create and manipulate 75graphics with the OpenGL ES API: {@link android.opengl.GLSurfaceView} and {@link 76android.opengl.GLSurfaceView.Renderer}. If your goal is to use OpenGL in your Android application, 77understanding how to implement these classes in an activity should be your first objective. 78</p> 79 80<dl> 81 <dt><strong>{@link android.opengl.GLSurfaceView}</strong></dt> 82 <dd>This class is a {@link android.view.View} where you can draw and manipulate objects using 83 OpenGL API calls and is similar in function to a {@link android.view.SurfaceView}. You can use 84 this class by creating an instance of {@link android.opengl.GLSurfaceView} and adding your 85 {@link android.opengl.GLSurfaceView.Renderer Renderer} to it. However, if you want to capture 86 touch screen events, you should extend the {@link android.opengl.GLSurfaceView} class to 87 implement the touch listeners, as shown in OpenGL Tutorials for 88 <a href="{@docRoot}resources/tutorials/opengl/opengl-es10.html#touch">ES 1.0</a>, 89 <a href="{@docRoot}resources/tutorials/opengl/opengl-es20.html#touch">ES 2.0</a> and the <a 90href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchRotateActivity.html" 91>TouchRotateActivity</a> sample.</dd> 92 93 <dt><strong>{@link android.opengl.GLSurfaceView.Renderer}</strong></dt> 94 <dd>This interface defines the methods required for drawing graphics in an OpenGL {@link 95 android.opengl.GLSurfaceView}. You must provide an implementation of this interface as a 96 separate class and attach it to your {@link android.opengl.GLSurfaceView} instance using 97 {@link android.opengl.GLSurfaceView#setRenderer(android.opengl.GLSurfaceView.Renderer) 98 GLSurfaceView.setRenderer()}. 99 100 <p>The {@link android.opengl.GLSurfaceView.Renderer} interface requires that you implement the 101 following methods:</p> 102 <ul> 103 <li> 104 {@link 105 android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10, 106 javax.microedition.khronos.egl.EGLConfig) onSurfaceCreated()}: The system calls this 107 method once, when creating the {@link android.opengl.GLSurfaceView}. Use this method to perform 108 actions that need to happen only once, such as setting OpenGL environment parameters or 109 initializing OpenGL graphic objects. 110 </li> 111 <li> 112 {@link 113 android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10) 114 onDrawFrame()}: The system calls this method on each redraw of the {@link 115 android.opengl.GLSurfaceView}. Use this method as the primary execution point for 116 drawing (and re-drawing) graphic objects.</li> 117 <li> 118 {@link 119 android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10, 120 int, int) onSurfaceChanged()}: The system calls this method when the {@link 121 android.opengl.GLSurfaceView} geometry changes, including changes in size of the {@link 122 android.opengl.GLSurfaceView} or orientation of the device screen. For example, the system calls 123 this method when the device changes from portrait to landscape orientation. Use this method to 124 respond to changes in the {@link android.opengl.GLSurfaceView} container. 125 </li> 126 </ul> 127 </dd> 128</dl> 129 130<h3 id="packages">OpenGL packages</h3> 131<p>Once you have established a container view for OpenGL using {@link 132android.opengl.GLSurfaceView} and {@link android.opengl.GLSurfaceView.Renderer}, you can begin 133calling OpenGL APIs using the following classes:</p> 134 135<ul> 136 <li>OpenGL ES 1.0/1.1 API Packages 137 <ul> 138 <li>{@link android.opengl} - This package provides a static interface to the OpenGL ES 1391.0/1.1 classes and better performance than the javax.microedition.khronos package interfaces. 140 <ul> 141 <li>{@link android.opengl.GLES10}</li> 142 <li>{@link android.opengl.GLES10Ext}</li> 143 <li>{@link android.opengl.GLES11}</li> 144 <li>{@link android.opengl.GLES10Ext}</li> 145 </ul> 146 </li> 147 <li>{@link javax.microedition.khronos.opengles} - This package provides the standard 148implementation of OpenGL ES 1.0/1.1. 149 <ul> 150 <li>{@link javax.microedition.khronos.opengles.GL10}</li> 151 <li>{@link javax.microedition.khronos.opengles.GL10Ext}</li> 152 <li>{@link javax.microedition.khronos.opengles.GL11}</li> 153 <li>{@link javax.microedition.khronos.opengles.GL11Ext}</li> 154 <li>{@link javax.microedition.khronos.opengles.GL11ExtensionPack}</li> 155 </ul> 156 </li> 157 </ul> 158 </li> 159 <li>OpenGL ES 2.0 API Class 160 <ul> 161 <li>{@link android.opengl.GLES20 android.opengl.GLES20} - This package provides the 162interface to OpenGL ES 2.0 and is available starting with Android 2.2 (API Level 8).</li> 163 </ul> 164 </li> 165</ul> 166 167<p>If you'd like to start building an app with OpenGL right away, have a look at the tutorials for 168<a href="{@docRoot}resources/tutorials/opengl/opengl-es10.html">OpenGL ES 1.0</a> or 169<a href="{@docRoot}resources/tutorials/opengl/opengl-es20.html">OpenGL ES 2.0</a>! 170</p> 171 172<h2 id="manifest">Declaring OpenGL Requirements</h2> 173<p>If your application uses OpenGL features that are not available on all devices, you must include 174these requirements in your <a 175href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a></code> file. 176Here are the most common OpenGL manifest declarations:</p> 177 178<ul> 179 <li><strong>OpenGL ES version requirements</strong> - If your application only supports OpenGL ES 1802.0, you must declare that requirement by adding the following settings to your manifest as 181shown below. 182 183<pre> 184 <!-- Tell the system this app requires OpenGL ES 2.0. --> 185 <uses-feature android:glEsVersion="0x00020000" android:required="true" /> 186</pre> 187 188 <p>Adding this declaration causes Google Play to restrict your application from being 189 installed on devices that do not support OpenGL ES 2.0.</p> 190 </li> 191 <li><strong>Texture compression requirements</strong> - If your application uses texture 192compression formats, you must declare the formats your application supports in your manifest file 193using <a href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html">{@code 194<supports-gl-texture>}</a>. For more information about available texture compression 195formats, see <a href="#textures">Texture compression support</a>. 196 197<p>Declaring texture compression requirements in your manifest hides your application from users 198with devices that do not support at least one of your declared compression types. For more 199information on how Google Play filtering works for texture compressions, see the <a 200href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html#market-texture-filtering"> 201Google Play and texture compression filtering</a> section of the {@code 202<supports-gl-texture>} documentation.</p> 203 </li> 204</ul> 205 206 207<h2 id="coordinate-mapping">Mapping Coordinates for Drawn Objects</h2> 208 209<p>One of the basic problems in displaying graphics on Android devices is that their screens can 210vary in size and shape. OpenGL assumes a square, uniform coordinate system and, by default, happily 211draws those coordinates onto your typically non-square screen as if it is perfectly square.</p> 212 213<img src="{@docRoot}images/opengl/coordinates.png"> 214<p class="img-caption"> 215 <strong>Figure 1.</strong> Default OpenGL coordinate system (left) mapped to a typical Android 216device screen (right). 217</p> 218 219<p>The illustration above shows the uniform coordinate system assumed for an OpenGL frame on the 220left, and how these coordinates actually map to a typical device screen in landscape orientation 221on the right. To solve this problem, you can apply OpenGL projection modes and camera views to 222transform coordinates so your graphic objects have the correct proportions on any display.</p> 223 224<p>In order to apply projection and camera views, you create a projection matrix and a camera view 225matrix and apply them to the OpenGL rendering pipeline. The projection matrix recalculates the 226coordinates of your graphics so that they map correctly to Android device screens. The camera view 227matrix creates a transformation that renders objects from a specific eye position.</p> 228 229<h3 id="proj-es1">Projection and camera view in OpenGL ES 1.0</h3> 230<p>In the ES 1.0 API, you apply projection and camera view by creating each matrix and then 231adding them to the OpenGL environment.</p> 232 233<ol> 234<li><strong>Projection matrix</strong> - Create a projection matrix using the geometry of the 235device screen in order to recalculate object coordinates so they are drawn with correct proportions. 236The following example code demonstrates how to modify the {@link 237android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10, 238int, int) onSurfaceChanged()} method of a {@link android.opengl.GLSurfaceView.Renderer} 239implementation to create a projection matrix based on the screen's aspect ratio and apply it to the 240OpenGL rendering environment. 241 242<pre> 243 public void onSurfaceChanged(GL10 gl, int width, int height) { 244 gl.glViewport(0, 0, width, height); 245 246 // make adjustments for screen ratio 247 float ratio = (float) width / height; 248 gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode 249 gl.glLoadIdentity(); // reset the matrix to its default state 250 gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); // apply the projection matrix 251 } 252</pre> 253</li> 254 255<li><strong>Camera transformation matrix</strong> - Once you have adjusted the coordinate system 256using a projection matrix, you must also apply a camera view. The following example code shows how 257to modify the {@link 258android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10) 259onDrawFrame()} method of a {@link android.opengl.GLSurfaceView.Renderer} 260implementation to apply a model view and use the 261{@link android.opengl.GLU#gluLookAt(javax.microedition.khronos.opengles.GL10, float, float, float, 262float, float, float, float, float, float) GLU.gluLookAt()} utility to create a viewing tranformation 263which simulates a camera position. 264 265<pre> 266 public void onDrawFrame(GL10 gl) { 267 ... 268 // Set GL_MODELVIEW transformation mode 269 gl.glMatrixMode(GL10.GL_MODELVIEW); 270 gl.glLoadIdentity(); // reset the matrix to its default state 271 272 // When using GL_MODELVIEW, you must set the camera view 273 GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); 274 ... 275 } 276</pre> 277</li> 278</ol> 279 280<p>For a complete example of how to apply projection and camera views with OpenGL ES 1.0, see the <a 281href="{@docRoot}resources/tutorials/opengl/opengl-es10.html#projection-and-views">OpenGL ES 1.0 282tutorial</a>.</p> 283 284 285<h3 id="proj-es2">Projection and camera view in OpenGL ES 2.0</h3> 286<p>In the ES 2.0 API, you apply projection and camera view by first adding a matrix member to 287the vertex shaders of your graphics objects. With this matrix member added, you can then 288generate and apply projection and camera viewing matrices to your objects.</p> 289 290<ol> 291<li><strong>Add matrix to vertex shaders</strong> - Create a variable for the view projection matrix 292and include it as a multiplier of the shader's position. In the following example vertex shader 293code, the included {@code uMVPMatrix} member allows you to apply projection and camera viewing 294matrices to the coordinates of objects that use this shader. 295 296<pre> 297 private final String vertexShaderCode = 298 299 // This matrix member variable provides a hook to manipulate 300 // the coordinates of objects that use this vertex shader 301 "uniform mat4 uMVPMatrix; \n" + 302 303 "attribute vec4 vPosition; \n" + 304 "void main(){ \n" + 305 306 // the matrix must be included as part of gl_Position 307 " gl_Position = uMVPMatrix * vPosition; \n" + 308 309 "} \n"; 310</pre> 311 <p class="note"><strong>Note:</strong> The example above defines a single transformation matrix 312member in the vertex shader into which you apply a combined projection matrix and camera view 313matrix. Depending on your application requirements, you may want to define separate projection 314matrix and camera viewing matrix members in your vertex shaders so you can change them 315independently.</p> 316</li> 317<li><strong>Access the shader matrix</strong> - After creating a hook in your vertex shaders to 318apply projection and camera view, you can then access that variable to apply projection and 319camera viewing matrices. The following code shows how to modify the {@link 320android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10, 321javax.microedition.khronos.egl.EGLConfig) onSurfaceCreated()} method of a {@link 322android.opengl.GLSurfaceView.Renderer} implementation to access the matrix 323variable defined in the vertex shader above. 324 325<pre> 326 public void onSurfaceCreated(GL10 unused, EGLConfig config) { 327 ... 328 muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); 329 ... 330 } 331</pre> 332</li> 333<li><strong>Create projection and camera viewing matrices</strong> - Generate the projection and 334viewing matrices to be applied the graphic objects. The following example code shows how to modify 335the {@link 336android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10, 337javax.microedition.khronos.egl.EGLConfig) onSurfaceCreated()} and {@link 338android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10, 339int, int) onSurfaceChanged()} methods of a {@link android.opengl.GLSurfaceView.Renderer} 340implementation to create camera view matrix and a projection matrix based on the screen aspect ratio 341of the device. 342 343<pre> 344 public void onSurfaceCreated(GL10 unused, EGLConfig config) { 345 ... 346 // Create a camera view matrix 347 Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); 348 } 349 350 public void onSurfaceChanged(GL10 unused, int width, int height) { 351 GLES20.glViewport(0, 0, width, height); 352 353 float ratio = (float) width / height; 354 355 // create a projection matrix from device screen geometry 356 Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7); 357 } 358</pre> 359</li> 360 361<li><strong>Apply projection and camera viewing matrices</strong> - To apply the projection and 362camera view transformations, multiply the matrices together and then set them into the vertex 363shader. The following example code shows how modify the {@link 364android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10) 365onDrawFrame()} method of a {@link android.opengl.GLSurfaceView.Renderer} implementation to combine 366the projection matrix and camera view created in the code above and then apply it to the graphic 367objects to be rendered by OpenGL. 368 369<pre> 370 public void onDrawFrame(GL10 unused) { 371 ... 372 // Combine the projection and camera view matrices 373 Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); 374 375 // Apply the combined projection and camera view transformations 376 GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); 377 378 // Draw objects 379 ... 380 } 381</pre> 382</li> 383</ol> 384<p>For a complete example of how to apply projection and camera view with OpenGL ES 2.0, see the <a 385href="{@docRoot}resources/tutorials/opengl/opengl-es20.html#projection-and-views">OpenGL ES 2.0 386tutorial</a>.</p> 387 388<h2 id="faces-winding">Shape Faces and Winding</h2> 389 390<p>In OpenGL, the face of a shape is a surface defined by three or more points in three-dimensional 391space. A set of three or more three-dimensional points (called vertices in OpenGL) have a front face 392and a back face. How do you know which face is front and which is the back? Good question. The 393answer has to do with winding, or, the direction in which you define the points of a shape.</p> 394 395<img src="{@docRoot}images/opengl/ccw-winding.png"> 396<p class="img-caption"> 397 <strong>Figure 1.</strong> Illustration of a coordinate list which translates into a 398counterclockwise drawing order.</p> 399 400<p>In this example, the points of the triangle are defined in an order such that they are drawn in a 401counterclockwise direction. The order in which these coordinates are drawn defines the winding 402direction for the shape. By default, in OpenGL, the face which is drawn counterclockwise is the 403front face. The triangle shown in Figure 1 is defined so that you are looking at the front face of 404the shape (as interpreted by OpenGL) and the other side is the back face.</p> 405 406<p>Why is it important to know which face of a shape is the front face? The answer has to do with a 407commonly used feature of OpenGL, called face culling. Face culling is an option for the OpenGL 408environment which allows the rendering pipeline to ignore (not calculate or draw) the back face of a 409shape, saving time, memory and processing cycles:</p> 410 411<pre> 412// enable face culling feature 413gl.glEnable(GL10.GL_CULL_FACE); 414// specify which faces to not draw 415gl.glCullFace(GL10.GL_BACK); 416</pre> 417 418<p>If you try to use the face culling feature without knowing which sides of your shapes are the 419front and back, your OpenGL graphics are going to look a bit thin, or possibly not show up at all. 420So, always define the coordinates of your OpenGL shapes in a counterclockwise drawing order.</p> 421 422<p class="note"><strong>Note:</strong> It is possible to set an OpenGL environment to treat the 423clockwise face as the front face, but doing so requires more code and is likely to confuse 424experienced OpenGL developers when you ask them for help. So don’t do that.</p> 425 426<h2 id="compatibility">OpenGL Versions and Device Compatibility</h2> 427 428<p>The OpenGL ES 1.0 and 1.1 API specifications have been supported since Android 1.0. 429Beginning with Android 2.2 (API Level 8), the framework supports the OpenGL ES 2.0 API 430specification. OpenGL ES 2.0 is supported by most Android devices and is recommended for new 431applications being developed with OpenGL. For information about the relative number of 432Android-powered devices that support a given version of OpenGL ES, see the <a 433href="{@docRoot}resources/dashboard/opengl.html">OpenGL ES Versions Dashboard</a>.</p> 434 435 436<h3 id="textures">Texture compression support</h3> 437<p>Texture compression can significantly increase the performance of your OpenGL application by 438reducing memory requirements and making more efficient use of memory bandwidth. The Android 439framework provides support for the ETC1 compression format as a standard feature, including a {@link 440android.opengl.ETC1Util} utility class and the {@code etc1tool} compression tool (located in the 441Android SDK at {@code <sdk>/tools/}). For an example of an Android application that uses 442texture compression, see the <a 443href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/CompressedTextureActivity.html" 444>CompressedTextureActivity</a> code sample.</p> 445 446<p>The ETC format is supported by most Android devices, but it not guarranteed to be available. To 447check if the ETC1 format is supported on a device, call the {@link 448android.opengl.ETC1Util#isETC1Supported() ETC1Util.isETC1Supported()} method.</p> 449 450<p class="note"><b>Note:</b> The ETC1 texture compression format does not support textures with an 451alpha channel. If your application requires textures with an alpha channel, you should 452investigate other texture compression formats available on your target devices.</p> 453 454<p>Beyond the ETC1 format, Android devices have varied support for texture compression based on 455their GPU chipsets and OpenGL implementations. You should investigate texture compression support on 456the the devices you are are targeting to determine what compression types your application should 457support. In order to determine what texture formats are supported on a given device, you must <a 458href="#gl-extension-query">query the device</a> and review the <em>OpenGL extension names</em>, 459which identify what texture compression formats (and other OpenGL features) are supported by the 460device. Some commonly supported texture compression formats are as follows:</p> 461 462<ul> 463 <li><strong>ATITC (ATC)</strong> - ATI texture compression (ATITC or ATC) is available on a 464wide variety of devices and supports fixed rate compression for RGB textures with and without 465an alpha channel. This format may be represented by several OpenGL extension names, for example: 466 <ul> 467 <li>{@code GL_AMD_compressed_ATC_texture}</li> 468 <li>{@code GL_ATI_texture_compression_atitc}</li> 469 </ul> 470 </li> 471 <li><strong>PVRTC</strong> - PowerVR texture compression (PVRTC) is available on a wide 472variety of devices and supports 2-bit and 4-bit per pixel textures with or without an alpha channel. 473This format is represented by the following OpenGL extension name: 474 <ul> 475 <li>{@code GL_IMG_texture_compression_pvrtc}</li> 476 </ul> 477 </li> 478 <li><strong>S3TC (DXT<em>n</em>/DXTC)</strong> - S3 texture compression (S3TC) has several 479format variations (DXT1 to DXT5) and is less widely available. The format supports RGB textures with 4804-bit alpha or 8-bit alpha channels. This format may be represented by several OpenGL extension 481names, for example: 482 <ul> 483 <li>{@code GL_OES_texture_compression_S3TC}</li> 484 <li>{@code GL_EXT_texture_compression_s3tc}</li> 485 <li>{@code GL_EXT_texture_compression_dxt1}</li> 486 <li>{@code GL_EXT_texture_compression_dxt3}</li> 487 <li>{@code GL_EXT_texture_compression_dxt5}</li> 488 </ul> 489 </li> 490 <li><strong>3DC</strong> - 3DC texture compression (3DC) is a less widely available format that 491supports RGB textures with an an alpha channel. This format is represented by the following OpenGL 492extension name:</li> 493 <ul> 494 <li>{@code GL_AMD_compressed_3DC_texture}</li> 495 </ul> 496</ul> 497 498<p class="warning"><strong>Warning:</strong> These texture compression formats are <em>not 499supported</em> on all devices. Support for these formats can vary by manufacturer and device. For 500information on how to determine what texture compression formats are on a particular device, see 501the next section. 502</p> 503 504<p class="note"><strong>Note:</strong> Once you decide which texture compression formats your 505application will support, make sure you declare them in your manifest using <a 506href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html"><supports-gl-texture> 507</a>. Using this declaration enables filtering by external services such as Google Play, so that 508your app is installed only on devices that support the formats your app requires. For details, see 509<a 510href="{@docRoot}guide/topics/graphics/opengl.html#manifest">OpenGL manifest declarations</a>.</p> 511 512<h3 id="gl-extension-query">Determining OpenGL extensions</h3> 513<p>Implementations of OpenGL vary by Android device in terms of the extensions to the OpenGL ES API 514that are supported. These extensions include texture compressions, but typically also include other 515extensions to the OpenGL feature set.</p> 516 517<p>To determine what texture compression formats, and other OpenGL extensions, are supported on a 518particular device:</p> 519<ol> 520 <li>Run the following code on your target devices to determine what texture compression 521formats are supported: 522<pre> 523 String extensions = javax.microedition.khronos.opengles.GL10.glGetString(GL10.GL_EXTENSIONS); 524</pre> 525 <p class="warning"><b>Warning:</b> The results of this call <em>vary by device!</em> You 526must run this call on several target devices to determine what compression types are commonly 527supported.</p> 528 </li> 529 <li>Review the output of this method to determine what OpenGL extensions are supported on the 530device.</li> 531</ol> 532 533 534<h2 id="choosing-version">Choosing an OpenGL API Version</h2> 535 536<p>OpenGL ES API version 1.0 (and the 1.1 extensions) and version 2.0 both provide high 537performance graphics interfaces for creating 3D games, visualizations and user interfaces. Graphics 538programming for the OpenGL ES 1.0/1.1 API versus ES 2.0 differs significantly, and so developers 539should carefully consider the following factors before starting development with either API:</p> 540 541<ul> 542 <li><strong>Performance</strong> - In general, OpenGL ES 2.0 provides faster graphics performance 543than the ES 1.0/1.1 APIs. However, the performance difference can vary depending on the Android 544device your OpenGL application is running on, due to differences in the implementation of the OpenGL 545graphics pipeline.</li> 546 <li><strong>Device Compatibility</strong> - Developers should consider the types of devices, 547Android versions and the OpenGL ES versions available to their customers. For more information 548on OpenGL compatibility across devices, see the <a href="#compatibility">OpenGL Versions and Device 549Compatibility</a> section.</li> 550 <li><strong>Coding Convenience</strong> - The OpenGL ES 1.0/1.1 API provides a fixed function 551pipeline and convenience functions which are not available in the ES 2.0 API. Developers who are new 552to OpenGL may find coding for OpenGL ES 1.0/1.1 faster and more convenient.</li> 553 <li><strong>Graphics Control</strong> - The OpenGL ES 2.0 API provides a higher degree 554of control by providing a fully programmable pipeline through the use of shaders. With more 555direct control of the graphics processing pipeline, developers can create effects that would be 556very difficult to generate using the 1.0/1.1 API.</li> 557</ul> 558 559<p>While performance, compatibility, convenience, control and other factors may influence your 560decision, you should pick an OpenGL API version based on what you think provides the best experience 561for your users.</p> 562