The Android Diaries | How to build a PowerVR Graphics SDK Example

Share on linkedin
Share on twitter
Share on facebook
Share on reddit
Share on digg
Share on email

After giving you a brief introduction to graphics development on Android and our PowerVR Graphics SDK v3.0 r2, it’s now time to make our PowerVR-based device say “Hello”! There are several ways to do this, but in our opinion there is none like a plain triangle rendered on a coloured background!

For this exact purpose, the PowerVR Graphics SDK includes a simple C++ application called HelloAPI. The build steps for this project vary slightly depending on which SDK you have downloaded, so the following sections are split to accommodate both paths (prefixed with Option 1 and Option 2).

Option 1: Using the Android Manager add-in SDK

First, you will need to add the IMG_SDK_HOME environment variable for your NDK builds. To do so globally in Eclipse, click on Window and open the Preferences menu, navigate to C/C++ –> Build –> Environment and add the variable IMG_SDK_HOME, setting its value to the location the PowerVR Graphics SDK add-on is installed (typically under the add-ons directory inside the Android SDK). This variable only needs to be set once so the SDK’s Examples know where to find their build dependencies.

PowerVR graphics SDK on Android SDK Manager - Add-on Sites _014

Note: The Android SDK integration required us to use Google’s preferred naming conventions for directories. Because of this, we’ve had to make a few changes, such as changing the “Examples” folder to “samples”

An Example can be imported by selecting the PowerVR Graphics SDK during the creation of a new Android sample project in Eclipse. For the purpose of this post, you should select the HelloAPI “sample” from the OpenGL ES 2.0 PowerVR Graphics SDK. Once the project has been imported, you must then right-click the <project name>->Android Tools->Add Native Support.

PowerVR graphics SDK on Android SDK Manager _010

And that’s it! You can now use Eclipse’s build, deploy and debug functionality!

Option 2: Using the standard PowerVR Graphics SDK

PowerVR Graphics SDK v3.0

The native build

First, open up a terminal and navigate to the Example project’s Android build directory. HelloAPI can be found here:

<PowerVRGraphicsSDK>/SDK_3.0/Examples/Beginner/01_HelloAPI/OGLES2/Build/Android/

Next, you need to update the run the following on the first build to create local.properties:

android update project –p .-t [TARGET]

In the example above, [TARGET] must be replaced with the target ID of the platform version you want to target on your system. Available targets can be queried with the following command:

android list target

To use the ‘android’ tool you need to have the Android SDK’s platform-tools folder in your path. Once this is done, the application is then build in two stages. The first stage compiles the C++ code into a library. This is achieved using ‘ndk-build’, a tool included in the Android NDK. To compile for all supported platforms type:

ndk-build

On an a specific platform you can compile by typing:

ndk-build APP_ABI=[PLATFORM]

Replacing [PLATFORM] with an entry from the following list of supported ABIs:

  • armeabi
  • armeabi-v7a
  • x86
  • mips

The wrapper

The second stage compiles the Java wrapper and creates the .apk file for installing on your device. The quickest way of achieving this is to type:

ant debug

This will create an .apk file in ./bin and will handle the signing of your application for you (debug signing key is used).

(To create a release build, please see https://developer.android.com/guide/developing/other-ide.html#ReleaseMode)

Deploying the APK

To install the APK to your target device, you can use the ‘adb’ tool. This is found in the Android SDK’s platform-tools directory. You should add the platform-tools directory to your path so adb can be used from anywhere in the terminal.

To install the APK, open a terminal in the ./bin directory and run the following command:

adb install –r OGLES2HelloAPI-debug.apk

And that’s it!

You can launch the HelloAPI Example app on your device and witness the mighty yellow triangle rendered on a sky blue background! The example is trivial, but provides a good starting point for programmers new to 3D graphics and the OpenGL ES APIs.

PowerVR Graphics SDK_HelloAPI

Now that you know the basics, you can dive into the rest of the PowerVR Graphics SDK to learn new techniques and optimizations to improve your own applications. Happy coding!

The Android Diaries’ is a series of blog posts, articles and tutorials where we focus on all aspects of graphics development on Android, the Android SDK as well as Android-specific APIs like Renderscript or Filterscript. If you have any Android-related questions, ideas or suggestions, please leave a comment in the box below or start a discussion on our PowerVR-dedicated forum and we will get back to you as soon as possible. Make sure you also follow us on Twitter (@ImaginationTech and @PowerVRInsider) for the latest news and updates from Imagination and the PowerVR Insider developer programme.

Guillem Vinals Gangolells has contributed to this article.

Joe Davis

Joe Davis

Joe Davis leads the PowerVR Graphics developer support team. He and his team support a wide variety of graphics developers including those writing games, middleware, UIs, navigation systems, operating systems and web browsers. Joe regularly attends and presents at developer conferences to help graphics developers get the most out of PowerVR GPUs. You can follow him on Twitter @joedavisdev.

1 thought on “The Android Diaries | How to build a PowerVR Graphics SDK Example”

  1. I had a problem with this using ADT/Eclipse on Ubuntu
    __gmsl:512: *** non-numeric second argument to `wordlist’ function: ”. Stop.
    After much messing around.
    The source of the failure was that the NDK script awk/extract-minsdkversion.awk was failing to get the minimum SDK version.
    The symptom of the awk script failure is:
    Invalid attribute name:
    package
    The cause of this problem is that the SDK sample AndroidManifest.xml files have DOS linefeeds.
    You can fix this in vim with
    :set ff=unix

    Reply

Please leave a comment below

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted. We respect your privacy and will not publish your personal details.

Blog Contact

If you have any enquiries regarding any of our blog posts, please contact:

United Kingdom

[email protected]
Tel: +44 (0)1923 260 511

Search by Tag

Search by Author

Related blog articles

Beaglebone Black

Fun with PowerVR and the BeagleBone Black: Low-Cost Development Made Easy

Development boards are cool and the BeagleBone® Black (BBB) is one of the more interesting ones around. This widely available tiny board costs around £35 and will boot Linux is only 10 seconds so anyone interested in development can get stuck in quickly. The Introduction to Mobile Graphics course has been recently revamped for 2020 for the Imagination’s University Programme and the widely available, low-cost BBB is an ideal platform for student teaching and exercises based on OpenGL® ES2.0, instead of an expensive standard PC.

Read More »
Apple M1 image

Why you should be running your iOS apps on your new Apple M1 laptop

Towards the end of last year, Apple released the latest version of its Apple MacBook Pro and Macbook Air laptops. This release was notable as with these brand-new laptops Apple made a significant change – the processor inside was based on its own M1 chip rather than the Intel architecture that it had been using since 2006. Since its release, the Apple M1 has been widely hailed for its performance, outstripping Intel in all the major benchmarks and all in a cool, quiet package with low power consumption.

Read More »
android background

The Android Invasion: Imagination GPU IP buddies up with Google-powered devices

Google Android continues to have the lion share of the mobile market, powering around 75% of all smartphones and tablets, making it the most used operating system in the world. Imagination’s PowerVR architecture-based IP and the Android OS are bedfellows, with a host of devices based on Android coming to market all the time. Here we list a few that have appeared in Q4 2020.

Read More »

Connect

Sign up to receive the latest news and product updates from Imagination straight to your inbox.