diff --git a/project/jni/application/src b/project/jni/application/src index d83877510..f80955918 120000 --- a/project/jni/application/src +++ b/project/jni/application/src @@ -1 +1 @@ -gemrb \ No newline at end of file +test32bpp \ No newline at end of file diff --git a/project/jni/application/test32bpp/AndroidAppSettings.cfg b/project/jni/application/test32bpp/AndroidAppSettings.cfg new file mode 100644 index 000000000..f5f6e0de6 --- /dev/null +++ b/project/jni/application/test32bpp/AndroidAppSettings.cfg @@ -0,0 +1,44 @@ +# The application settings for Android libSDL port +AppSettingVersion=17 +LibSdlVersion=1.2 +AppName="Ballfield 32bpp" +AppFullName=net.olofson.ballfield.highbpp +ScreenOrientation=h +InhibitSuspend=n +AppDataDownloadUrl="Game data is 1 Mb|ballfield2.zip" +VideoDepthBpp=32 +NeedDepthBuffer=n +NeedStencilBuffer=n +NeedGles2=n +SwVideoMode=y +SdlVideoResize=y +SdlVideoResizeKeepAspect=n +CompatibilityHacks=n +AppUsesMouse=y +AppNeedsTwoButtonMouse=y +ShowMouseCursor=n +ForceRelativeMouseMode=n +AppNeedsArrowKeys=n +AppNeedsTextInput=y +AppUsesJoystick=y +AppHandlesJoystickSensitivity=n +AppUsesMultitouch=y +NonBlockingSwapBuffers=n +RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE" +AppTouchscreenKeyboardKeysAmount=0 +AppTouchscreenKeyboardKeysAmountAutoFire=0 +RedefinedKeysScreenKb="1 2 3 4 5 6 1 2 3 4" +StartupMenuButtonTimeout=3000 +HiddenMenuOptions='OptionalDownloadConfig' +FirstStartMenuOptions='' +MultiABI=n +AppVersionCode=101 +AppVersionName="1.01" +ResetSdlConfigForThisVersion=n +CompiledLibraries="sdl_mixer sdl_image" +CustomBuildScript=n +AppCflags='-O2 -finline-functions' +AppLdflags='' +AppSubdirsBuild='' +AppCmdline='' +ReadmeText='^Readme text' diff --git a/project/jni/application/test32bpp/AndroidData/ballfield2.zip b/project/jni/application/test32bpp/AndroidData/ballfield2.zip new file mode 100644 index 000000000..655e4ce19 Binary files /dev/null and b/project/jni/application/test32bpp/AndroidData/ballfield2.zip differ diff --git a/project/jni/application/test32bpp/ballfield.cpp b/project/jni/application/test32bpp/ballfield.cpp new file mode 100644 index 000000000..a86503b4f --- /dev/null +++ b/project/jni/application/test32bpp/ballfield.cpp @@ -0,0 +1,668 @@ +/* + * "Ballfield" + * + * (C) David Olofson , 2002, 2003 + * + * This software is released under the terms of the GPL. + * + * Contact author for permission if you want to use this + * software, or work derived from it, under other terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "SDL.h" +#include "SDL_image.h" + + +/*---------------------------------------------------------- + Definitions... +----------------------------------------------------------*/ +#define SCREEN_W 640 +#define SCREEN_H 480 + +#define BALLS 400 + +#define COLORS 2 + +typedef struct +{ + Sint32 x, y, z; /* Position */ + Uint32 c; /* Color */ +} point_t; + + +/* + * Ballfield + */ +typedef struct +{ + point_t points[BALLS]; + SDL_Rect *frames; + SDL_Surface *gfx[COLORS]; + int use_alpha; +} ballfield_t; + + +/* + * Size of the biggest ball image in pixels + * + * Balls are scaled down and *packed*, one pixel + * smaller for each frame down to 1x1. The actual + * image width is (obviously...) the same as the + * width of the first frame. + */ +#define BALL_W 32 +#define BALL_H 32 + + + + +/*---------------------------------------------------------- + General tool functions +----------------------------------------------------------*/ + +/* + * Bump areas of low and high alpha to 0% or 100% + * respectively, just in case the graphics contains + * "alpha noise". + */ +SDL_Surface *clean_alpha(SDL_Surface *s) +{ + SDL_Surface *work; + SDL_Rect r; + Uint32 *pixels; + int pp; + int x, y; + + work = SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, + 32, 0xff000000, 0x00ff0000, 0x0000ff00, + 0x000000ff); + if(!work) + return NULL; + + r.x = r.y = 0; + r.w = s->w; + r.h = s->h; + if(SDL_BlitSurface(s, &r, work, NULL) < 0) + { + SDL_FreeSurface(work); + return NULL; + } + + SDL_LockSurface(work); + pixels = (Uint32 *)work->pixels; + pp = work->pitch / sizeof(Uint32); + for(y = 0; y < work->h; ++y) + for(x = 0; x < work->w; ++x) + { + Uint32 pix = pixels[y*pp + x]; + switch((pix & 0xff) >> 4) + { + case 0: + pix = 0x00000000; + break; + default: + break; + case 15: + pix |= 0xff; + break; + } + pixels[y*pp + x] = pix; + } + SDL_UnlockSurface(work); + + return work; +} + + +/* + * Load and convert an antialiazed, zoomed set of sprites. + */ +SDL_Surface *load_zoomed(char *name, int alpha) +{ + SDL_Surface *sprites; + SDL_Surface *temp = IMG_Load(name); + if(!temp) + return NULL; + + /* + sprites = temp; + SDL_SetAlpha(sprites, 0, 255); + temp = clean_alpha(sprites); + SDL_FreeSurface(sprites); + */ + if(!temp) + { + fprintf(stderr, "Could not clean alpha!\n"); + return NULL; + } + + if(alpha) + { + SDL_SetAlpha(temp, 0, SDL_ALPHA_OPAQUE); + sprites = SDL_DisplayFormatAlpha(temp); + } + else + { + SDL_SetColorKey(temp, SDL_SRCCOLORKEY, + SDL_MapRGB(temp->format, 0, 0, 0)); + sprites = SDL_DisplayFormat(temp); + } + SDL_FreeSurface(temp); + + return sprites; +} + + +void print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, float value) +{ + char buf[16]; + int val = (int)(value * 10.0); + int pos, p = 0; + SDL_Rect from; + + /* Sign */ + if(val < 0) + { + buf[p++] = 10; + val = -val; + } + + /* Integer part */ + pos = 10000000; + while(pos > 1) + { + int num = val / pos; + val -= num * pos; + pos /= 10; + if(p || num) + buf[p++] = num; + } + + /* Decimals */ + if(val / pos) + { + buf[p++] = 11; + while(pos > 0) + { + int num = val / pos; + val -= num * pos; + pos /= 10; + buf[p++] = num; + } + } + + /* Render! */ + from.y = 0; + from.w = 7; + from.h = 10; + for(pos = 0; pos < p; ++pos) + { + SDL_Rect to; + to.x = x + pos * 7; + to.y = y; + from.x = buf[pos] * 7; + SDL_BlitSurface(font, &from, dst, &to); + } +} + +void print_num_hex(SDL_Surface *dst, SDL_Surface *font, int x, int y, unsigned val) +{ + char buf[8]; + int pos, p = 0; + SDL_Rect from; + + //val = htonl(val); // Big-endian + + /* Render! */ + from.y = 0; + from.w = 7; + from.h = 10; + for(pos = 0; pos < 8; ++pos) + { + SDL_Rect to; + to.x = 8 * 7 - (x + pos * 7); // Little-endian number wrapped backwards + to.y = y; + from.x = ( ( val >> (pos * 4) ) & 0xf ) * 7; + SDL_BlitSurface(font, &from, dst, &to); + } +} + +/*---------------------------------------------------------- + ballfield_t functions +----------------------------------------------------------*/ + +ballfield_t *ballfield_init(void) +{ + int i; + ballfield_t *bf = (ballfield_t *)calloc(sizeof(ballfield_t), 1); + if(!bf) + return NULL; + for(i = 0; i < BALLS; ++i) + { + bf->points[i].x = rand() % 0x20000; + bf->points[i].y = rand() % 0x20000; + bf->points[i].z = 0x20000 * i / BALLS; + if(rand() % 100 > 80) + bf->points[i].c = 1; + else + bf->points[i].c = 0; + } + return bf; +} + + +void ballfield_free(ballfield_t *bf) +{ + int i; + for(i = 0; i < COLORS; ++i) + SDL_FreeSurface(bf->gfx[i]); +} + + +static int ballfield_init_frames(ballfield_t *bf) +{ + int i, j; + /* + * Set up source rects for all frames + */ + bf->frames = (SDL_Rect *)calloc(sizeof(SDL_Rect), bf->gfx[0]->w); + if(!bf->frames) + { + fprintf(stderr, "No memory for frame rects!\n"); + return -1; + } + for(j = 0, i = 0; i < bf->gfx[0]->w; ++i) + { + bf->frames[i].x = 0; + bf->frames[i].y = j; + bf->frames[i].w = bf->gfx[0]->w - i; + bf->frames[i].h = bf->gfx[0]->w - i; + j += bf->gfx[0]->w - i; + } + return 0; +} + + +int ballfield_load_gfx(ballfield_t *bf, char *name, unsigned int color) +{ + if(color >= COLORS) + return -1; + + bf->gfx[color] = load_zoomed(name, bf->use_alpha); + if(!bf->gfx[color]) + return -2; + + if(!bf->frames) + return ballfield_init_frames(bf); + + return 0; +} + + +void ballfield_move(ballfield_t *bf, Sint32 dx, Sint32 dy, Sint32 dz) +{ + int i; + for(i = 0; i < BALLS; ++i) + { + bf->points[i].x += dx; + bf->points[i].x &= 0x1ffff; + bf->points[i].y += dy; + bf->points[i].y &= 0x1ffff; + bf->points[i].z += dz; + bf->points[i].z &= 0x1ffff; + } +} + + +void ballfield_render(ballfield_t *bf, SDL_Surface *screen) +{ + int i, j, z; + + /* + * Find the ball with the highest Z. + */ + z = 0; + j = 0; + for(i = 0; i < BALLS; ++i) + { + if(bf->points[i].z > z) + { + j = i; + z = bf->points[i].z; + } + } + + /* + * Render all balls in back->front order. + */ + for(i = 0; i < BALLS; ++i) + { + SDL_Rect r; + int f; + z = bf->points[j].z; + z += 50; + f = ((bf->frames[0].w << 12) + 100000) / z; + f = bf->frames[0].w - f; + if(f < 0) + f = 0; + else if(f > bf->frames[0].w - 1) + f = bf->frames[0].w - 1; + z >>= 7; + z += 1; + r.x = (bf->points[j].x - 0x10000) / z; + r.y = (bf->points[j].y - 0x10000) / z; + r.x += (screen->w - bf->frames[f].w) >> 1; + r.y += (screen->h - bf->frames[f].h) >> 1; + SDL_BlitSurface(bf->gfx[bf->points[j].c], + &bf->frames[f], screen, &r); + if(--j < 0) + j = BALLS - 1; + } +} + + + +/*---------------------------------------------------------- + Other rendering functions +----------------------------------------------------------*/ + +/* + * Draw tiled background image with offset. + */ +void tiled_back(SDL_Surface *back, SDL_Surface *screen, int xo, int yo) +{ + /* + int x, y; + SDL_Rect r; + if(xo < 0) + xo += back->w*(-xo/back->w + 1); + if(yo < 0) + yo += back->h*(-yo/back->h + 1); + xo %= back->w; + yo %= back->h; + for(y = -yo; y < screen->h; y += back->h) + for(x = -xo; x < screen->w; x += back->w) + { + r.x = x; + r.y = y; + SDL_BlitSurface(back, NULL, screen, &r); + } + */ + SDL_Rect r; + xo %= back->w/8; + yo %= back->h/8; + r.x = xo - back->w/2 + screen->w/2; + r.y = yo - back->h/2 + screen->h/2; + r.w = back->w; + r.h = back->h; + SDL_BlitSurface(back, NULL, screen, &r); +} + + + +/*---------------------------------------------------------- + main() +----------------------------------------------------------*/ + + +int main(int argc, char* argv[]) +{ + ballfield_t *balls; + SDL_Surface *screen; + SDL_Surface *temp_image; + SDL_Surface *back, *logo, *font, *font_hex; + SDL_Event event; + int bpp = 32, + flags = 0, + alpha = 1; + int x_offs = 0, y_offs = 0; + long tick, + last_tick, + last_avg_tick; + double t = 0; + float dt; + int i; + float fps = 0.0; + int fps_count = 0; + int fps_start = 0; + float x_speed, y_speed, z_speed; + + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); + + atexit(SDL_Quit); + + screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, bpp, flags); + if(!screen) + { + fprintf(stderr, "Failed to open screen!\n"); + exit(-1); + } + + SDL_WM_SetCaption("Ballfield", "Ballfield"); + if(flags & SDL_FULLSCREEN) + SDL_ShowCursor(0); + + balls = ballfield_init(); + if(!balls) + { + fprintf(stderr, "Failed to create ballfield!\n"); + exit(-1); + } + + /* + * Load and prepare balls... + */ + balls->use_alpha = alpha; + if( ballfield_load_gfx(balls, "blueball.png", 0) + || + ballfield_load_gfx(balls, "redball.png", 1) ) + { + fprintf(stderr, "Could not load balls!\n"); + exit(-1); + } + + /* + * Load background image + */ + temp_image = IMG_Load("sun.gif"); + if(!temp_image) + { + fprintf(stderr, "Could not load background!\n"); + exit(-1); + } + back = SDL_DisplayFormat(temp_image); + SDL_FreeSurface(temp_image); + + /* + * Load logo + */ + temp_image = SDL_LoadBMP("logo.bmp"); + if(!temp_image) + { + fprintf(stderr, "Could not load logo!\n"); + exit(-1); + } + SDL_SetColorKey(temp_image, SDL_SRCCOLORKEY, + SDL_MapRGB(temp_image->format, 255, 0, 255)); + logo = SDL_DisplayFormat(temp_image); + SDL_FreeSurface(temp_image); + + /* + * Load font + */ + temp_image = SDL_LoadBMP("font7x10.bmp"); + if(!temp_image) + { + fprintf(stderr, "Could not load font!\n"); + exit(-1); + } + SDL_SetColorKey(temp_image, SDL_SRCCOLORKEY, + SDL_MapRGB(temp_image->format, 255, 0, 255)); + font = SDL_DisplayFormat(temp_image); + SDL_FreeSurface(temp_image); + + temp_image = SDL_LoadBMP("font7x10-hex.bmp"); + if(!temp_image) + { + fprintf(stderr, "Could not load hex font!\n"); + exit(-1); + } + SDL_SetColorKey(temp_image, SDL_SRCCOLORKEY, + SDL_MapRGB(temp_image->format, 255, 0, 255)); + font_hex = SDL_DisplayFormat(temp_image); + SDL_FreeSurface(temp_image); + + last_avg_tick = last_tick = SDL_GetTicks(); + + enum { MAX_POINTERS = 16, PTR_PRESSED = 4 }; + int touchPointers[MAX_POINTERS][5]; + + memset(touchPointers, 0, sizeof(touchPointers)); + SDL_Joystick * joysticks[MAX_POINTERS+1]; + for(i=0; i>11, y_offs>>11); + + /* Ballfield */ + ballfield_render(balls, screen); + + /* Logo */ + r.x = 2; + r.y = 2; + SDL_BlitSurface(logo, NULL, screen, &r); + + /* FPS counter */ + if(tick > fps_start + 500) + { + fps = (float)fps_count * 1000.0 / (tick - fps_start); + fps_count = 0; + fps_start = tick; + } + ++fps_count; + + for(i=0; i= 24 ) { - PixelFormatEnumAlpha = SDL_PIXELFORMAT_RGBA8888; - PixelFormatEnumColorkey = SDL_PIXELFORMAT_RGBA8888; + PixelFormatEnumAlpha = SDL_PIXELFORMAT_ABGR8888; + PixelFormatEnumColorkey = SDL_PIXELFORMAT_ABGR8888; } SDL_memset(&alphaFormat, 0, sizeof(alphaFormat)); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c b/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c index 62d88ecf9..6bac554f2 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c @@ -133,7 +133,7 @@ SDL_RenderDriver GL_ES_RenderDriver = { SDL_PIXELFORMAT_RGBA5551, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB24, - SDL_PIXELFORMAT_RGBA8888}, + SDL_PIXELFORMAT_ABGR8888}, 0, 0} };