Updated the README and removed the old graywin test
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jan 2012 22:30:27 -0500
changeset 6264a388f8fd2388
parent 6263 8f3cd223a343
child 6265 01bf72bcad1e
Updated the README and removed the old graywin test
test/README
test/graywin.c
     1.1 --- a/test/README	Sun Jan 22 22:29:50 2012 -0500
     1.2 +++ b/test/README	Sun Jan 22 22:30:27 2012 -0500
     1.3 @@ -2,20 +2,12 @@
     1.4  These are test programs for the SDL library:
     1.5  
     1.6  	checkkeys	Watch the key events to check the keyboard
     1.7 -	graywin		Display a gray gradient and center mouse on spacebar
     1.8  	loopwave	Audio test -- loop playing a WAV file
     1.9 -	testalpha	Display an alpha faded icon -- paint with mouse
    1.10  	testaudioinfo	Lists audio device capabilities
    1.11 -	testbitmap	Test displaying 1-bit bitmaps
    1.12 -	testblitspeed	Tests performance of SDL's blitters and converters.
    1.13  	testcdrom	Sample audio CD control program
    1.14 -	testcursor	Tests custom mouse cursor
    1.15 -	testdyngl	Tests dynamically loading OpenGL library
    1.16  	testerror	Tests multi-threaded error handling
    1.17  	testfile	Tests RWops layer
    1.18 -	testgamma	Tests video device gamma ramp
    1.19 -	testgl		A very simple example of using OpenGL with SDL
    1.20 -	testgl2		An even simpler example using the SDL 2.0 API
    1.21 +	testgl2		A very simple example of using OpenGL with SDL
    1.22  	testhread	Hacked up test of multi-threading
    1.23  	testiconv	Tests international string conversion
    1.24  	testjoystick	List joysticks and watch joystick events
    1.25 @@ -23,19 +15,13 @@
    1.26  	testloadso	Tests the loadable library layer
    1.27  	testlock	Hacked up test of multi-threading and locking
    1.28  	testmultiaudio	Tests using several audio devices
    1.29 -	testoverlay	Tests the software/hardware overlay functionality.
    1.30  	testoverlay2	Tests the overlay flickering/scaling during playback.
    1.31  	testpalette	Tests palette color cycling
    1.32  	testplatform	Tests types, endianness and cpu capabilities
    1.33  	testsem		Tests SDL's semaphore implementation
    1.34  	testshape	Tests shaped windows
    1.35 -	testsprite	Example of fast sprite movement on the screen
    1.36 -	testsprite2	Improved version of testsprite
    1.37 +	testsprite2	Example of fast sprite movement on the screen
    1.38  	testtimer	Test the timer facilities
    1.39  	testver		Check the version and dynamic loading and endianness
    1.40 -	testvidinfo	Show the pixel format of the display and perfom the benchmark
    1.41 -	testwin		Display a BMP image at various depths
    1.42 -	testwm		Test window manager -- title, icon, events
    1.43 -	testwm2		Improved version of testwm
    1.44 -	threadwin	Test multi-threaded event handling
    1.45 +	testwm2		Test window manager -- title, icon, events
    1.46  	torturethread	Simple test for thread creation/destruction
     2.1 --- a/test/graywin.c	Sun Jan 22 22:29:50 2012 -0500
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,259 +0,0 @@
     2.4 -/*
     2.5 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     2.6 -
     2.7 -  This software is provided 'as-is', without any express or implied
     2.8 -  warranty.  In no event will the authors be held liable for any damages
     2.9 -  arising from the use of this software.
    2.10 -
    2.11 -  Permission is granted to anyone to use this software for any purpose,
    2.12 -  including commercial applications, and to alter it and redistribute it
    2.13 -  freely.
    2.14 -*/
    2.15 -
    2.16 -/* Simple program:  Fill a colormap with gray and stripe it down the screen */
    2.17 -
    2.18 -#include <stdio.h>
    2.19 -#include <stdlib.h>
    2.20 -#include <string.h>
    2.21 -#include <time.h>
    2.22 -
    2.23 -#include "SDL.h"
    2.24 -
    2.25 -#ifdef TEST_VGA16               /* Define this if you want to test VGA 16-color video modes */
    2.26 -#define NUM_COLORS	16
    2.27 -#else
    2.28 -#define NUM_COLORS	256
    2.29 -#endif
    2.30 -
    2.31 -/* Draw a randomly sized and colored box centered about (X,Y) */
    2.32 -void
    2.33 -DrawBox(SDL_Surface * screen, int X, int Y, int width, int height)
    2.34 -{
    2.35 -    static unsigned int seeded = 0;
    2.36 -    SDL_Rect area;
    2.37 -    Uint32 color;
    2.38 -    Uint32 randc;
    2.39 -
    2.40 -    /* Seed the random number generator */
    2.41 -    if (seeded == 0) {
    2.42 -        srand((unsigned int)time(NULL));
    2.43 -        seeded = 1;
    2.44 -    }
    2.45 -
    2.46 -    /* Get the bounds of the rectangle */
    2.47 -    area.w = (rand() % width);
    2.48 -    area.h = (rand() % height);
    2.49 -    area.x = X - (area.w / 2);
    2.50 -    area.y = Y - (area.h / 2);
    2.51 -    randc = (rand() % NUM_COLORS);
    2.52 -
    2.53 -    if (screen->format->BytesPerPixel == 1) {
    2.54 -        color = randc;
    2.55 -    } else {
    2.56 -        color = SDL_MapRGB(screen->format, randc, randc, randc);
    2.57 -    }
    2.58 -
    2.59 -    /* Do it! */
    2.60 -    SDL_FillRect(screen, &area, color);
    2.61 -    if (screen->flags & SDL_DOUBLEBUF) {
    2.62 -        SDL_Flip(screen);
    2.63 -    } else {
    2.64 -        SDL_UpdateRects(screen, 1, &area);
    2.65 -    }
    2.66 -}
    2.67 -
    2.68 -void
    2.69 -DrawBackground(SDL_Surface * screen)
    2.70 -{
    2.71 -    int i, j, k;
    2.72 -    Uint8 *buffer;
    2.73 -    Uint16 *buffer16;
    2.74 -    Uint16 color;
    2.75 -    Uint8 gradient;
    2.76 -
    2.77 -    /* Set the surface pixels and refresh! */
    2.78 -    /* Use two loops in case the surface is double-buffered (both sides) */
    2.79 -
    2.80 -    for (j = 0; j < 2; ++j) {
    2.81 -        if (SDL_LockSurface(screen) < 0) {
    2.82 -            fprintf(stderr, "Couldn't lock display surface: %s\n",
    2.83 -                    SDL_GetError());
    2.84 -            return;
    2.85 -        }
    2.86 -        buffer = (Uint8 *) screen->pixels;
    2.87 -
    2.88 -        if (screen->format->BytesPerPixel != 2) {
    2.89 -            for (i = 0; i < screen->h; ++i) {
    2.90 -                memset(buffer, (i * (NUM_COLORS - 1)) / screen->h,
    2.91 -                       screen->w * screen->format->BytesPerPixel);
    2.92 -                buffer += screen->pitch;
    2.93 -            }
    2.94 -        } else {
    2.95 -            for (i = 0; i < screen->h; ++i) {
    2.96 -                gradient = ((i * (NUM_COLORS - 1)) / screen->h);
    2.97 -                color =
    2.98 -                    SDL_MapRGB(screen->format, gradient, gradient, gradient);
    2.99 -                buffer16 = (Uint16 *) buffer;
   2.100 -                for (k = 0; k < screen->w; k++) {
   2.101 -                    *(buffer16 + k) = color;
   2.102 -                }
   2.103 -                buffer += screen->pitch;
   2.104 -            }
   2.105 -        }
   2.106 -
   2.107 -        SDL_UnlockSurface(screen);
   2.108 -        if (screen->flags & SDL_DOUBLEBUF) {
   2.109 -            SDL_Flip(screen);
   2.110 -        } else {
   2.111 -            SDL_UpdateRect(screen, 0, 0, 0, 0);
   2.112 -            break;
   2.113 -        }
   2.114 -    }
   2.115 -}
   2.116 -
   2.117 -SDL_Surface *
   2.118 -CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
   2.119 -{
   2.120 -    SDL_Surface *screen;
   2.121 -    int i;
   2.122 -    SDL_Color palette[NUM_COLORS];
   2.123 -
   2.124 -    /* Set the video mode */
   2.125 -    screen = SDL_SetVideoMode(w, h, bpp, flags);
   2.126 -    if (screen == NULL) {
   2.127 -        fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
   2.128 -        return (NULL);
   2.129 -    }
   2.130 -    fprintf(stderr, "Screen is in %s mode\n",
   2.131 -            (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
   2.132 -
   2.133 -    if (bpp == 8) {
   2.134 -        /* Set a gray colormap, reverse order from white to black */
   2.135 -        for (i = 0; i < NUM_COLORS; ++i) {
   2.136 -            palette[i].r = (NUM_COLORS - 1) - i * (256 / NUM_COLORS);
   2.137 -            palette[i].g = (NUM_COLORS - 1) - i * (256 / NUM_COLORS);
   2.138 -            palette[i].b = (NUM_COLORS - 1) - i * (256 / NUM_COLORS);
   2.139 -        }
   2.140 -        SDL_SetColors(screen, palette, 0, NUM_COLORS);
   2.141 -    }
   2.142 -
   2.143 -    return (screen);
   2.144 -}
   2.145 -
   2.146 -int
   2.147 -main(int argc, char *argv[])
   2.148 -{
   2.149 -    SDL_Surface *screen;
   2.150 -    Uint32 videoflags;
   2.151 -    int done;
   2.152 -    SDL_Event event;
   2.153 -    int width, height, bpp;
   2.154 -
   2.155 -    /* Initialize SDL */
   2.156 -    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   2.157 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   2.158 -        exit(1);
   2.159 -    }
   2.160 -
   2.161 -    /* See if we try to get a hardware colormap */
   2.162 -    width = 640;
   2.163 -    height = 480;
   2.164 -    bpp = 8;
   2.165 -    videoflags = SDL_SWSURFACE;
   2.166 -    while (argc > 1) {
   2.167 -        --argc;
   2.168 -        if (argv[argc - 1] && (strcmp(argv[argc - 1], "-width") == 0)) {
   2.169 -            width = atoi(argv[argc]);
   2.170 -            --argc;
   2.171 -        } else if (argv[argc - 1]
   2.172 -                   && (strcmp(argv[argc - 1], "-height") == 0)) {
   2.173 -            height = atoi(argv[argc]);
   2.174 -            --argc;
   2.175 -        } else if (argv[argc - 1] && (strcmp(argv[argc - 1], "-bpp") == 0)) {
   2.176 -            bpp = atoi(argv[argc]);
   2.177 -            --argc;
   2.178 -        } else if (argv[argc] && (strcmp(argv[argc], "-hw") == 0)) {
   2.179 -            videoflags |= SDL_HWSURFACE;
   2.180 -        } else if (argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0)) {
   2.181 -            videoflags |= SDL_HWPALETTE;
   2.182 -        } else if (argv[argc] && (strcmp(argv[argc], "-flip") == 0)) {
   2.183 -            videoflags |= SDL_DOUBLEBUF;
   2.184 -        } else if (argv[argc] && (strcmp(argv[argc], "-noframe") == 0)) {
   2.185 -            videoflags |= SDL_NOFRAME;
   2.186 -        } else if (argv[argc] && (strcmp(argv[argc], "-resize") == 0)) {
   2.187 -            videoflags |= SDL_RESIZABLE;
   2.188 -        } else if (argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0)) {
   2.189 -            videoflags |= SDL_FULLSCREEN;
   2.190 -        } else {
   2.191 -            fprintf(stderr,
   2.192 -                    "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-flip] [-noframe] [-fullscreen] [-resize]\n",
   2.193 -                    argv[0]);
   2.194 -            exit(1);
   2.195 -        }
   2.196 -    }
   2.197 -
   2.198 -    /* Set a video mode */
   2.199 -    screen = CreateScreen(width, height, bpp, videoflags);
   2.200 -    if (screen == NULL) {
   2.201 -        exit(2);
   2.202 -    }
   2.203 -
   2.204 -    DrawBackground(screen);
   2.205 -
   2.206 -    /* Wait for a keystroke */
   2.207 -    done = 0;
   2.208 -    while (!done && SDL_WaitEvent(&event)) {
   2.209 -        switch (event.type) {
   2.210 -        case SDL_MOUSEBUTTONDOWN:
   2.211 -            DrawBox(screen, event.button.x, event.button.y, width, height);
   2.212 -            break;
   2.213 -        case SDL_KEYDOWN:
   2.214 -            /* Ignore ALT-TAB for windows */
   2.215 -            if ((event.key.keysym.sym == SDLK_LALT) ||
   2.216 -                (event.key.keysym.sym == SDLK_TAB)) {
   2.217 -                break;
   2.218 -            }
   2.219 -            /* Center the mouse on <SPACE> */
   2.220 -            if (event.key.keysym.sym == SDLK_SPACE) {
   2.221 -                SDL_WarpMouse(width / 2, height / 2);
   2.222 -                break;
   2.223 -            }
   2.224 -            /* Toggle fullscreen mode on <RETURN> */
   2.225 -            if (event.key.keysym.sym == SDLK_RETURN) {
   2.226 -                videoflags ^= SDL_FULLSCREEN;
   2.227 -                screen = CreateScreen(screen->w, screen->h,
   2.228 -                                      screen->format->BitsPerPixel,
   2.229 -                                      videoflags);
   2.230 -                if (screen == NULL) {
   2.231 -                    fprintf(stderr, "Couldn't toggle fullscreen mode\n");
   2.232 -                    done = 1;
   2.233 -                }
   2.234 -                DrawBackground(screen);
   2.235 -                break;
   2.236 -            }
   2.237 -            /* Any other key quits the application... */
   2.238 -        case SDL_QUIT:
   2.239 -            done = 1;
   2.240 -            break;
   2.241 -        case SDL_VIDEOEXPOSE:
   2.242 -            DrawBackground(screen);
   2.243 -            break;
   2.244 -        case SDL_VIDEORESIZE:
   2.245 -            printf("Screen resized to %dx%d\n", event.resize.w,
   2.246 -                   event.resize.h);
   2.247 -            screen =
   2.248 -                CreateScreen(event.resize.w, event.resize.h,
   2.249 -                             screen->format->BitsPerPixel, videoflags);
   2.250 -            if (screen == NULL) {
   2.251 -                fprintf(stderr, "Couldn't resize video mode\n");
   2.252 -                done = 1;
   2.253 -            }
   2.254 -            DrawBackground(screen);
   2.255 -            break;
   2.256 -        default:
   2.257 -            break;
   2.258 -        }
   2.259 -    }
   2.260 -    SDL_Quit();
   2.261 -    return (0);
   2.262 -}