diff options
author | Pixel <Pixel> | 2002-10-07 00:35:31 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-10-07 00:35:31 +0000 |
commit | a006ec06d4c08c8e055bd847981c84103e2a199b (patch) | |
tree | 0dc7d644b70004d96a41222b9078b3aef5883ec2 /ffx-convert.cpp | |
parent | 34faca9abee25ec4ec09e2a1b66406d5c1aa5e26 (diff) |
Interactive texture thing.
Diffstat (limited to 'ffx-convert.cpp')
-rw-r--r-- | ffx-convert.cpp | 120 |
1 files changed, 103 insertions, 17 deletions
diff --git a/ffx-convert.cpp b/ffx-convert.cpp index 45bc314..8ad0059 100644 --- a/ffx-convert.cpp +++ b/ffx-convert.cpp @@ -1,15 +1,14 @@ #include <unistd.h> +#include <SDL/SDL.h> #include "generic.h" #include "Main.h" #include "Image.h" #include "Input.h" #include "Output.h" -#define IMG_SX 256 -#define IMG_SY 256 +int IMG_SX = 128, IMG_SY = 128, BLOC_SX = 128, BLOC_SY = 128; -#define BLOC_SX 16 -#define BLOC_SY 8 +int do_swap = 0; CODE_BEGINS @@ -19,7 +18,6 @@ Color LookUp(char i) { int transform(int x, int y) { -/* int numero_bloc_x = x / BLOC_SX; int numero_bloc_y = y / BLOC_SY; @@ -29,17 +27,35 @@ int transform(int x, int y) { int by = y % BLOC_SY; return numero_bloc * BLOC_SX * BLOC_SY + by * BLOC_SX + bx; -*/ - return y * IMG_SX + x; +// return y * IMG_SX + x; } virtual int startup() throw (GeneralException) { int c; - while ((c = getopt(argc, argv, "")) != EOF) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) { + printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError()); + exit(-1); + } + atexit(SDL_Quit); + SDL_ShowCursor(SDL_DISABLE); + + while ((c = getopt(argc, argv, "x:y:z:t:")) != EOF) { switch (c) { + case 'x': + IMG_SX = atoi(optarg); + break; + case 'y': + IMG_SY = atoi(optarg); + break; + case 'z': + BLOC_SX = atoi(optarg); + break; + case 't': + BLOC_SY = atoi(optarg); + break; default: printm(M_ERROR, "Unknow option: %c\n", c); throw Exit(-1); @@ -55,25 +71,93 @@ virtual int startup() throw (GeneralException) { Output * tga = new Output(argv[optind + 1]); Image * img = new Image(IMG_SX, IMG_SY); - map->seek(0x140); - - char buffer[65536]; + char buffer[131072]; Byte b; -/* - for (int i = 0; i < 32768; i++) { + for (int i = 0; i < ((IMG_SX * IMG_SY) >> 1); i++) { int j = i << 1; map->read(&b, 1); buffer[j] = b & 0x0f; buffer[j + 1] = (b & 0xf0) >> 4; } -*/ - for (int i = 0; i < 65536; i++) { - map->read(&b, 1); - buffer[i] = b; + + SDL_Surface * screen = 0; + screen = SDL_SetVideoMode(IMG_SX * 2, IMG_SY * 2, 24, SDL_HWSURFACE | SDL_DOUBLEBUF); + if (!screen) { + printm(M_ERROR, "Couldn't get framebuffer\n"); + exit(-1); } + SDL_Event event; + + bool exitting = false; + + while (!exitting) { + Uint8 * pixels = ((Uint8 *) screen->pixels); + for (int y = 0; y < IMG_SX; y++) { + for (int x = 0; x < IMG_SY; x++) { + Color c = LookUp(buffer[transform(x, y)]); + pixels[((x * 2 + 0) * IMG_SY * 2 + (y * 2 + 0)) * 3 + 0] = c.R; + pixels[((x * 2 + 0) * IMG_SY * 2 + (y * 2 + 0)) * 3 + 1] = c.G; + pixels[((x * 2 + 0) * IMG_SY * 2 + (y * 2 + 0)) * 3 + 2] = c.B; + + pixels[((x * 2 + 0) * IMG_SY * 2 + (y * 2 + 1)) * 3 + 0] = c.R; + pixels[((x * 2 + 0) * IMG_SY * 2 + (y * 2 + 1)) * 3 + 1] = c.G; + pixels[((x * 2 + 0) * IMG_SY * 2 + (y * 2 + 1)) * 3 + 2] = c.B; + + pixels[((x * 2 + 1) * IMG_SY * 2 + (y * 2 + 0)) * 3 + 0] = c.R; + pixels[((x * 2 + 1) * IMG_SY * 2 + (y * 2 + 0)) * 3 + 1] = c.G; + pixels[((x * 2 + 1) * IMG_SY * 2 + (y * 2 + 0)) * 3 + 2] = c.B; + + pixels[((x * 2 + 1) * IMG_SY * 2 + (y * 2 + 1)) * 3 + 0] = c.R; + pixels[((x * 2 + 1) * IMG_SY * 2 + (y * 2 + 1)) * 3 + 1] = c.G; + pixels[((x * 2 + 1) * IMG_SY * 2 + (y * 2 + 1)) * 3 + 2] = c.B; + + } + } + + SDL_Flip(screen); + + SDL_WaitEvent(&event); + + switch (event.type) { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_UP: + BLOC_SY >>= 1; + break; + case SDLK_DOWN: + BLOC_SY <<= 1; + break; + case SDLK_LEFT: + BLOC_SX >>= 1; + break; + case SDLK_RIGHT: + BLOC_SX <<= 1; + break; + case SDLK_SPACE: + do_swap ^= 1; + break; + default: + break; + } + if (BLOC_SX == 0) + BLOC_SX = 1; + if (BLOC_SY == 0) + BLOC_SY = 1; + if (BLOC_SX > IMG_SX) + BLOC_SX = IMG_SX; + if (BLOC_SY > IMG_SY) + BLOC_SY = IMG_SY; + printm(M_BARE, "Bloc size = %3ix%3i\n", BLOC_SX, BLOC_SY); + break; + case SDL_QUIT: + exitting = true; + break; + } + } + img->Fill(); for (int y = 0; y < IMG_SX; y++) { @@ -86,6 +170,8 @@ virtual int startup() throw (GeneralException) { copy(img, tga); + SDL_Quit(); + return 0; } |