Game Development Reference
In-Depth Information
void JNI_RGB565_SurfaceInit(int w, int h)
{
// min texture w&h
int texw = 256;
int texh = 256;
// Get texture size (must be POT) >= WxH
getBestTexSize(w, h, &texw, &texh);
// Center image on screen?
int offx = texw > w ? (texw - w)/2 : 0;
int offy = texh > h ? (texh - h)/2 : 0;
if ( w > texw || h > texh)
printf ("Error: Invalid surface size %sx%d", w, h);
// Create the OpenGL texture used to render
CreateEmptyTextureRGB565 (texw, texh, offx, offy);
}
Drawing into the Texture
Finally, to render into the display (also known as surface flipping ), you call JNI_RGB565_Flip with
an array of pixel data (encoded as RGB565) plus the size of the image. JNI_RGB565_Flip draws
into the texture by calling DrawIntoTextureRGB565 and swaps the buffers. Note that the buffer
swapping is done in Java, not C, and therefore you need a way to tell Java it is time to swap. You
can do this using JNI to call some Java method to do the actual swapping (see Listing 3-12).
Listing 3-12. Drawing an Image Buffer into a Texture Using a Quad
// Quad vertices X, Y, Z
static const float vertices[] = {
-1.0f, -1.0f, 0,
1.0f, -1.0f, 0,
1.0f, 1.0f, 0,
-1.0f, 1.0f, 0
};
// Quad coords (0-1)
static const float coords[] = {
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
};
// Quad vertex indices
static const unsigned short indices[] = { 0, 1, 2, 3};
/**
* Draw an array of pixels in the entire screen using a Quad
* pixels: unsigned short for RGB565
*/
 
Search WWH ::




Custom Search