File: gfxinfo.c

package info (click to toggle)
allegro4.4 2:4.4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,744 kB
  • sloc: ansic: 164,458; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,107; python: 676; pascal: 179; makefile: 55; perl: 29; lisp: 1
file content (130 lines) | stat: -rw-r--r-- 3,439 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*         ______   ___    ___
 *        /\  _  \ /\_ \  /\_ \
 *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
 *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
 *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
 *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
 *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
 *                                           /\____/
 *                                           \_/__/
 *
 *      List which resolutions and color depths are available.
 *
 *      By Lorenzo Petrone.
 *
 *      See readme.txt for copyright information.
 */


#define ALLEGRO_USE_CONSOLE
#include <string.h>
#include <stdio.h>
#include "allegro.h"
#include "allegro/internal/aintern.h"



char *al_un_id(char *out, int driver_id)
{
   out[0] = (driver_id >> 24) & 0xff;
   out[1] = (driver_id >> 16) & 0xff;
   out[2] = (driver_id >> 8) & 0xff;
   out[3] = (driver_id) & 0xff;
   out[4] = '\0';
   return out;
}



int al_id_safe(char *s)
{
   int l = strlen(s);
   return AL_ID((l > 0) ? s[0] : ' ',
                (l > 1) ? s[1] : ' ',
                (l > 2) ? s[2] : ' ',
                (l > 3) ? s[3] : ' ');
}



int main(int argc, char *argv[])
{
   _DRIVER_INFO *driver_info;
   GFX_DRIVER **gfx_driver;
   GFX_MODE_LIST *gfx_mode_list;
   int driver_count, i, id;
   char buf[5];

   if (allegro_init() != 0)
      return 1;

   printf("Allegro graphics info utility " ALLEGRO_VERSION_STR ", " ALLEGRO_PLATFORM_STR "\n");
   printf("By Lorenzo Petrone, " ALLEGRO_DATE_STR "\n\n");

   if (system_driver->gfx_drivers)
      driver_info = system_driver->gfx_drivers();
   else
      driver_info = _gfx_driver_list;

   driver_count = 0;
   while (driver_info[driver_count].driver)
      driver_count++;

   gfx_driver = malloc(sizeof(GFX_DRIVER *) * driver_count);
   if (!gfx_driver)
      return 1;
   for (i = 0; i < driver_count; i++)
      gfx_driver[i] = driver_info[i].driver;

   if (argc == 1) {
      printf("No graphics driver specified.  These are available:\n\n");
      for (i = 0; i < driver_count; i++)
         printf("%s : %s\n", al_un_id(buf, gfx_driver[i]->id), gfx_driver[i]->ascii_name);
      printf("\n");
      goto end;
   }

   id = al_id_safe(argv[1]);
   for (i = 0; i < driver_count; i++) {
      if ((strcmp(gfx_driver[i]->ascii_name, argv[1]) == 0) || (gfx_driver[i]->id == id)) {
         printf("Name: %s; driver ID: %s\n", gfx_driver[i]->ascii_name, al_un_id(buf, gfx_driver[i]->id));
         break;
      }
   }

   if (i == driver_count) {
      printf("Unknown graphics driver %s.\n"
             "Run gfxinfo without parameters to see a list.\n\n", argv[1]);
      goto end;
   }

   if (gfx_driver[i]->windowed) {
      printf("This is a windowed mode driver. You can use any resolution you want.\n\n");
      goto end;
   }

   gfx_mode_list = get_gfx_mode_list(gfx_driver[i]->id);
   if (!gfx_mode_list) {
      printf("Failed to retrieve mode list. This might be because the driver\n"
             "doesn't support mode fetching.\n\n");
      goto end;
   }

   for (i = 0; i < gfx_mode_list->num_modes; i++) {
      printf("%4dx%-4d %2d bpp\n",
             gfx_mode_list->mode[i].width,
             gfx_mode_list->mode[i].height,
             gfx_mode_list->mode[i].bpp);
   }
   printf("\n");

   destroy_gfx_mode_list(gfx_mode_list);

   end:
   
   free(gfx_driver);
   
   return 0;
}

END_OF_MAIN()