Book Image

OpenGL ES 3.0 Cookbook

By : Parminder Singh
Book Image

OpenGL ES 3.0 Cookbook

By: Parminder Singh

Overview of this book

<p>"Write once, use anywhere" is truly the power behind OpenGL ES and has made it an embedded industry standard. The library provides cutting-edge, easy-to-use features to build a wide range of applications in the gaming, simulation, augmented-reality, image-processing, and geospatial domains.</p> <p>The book starts by providing you with all the necessary OpenGL ES 3.0 setup guidelines on iOS and Android platforms. You'll go on to master the fundamentals of modern 3D graphics, such as drawing APIs, transformations, buffer objects, the model-view-project analogy, and much more. The book goes on to deal with advanced topics and offers a wide range of recipes on the light shading, real-time rendering techniques with static and procedure textures to create stunning visualizations and runtime effects.</p>
Table of Contents (21 chapters)
OpenGL ES 3.0 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Software requirements for OpenGL ES 3.0 – Android ADT


In the previous section, we have implemented the source code for our first simple program in OpenGL ES 3.0. We will use the same program to render the output on the Android and iOS platforms. This section will cover all the basic requirements that we need to develop OpenGL ES 3.0 applications on the Android platform.

Android is a Linux-based operating system; therefore, most of its development and configuration requires UNIX-based tools. This section discusses all the prerequisites for OpenGL ES 3.0's development on Android.

Android supports the OpenGL ES application development in two ways: the Java framework API and Native Development Kit (NDK). The Java framework APIs for OpenGL ES 3.0 focuses on the Java code style of development. Therefore, if you are developing an application purely in Java code, you can build the OpenGL ES 3.0 code within the Java-based application framework. In contrast, the NDK uses the C/C++ language to build the OpenGL ES 3.0 application. This is more suitable for developers who are interested to develop OpenGL ES applications in the C/C++ language. The additional benefit is that the same code can be used across different platforms, which support the C/C++ language, such as iOS, Blackberry, Windows, and so on. JNI works as an interface between the core Java application framework and the NDK C/C++ code.

This book focuses on the native development of the OpenGL ES application through NDK. We will also see the advantages of using NDK over Java framework APIs.

Getting ready

For Android development, you must ensure the following prerequisites are fulfilled on your machine (Window/Linux/Mac) before starting the development sessions. Download the following packages and proceed to the next section:

How to do it...

ADT bundle: Android Developer Tools (ADT) are a combo set of the Android software development kit. This provides us all necessary APIs, debugger, and test applications to build Android apps. It contains a variety of other tools that help us in profiling apps and provides an emulation support to run apps on an emulator.

Download the ADT bundle according to your operating system. The downloaded package will be in ZIP form; unzip it. This will extract a folder with the adt-bundle-xxxxx name. The name is dependent on the operating system and its version type: 32/64 bit.

This extracted ADT bundle contains the following important folders:

  • Eclipse folder: This folder contains the Eclipse IDE, which is an integrated environment to develop Android applications. This special Eclipse lets users to quickly set up new Android projects, add framework packages, create UI, export .apk, and provide many more features.

  • SDK folder: This folder contains tools to develop and debug your app; tools to support new features on the Android platform, sample apps, documentation, system images; and SDK dependent tools that are available when new platforms are released. For more information on the SDK, refer to https://developer.android.com/sdk/exploring.html.

    Note

    For the sake of better project management, keep your installation in the central location. We have created a folder called Android and extracted the ADT bundle within this folder. The folder name and location can be as per your personal choice.

  • JDK: Depending on the ADT's requirements, you may need to update the Java Development kit. JDK contains tools to develop, debug, and monitor Java applications.

    Go to the previously mentioned URL and download the JDK. The minimum requirement is JDK 6.0. However, higher versions must be workable. Download the installer and install it on your machine. JDK automatically contains the Java Runtime Environment (JRE), which contains everything required to run Java applications on your system. Therefore, there is no need to install any other software package.

  • NDK: The Native Development Kit is a toolset that helps to develop some parts of the Android application in the C/C++ language. It provides an interface between the Java and C++ code to communicate with each other. Download the latest NDK package and uncompress it into our Android folder.

  • Environment variables: Make sure that you define the system environment variable path to locate your NDK, SDK, and platform tools. This will be helpful in running executables from command-line terminals. Additionally, we need to define ANDROID_HOME to locate the SDK folder in the ADT bundle. The following sample shows the definition of these environment variables in the .bash_profile file under the Mac operating system. Similarly, these need to be defined in other operating systems, according to their way of defining environment variables:

    bash_profile
    PATH=/usr/local/bin:/usr/local/sbin:$PATH
    
    ANDROID_NDK=/Users/parmindersingh/Dev/Android/android-ndk-r9c
    ANDROID_HOME=/Users/parmindersingh/Dev/Android/adt-bundle-mac/sdk
    
    PATH=$ANDROID_NDK:$PATH
    PATH=$ANDROID_HOME/tool:$ANDROID_HOME/platform-tools:$PATH
    export ANDROID_HOME
  • Android SDK Manager: In the ADT bundle folder, open Eclipse IDE and navigate to Window | Android SDK Manager. Install Android 4.3 and its related subcomponents, as shown in the following screenshot:

    Note

    For OpenGL ES 3.0, we need Android 4.3 (the Level 18 API) or higher versions.

  • Cygwin: Cygwin is a UNIX-based command-line terminal application that allows Windows users to compile and debug Unix-based applications.

    1. Download the setup.exe from the URL mentioned in the previous section and execute it. This will open the installation interface for the app. Click on default selection on each window and click on the Next button until the list of packages needed to be installed does not appear.

    2. Search for make and select Devel/make. Similarly, search shell, select Shells/bash, click on next and then click on Finish. This will install a Cygwin Terminal in your Windows program list. Make a shortcut on your desktop for quick launch. Refer to the following screenshot for assistance:

How it works...

The Android SDK provides a beautiful modular package that contains all required tools that are necessary to build an Android application. SDK and platform tools in conjunction with the SDK platform act as a backbone of the Android application development. These provide services to debug, manage, and deploy Android applications. They manage various Android platforms and related SDK APIs. This package also contains a customized eclipse for Android development; it helps to build the applications UI quickly. IDE provides special tools (such as the Android SDK Manager) that allow you to install new Android platforms and many other helper tools.

Android supports the development of some portions of its application in the C/C++ language. This kind of development is supported through the NDK tool; this tool offers an interface called Java Native Interface (JNI) that helps to set up communication between the Java framework and native code to communicate with each other. NDK needs a Unix-based command-line terminal to build C/C++ libraries. This command-line terminal is built in under UNIX-based operating systems. On Windows, it's provided by the Cygwin application. Developers build the code and export the native code functionality through libraries (.so/.dll/.a). The Android application uses these libraries in static or uses the shared form to integrate it into the application.