Game Development Reference
In-Depth Information
the right balance of performance versus display quality. As you saw in Chapter 2, video
scaling can be one of three kinds, from slowest to the fastest.
Software : The slowest method but the easiest to implement. Best for old
devices with no GPUs. However, most of today's phones are hardware
accelerated.
Hybrid : Uses a mix of software drawing (to create an image buffer) and
hardware rendering (to draw into the display). It is fast and can render
images at any resolution greater than 256x256.
Hardware only : The fastest of the bunch but the hardest to implement.
Depending on the complexity of your game, it may require a powerful
GPU. If you have good hardware, it can create games with amazing
quality and effects. It is a tough choice in hardware-fragmented
platforms such as Android.
This section tackles the middle choice, hybrid scaling. It is the best choice for a fragmented
platform where you have a software renderer and want to scale your game to any display
resolution. It is perfect for games such as emulators, arcade, simple shooters, and others.
It also works very well in low-, middle-, and high-power devices. First, you'll get a general
overview of hybrid scaling and why it is the preferable method to scale video. Next, you'll
dig into the implementation, including how to initialize a surface and draw into the texture to
perform the actual scaling.
Why Use Hybrid Scaling?
The principle behind this scaling technique is simple.
Your game creates an image buffer (usually in pixel format RGB565, the
most common for mobile) at a given size. You'll use 320x240, the typical
size of an emulator.
The image 320x240 needs to be scaled to a tablet size (1024x768)—or
any device for that matter. Here you could use a software scaler but it
would be painfully slow. Instead you create an OpenGL ES texture and
render the image (320x240) into the texture using a GL Quad.
By magic the texture will be scaled to the display size (1024x768) using
hardware, thus offering a significant performance boost to your game.
From the implementation point of view, the process can be described as follows:
Initialize the OpenGL ES texture : At the stage of the game where the
video gets initialized, a hardware surface must be created. This surface
consists of a simple texture where the video image will be rendered
(see Listings 3-10 and 3-11).
Draw the image buffer into the texture : At the end of your game loop,
render the video image into the texture, which will be automatically
scaled to fit any display size (see Listing 3-12).
 
Search WWH ::




Custom Search