Programming 3D Graphics with OpenGL

I n this chapter, we will talk about working with the OpenGL graphics API on the Android Platform. Specifically, we'll break down the topic into three sections. First, we'll provide an overview of OpenGL, OpenGL for Embedded Systems (OpenGL ES), and some competing standards. Second, we will explain the theory behind OpenGL and cover some of the essential OpenGL ES APIs. In the third and final section, we will give you the necessary code to build a test harness that you can use to exercise the APIs covered in the second section.

OpenGL ES is a 2D and 3D graphics API specifically for embedded systems, and Android supports it completely. The Android SDK distribution comes with a number of OpenGL ES samples to attest to this fact. However, in versions 1.0, 1.1, and 1.5 of the Android SDK, documentation on how to get started with OpenGL is minimal to nonexistent. The underlying assumption is that OpenGL ES is an open standard and that programmers can learn it from sources outside Android. A side effect of this assumption is that the few online resources that address using OpenGL with Android assume you're already familiar with OpenGL.

Here's the good news, though. In this chapter, we will help you with these minor roadblocks. With a few prerequisites, we will walk you through the creation of an OpenGL ES test harness that you can use to start drawing and experimenting with the OpenGL ES API. In the process, we will draw attention to the necessary basics of OpenGL and point you toward OpenGL resources online that will help you explore the matter further.

The way you construct this test harness, and hence the way you approach OpenGL, differs between releases 1.1 and 1.5. The approach in release 1.0 is the same as the approach in release 1.1, because the latter is a fix release for the former. We know there might be programmers out there using all three releases, so we will show you the test-harness implementation using 1.0 and 1.1 in this chapter. And we will reimplement this OpenGL test harness again in Chapter 13 using the 1.5 SDK. Even if you are programming in the 1.5 SDK, you might want to read this section to understand how the 1.5 SDK would have implemented the underlying abstraction. So, this chapter is certainly a prerequisite for Chapter 13.

By the end of this chapter, you'll be well-equipped with the ideas of drawing in three dimensions, setting up the OpenGL camera, and setting up the viewing volume (also called the frustum). We will do this by introducing almost no mathematics (unlike many OpenGL books).

Note The OpenGL camera concept is similar but distinct from the Camera class in Android's graphics package, which you learned about in Chapter 6. Whereas Android's Camera object from the graphics package simulates 3D-like viewing capabilities by projecting a 2D view moving in 3D space, the OpenGL camera is a paradigm that represents a virtual viewing point. In other words, it models a real-world scene through the viewing perspective of an observer looking through a camera. You'll learn more in the subsection "Understanding the Camera and Coordinates" under "Using OpenGL ES." Both cameras are still separate from the handheld device's physical camera that you use to take pictures or shoot video.

0 0

Post a comment