home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / carterrain / src / splash.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-17  |  4.2 KB  |  148 lines

  1. #include <allegro.h>
  2. #include <alleggl.h>
  3.  
  4. static int mode = AGL_FULLSCREEN, width, height;
  5.  
  6. struct resolution_entry {
  7.     int w,h;
  8.     char *s;
  9. } resolutions[] = {
  10.     {  640,  480, " 640x480 "  },
  11.     {  800,  600, " 800x600 "  },
  12.     { 1024,  768, "1024x768 "  },
  13.     { 1280, 1024, "1280x1024" },
  14.     { 1600, 1200, "1600x1200" }
  15. };
  16.  
  17. static char *resolution_lister (int i, int *size)
  18. {
  19.     if (i < 0) {
  20.         *size = sizeof resolutions / sizeof *resolutions;
  21.         return NULL;
  22.     }
  23.     return resolutions[i].s;
  24. }
  25.  
  26.  
  27.  
  28. struct colour_depth_entry {
  29.     int depth;
  30.     char *s;
  31. } colour_depths[] = {
  32.     { 15, "15 bpp" },
  33.     { 16, "16 bpp" },
  34.     { 24, "24 bpp" },
  35.     { 32, "32 bpp" }
  36. };
  37.  
  38. static char *colour_depth_lister (int i, int *size)
  39. {
  40.     if (i < 0) {
  41.         *size = sizeof colour_depths / sizeof *colour_depths;
  42.         return NULL;
  43.     }
  44.     return colour_depths[i].s;
  45. }
  46.  
  47. struct zbuffer_depth_entry {
  48.     int depth;
  49.     char *s;
  50. } zbuffer_depths[] = {
  51.     {  8, " 8 bpp" },
  52.     { 16, "16 bpp" },
  53.     { 24, "24 bpp" },
  54.     { 32, "32 bpp" }
  55. };
  56.  
  57. static char *zbuffer_depth_lister (int i, int *size)
  58. {
  59.     if (i < 0) {
  60.         *size = sizeof zbuffer_depths / sizeof *zbuffer_depths;
  61.         return NULL;
  62.     }
  63.     return zbuffer_depths[i].s;
  64. }
  65.  
  66.  
  67. static int setup (void)
  68. {
  69. #define RESOLUTION_LIST   4
  70. #define COLOUR_LIST       6
  71. #define ZBUFFER_LIST      8
  72. #define WINDOWED_BOX      9
  73. #define DOUBLEBUFFER_BOX 10
  74. #define BUTTON_OK        11
  75.     
  76.     DIALOG dlg[] = {
  77.     /*    proc                 x    y    w    h  fg bg  key    flags d1 d2  dp */
  78.     {    d_shadow_box_proc,   0,   0, 320, 200,  0, 0,   0,         0, 0, 0, NULL },
  79.     {    d_ctext_proc,      160,  10,   0,   0,  0, 0,   0,         0, 0, 0, (char*)"______________________________" },
  80.     {    d_ctext_proc,      160,   8,   0,   0,  0, 0,   0,         0, 0, 0, (char*)"carterrain OpenGL window setup" },
  81.     {    d_text_proc,        10,  30,   0,   0,  0, 0,   0,         0, 0, 0, (char*)"Resolution" },
  82.     {    d_list_proc,        10,  40,  96,  48,  0, 0,   0,         0, 1, 0, resolution_lister },
  83.     {    d_text_proc,       120,  30,   0,   0,  0, 0,   0,         0, 0, 0, (char*)"Colour depth" },
  84.     {    d_list_proc,       120,  40,  96,  48,  0, 0,   0,         0, 1, 0, colour_depth_lister },
  85.     {    d_text_proc,        10, 104,  96,  48,  0, 0,   0,         0, 0, 0, (char*)"Z-buffer depth" },
  86.     {    d_list_proc,        10, 114,  96,  48,  0, 0,   0,         0, 1, 0, zbuffer_depth_lister },
  87.     {    d_check_proc,       10, 170,  96,   8,  0, 0,   0,         0, 1, 0, (char*)"Windowed" },
  88.     {    d_check_proc,       10, 180, 128,   8,  0, 0,   0,D_SELECTED, 1, 0, (char*)"Double Buffered" },
  89.     {    d_button_proc,     220, 150,  96,  18,  0, 0,   0,    D_EXIT, 0, 0, (char*)"Ok" },
  90.     {    d_button_proc,     220, 174,  96,  18,  0, 0,   0,    D_EXIT, 0, 0, (char*)"Exit" },
  91.     {    NULL }
  92.     };
  93.  
  94.     int x;
  95.  
  96.     if (mode == AGL_WINDOWED)
  97.         dlg[WINDOWED_BOX].flags |= D_SELECTED;
  98.  
  99.     centre_dialog (dlg);
  100.     set_dialog_color (dlg, makecol(0, 212, 0), makecol(0, 0, 0));
  101.         
  102.     x = do_dialog (dlg, 4);
  103.     
  104.     allegro_gl_clear_settings();
  105.     allegro_gl_set (AGL_COLOR_DEPTH, colour_depths[dlg[COLOUR_LIST].d1].depth);
  106.     allegro_gl_set (AGL_Z_DEPTH, zbuffer_depths[dlg[ZBUFFER_LIST].d1].depth);
  107.     allegro_gl_set (AGL_DOUBLEBUFFER, (dlg[DOUBLEBUFFER_BOX].flags & D_SELECTED) ? 1 : 0);
  108.     allegro_gl_set (AGL_RENDERMETHOD, 1);
  109.     mode = ((dlg[WINDOWED_BOX].flags & D_SELECTED) ? AGL_WINDOWED : AGL_FULLSCREEN);
  110.     allegro_gl_set(mode, TRUE);
  111.     allegro_gl_set(AGL_REQUIRE, AGL_RENDERMETHOD);
  112.     allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD | mode);
  113.     width  = resolutions[dlg[RESOLUTION_LIST].d1].w;
  114.     height = resolutions[dlg[RESOLUTION_LIST].d1].h;
  115.  
  116.     return (x == BUTTON_OK);
  117. }
  118.  
  119.  
  120. void splash (void)
  121. {
  122.   int ok;
  123.  
  124.   allegro_init();
  125.   install_timer();
  126.   
  127.  
  128.   set_color_depth(8);
  129.   if (set_gfx_mode (GFX_AUTODETECT_WINDOWED, 320, 200, 0, 0) < 0)
  130.     {
  131.       allegro_message ("Error setting plain graphics mode:\n%s\n", allegro_error);
  132.       exit(-1);
  133.     }
  134.   
  135.   install_allegro_gl();
  136.   
  137.   install_keyboard();
  138.   install_mouse();
  139.   ok = setup();
  140.   if(!ok)
  141.     exit(0);
  142.   set_color_depth (32);
  143.   if (set_gfx_mode(GFX_OPENGL, width, height, 0, 0) < 0) {
  144.     allegro_message ("Error setting OpenGL graphics mode:\n%s\n", allegro_error);
  145.     return;
  146.   }
  147. }  
  148.