Game Development Reference
In-Depth Information
/**********************************************************
* Image Constructor
* The image must be a power of 2 (256x256, 512x256,...)
* to render full screen on the OpenGL texture. If the image
* is not POT (320x240) it will be scaled
**********************************************************/
SDL_Surface * JNI_SurfaceNew(int width, int height, int bpp, int flags)
{
Uint32 rmask = 0, gmask = 0, bmask =0 , amask = 0;
// texture size & offset
int realw = 256, realh = 256, offx = 0, offy = 0;
// Image must be a power of 2 for OpenGL to scale it.
if ( width > 512 ) {
Sys_Error("ERROR: INVALID IMAGE WIDTH %d (max POT 512x512)", width);
}
// REAL W/H must be the closest POT value to wxh
// Will scale to 512x256
// could be 256 but 512 gives better res (slower)
if ( width > 256 ) realw = 512;
// size not POT , zoom to closest POT. Choices are:
// 256x256 (fastest/low res) 512x256 (better res/slower)
// 512x512 slowest.
if ( ( width != 512 && width != 256) || ( height != 256 ) ) {
zoom = 1;
zoomx = realw / (float)width;
zoomy = realh / (float)height;
offx = offy = 0;
printf("WARNING Texture of size %dx%d will be scaled to %dx%d zoomx=%.3f zoomy=%.3f"
, width, height, realw, realh, zoomx, zoomy);
}
// Create the OpenGL texture used to render
CreateEmptyTextureRGB565 (realw, realh, offx, offy);
// This is the real surface used by the client to render the video
return SDL_CreateRGBSurface (SDL_SWSURFACE, width, height, bpp, rmask, gmask, bmask,
amask);
}
Search WWH ::




Custom Search