Game Development Reference
In-Depth Information
In Figure 3-11 you have the following sizes:
Device display: 859x480
Texture: 512x256
Image: 512x256
Zoom and Draw
In Figure 3-11 you can see that the image will be scaled at 100% of any device resolution,
which is what you want. But what do you do when the image is not a power of two? To get
past this caveat, you could
1.
Zoom the 320x240 image to the closest power of two (512x256 in
this case) using a software scaler.
2.
Convert the scaled surface into a RGB656 image, compatible with
DrawIntoTextureRGB565 from the previous section.
3.
Draw into the texture, thus performing hardware scaling to the
display resolution.
This solution is a little slower than the one in the preceding section but still much faster than
using a pure software scaler, especially if you run in high-resolution devices such as tablets.
Listing 3-13 shows how to zoom an SDL surface using the popular SDL_gfx library.
Listing 3-13. Zooming an Image with SDL_gfx roto-zoom
void JNI_Flip(SDL_Surface *surface )
{
if ( zoom ) {
// if surface is 8bit scaled will be 8bit else surface is 32 bit RGBA!
SDL_Surface * sized = zoomSurface( surface, zoomx, zoomy, SMOOTHING_OFF);
JNI_FlipByBPP (sized);
// Must clean up!
SDL_FreeSurface(sized);
}
else {
JNI_FlipByBPP (surface);
}
}
Zoom and Draw Implementation
To zoom/scale an SDL surface, you simply call SDL_gfx zoomSurface with
1.
An SDL surface
2.
Horizontal zoom factor:(0-1)
3.
Vertical zoom factor
4. SMOOTHING_OFF : This disables anti-aliasing for faster drawing
 
Search WWH ::




Custom Search