[AD] File to test different screen modes

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I don't know if anyone is interested in this, but I have attached a small
example file that I found very useful while developing my Allegro port.  I
found that getting a graphics driver that would work just right with lots
of different screen resolutions, screen depths and windowed -vs- full
screen modes, and that would also successfully be able to allow code to
*read* from the screen, was quite difficult.

This is because I was using slightly different methods of accessing the
screen memory depending on the depth and resolution, in order to allow
direct screen access in modes where it was allowed, while using an off
screen bitmap in modes where it wasn't.

Getting all of these modes to work *and* to be able to successfully read
back from the memory was quite tricky.  This test is a good regression test
to make sure you have everything working right (and that it stays working
if you change anything).

I don't know if anyone is interested, but it's attached if you are.  I've
tried to follow the Allegro coding style.

-- 
/-------------------------------------------------------------------\
[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2    ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne      ]
[Assembly Language: The most fun you can have with your clothes on! ]
\-------------------------------------------------------------------/
/*
 *    Example program for the Allegro library, by Colin Ward.
 *
 *    This is an example that developers might find useful when writing new ports
 *    of Allegro.  It will set the graphics mode to a number of different depths
 *    and resolutions, and will draw rectangles onto the screen and will then copy
 *    those rectangles around.  This will help developers to ensure that their
 *    graphics driver is able to handle different depths and resolutions, and that
 *    they can also successfully read from a graphics surface.
 */

#include <allegro.h>

/* This structure describes the screens or windows to be opened for testing */
typedef struct SCREENTEST {
   int width;
   int	height;
   int	depth;
   int fullscreen;
} SCREENTEST;

static SCREENTEST testscreens[] = {
   { 320, 200, 8, 0 }, { 640, 480, 8, 0 }, { 320, 200, 15, 0 }, { 640, 480, 15, 0 },
   { 320, 200, 24, 0 }, { 640, 480, 24, 0 }, { 320, 200, 32, 0 }, { 640, 480, 32, 0 },
   { 320, 200, 8, 1 }, { 640, 480, 8, 1 }, { 320, 200, 15, 1 }, { 640, 480, 15, 1 },
   { 320, 200, 24, 1 }, { 640, 480, 24, 1 }, { 320, 200, 32, 1 }, { 640, 480, 32, 1 }
};

#define NUM_SCREENTESTS (sizeof(testscreens) / sizeof(SCREENTEST))

int test_screenmode(int index)
{
   char description[256];
   int screenmode, y;

   /* set a graphics mode of the appropriate size and depth */
   set_color_depth(testscreens[index].depth);

   screenmode = (testscreens[index].fullscreen) ? GFX_AUTODETECT : GFX_AUTODETECT_WINDOWED;

   if (set_gfx_mode(screenmode, testscreens[index].width, testscreens[index].height, 0, 0) == 0) {
      /* set the color palette */
      set_palette(desktop_palette);

      /* clear the screen to white */
      clear_to_color(screen, makecol(255, 255, 255));

      /* you don't need to do this, but on some platforms (eg. Windows) things
       * will be drawn more quickly if you always acquire the screen before
       * trying to draw onto it.
       */
      acquire_screen();

      /* fill a rectangular area on the top left of the graphics surface */
      rectfill(screen, 1, 1, 49, 49, makecol(255, 0, 0));
      textout_ex(screen, font, "Filled rect", 60, 20, makecol(0, 0, 0), -1);

      /* write some text to the screen to show what the current depth and resolution are */
      sprintf(description, "Surface %d: %d x %d @ %d", index, testscreens[index].width, testscreens[index].height, testscreens[index].depth);
      textout_centre_ex(screen, font, description, SCREEN_W/2, SCREEN_H/2, makecol(0,0,0), -1);

      /* make a copy of the rectangle drawn to the left to make sure the graphcs driver is
       * able to read from the surface as well.  If it can't then it will either crash or the
       * target rectangle will be black.
       */
      y = (testscreens[index].height - 50);
      blit(screen, screen, 1, 1, 1, y, 50, 50);
      textout_ex(screen, font, "Copy of filled rect", 60, (y + 20), makecol(0, 0, 0), -1);

      /* you must always release bitmaps before calling any input functions */
      release_screen();

      /* wait for a key press and return whether it was escape */
      return((readkey() & 0xff) != 27);
   }
   else {
      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);

      return(0);
   }
}

int main(int argc, char *argv[])
{
   int index;

   /* you should always do this at the start of Allegro programs */
   if (allegro_init() != 0)
      return 1;

   /* set up the keyboard handler */
   install_keyboard(); 

   /* if a particular depth/resolution has been specified, test just that depth/resolution */
   if (argc > 1) {
      index = atoi(argv[1]);

      if ((index >= 0) && (index < (int) NUM_SCREENTESTS)) {
         test_screenmode(index);
      } else {
         printf("Test %d is out of range\n", index);
      }
   } else {
      /* otherwise test all depths and resolutions */

      for (index = 0; index < (int) NUM_SCREENTESTS; ++index) {
         if (!test_screenmode(index)) {
            break;
         }
      }
   }

   return 0;
}

END_OF_MAIN()


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/