Game Development Reference
In-Depth Information
// texture params
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Texture is RGB565
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 , pixels);
free (pixels);
}
Now, let's take a look at the actual implementation of the hybrid video scaler. The next two
sections show you how to initialize a surface for scaling and how to perform the actual drawing.
Initializing the Surface
For this scaler to work, it is critical that the size of the texture is a power of two equal to or
greater than the size of the video. If you don't make sure this rule applies, you will see a white
or black screen whenever the image is rendered. In Listing 3-11, the function JNI_RGB565_
SurfaceInit makes sure this rule is obeyed. It takes the width and height of the image as
arguments. It then calls getBestTexSize to obtain the closest texture size, and finally creates
the empty texture by calling CreateEmptyTextureRGB565 . Note that if the image is smaller than
the texture, it will be centered on-screen by calculating XY offset coordinates.
Listing 3-11. Surface Initialization
// Get the next POT texture size greater or equal to image size (wh)
static void getBestTexSize(int w, int h, int *tw, int *th)
{
int width = 256, height = 256;
#define MAX_WIDTH 1024
#define MAX_HEIGHT 1024
while ( width < w && width < MAX_WIDTH) { width *= 2; }
while ( height < h && height < MAX_HEIGHT) { height *= 2; }
*tw = width;
*th = height;
}
/**
* Ini an RGB565 surface
* params: (w,h) width, height of the image
*/
 
Search WWH ::




Custom Search