aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-14 14:53:55 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-14 14:53:55 +0000
commite90b381ac677f73d84b1d521046285c226450034 (patch)
tree8bbed2b5c8cc516d4b327df930aaa708a823482a /src/main.c
parent20d17a2ee2a90390724690e905fcddcce8422bc5 (diff)
Command-line arguments
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@13 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c69
1 files changed, 59 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index db6b260..32d7839 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,10 +14,12 @@
#endif
#include <stdlib.h>
+#include <stdarg.h>
#include <unistd.h>
#include <SDL.h>
#include <gl.h>
#include <glu.h>
+#include <assert.h>
#include "types.h"
#include "model.h"
@@ -26,12 +28,59 @@
#include "physics.h"
#include "utils.h"
+#define NOT_REACHED 0
+
+typedef enum {
+ RES_VGA,
+ RES_SXGA,
+ RES_WSXGA
+} ScreenResolution;
+
int main(int argc, char *argv[]) {
SDL_Event event;
int finished;
SDL_Surface *screen;
int width, height;
+ int c;
+ Uint32 video_flags;
+ ScreenResolution res;
+
+ res = RES_VGA;
+ video_flags = SDL_OPENGL;
+
+ while ((c = getopt(argc, argv, "hr:f")) != -1) {
+
+ switch ( c ) {
+
+ case 'r' : {
+ if ( strcasecmp(optarg, "vga") == 0 ) res = RES_VGA;
+ if ( strcasecmp(optarg, "sxga") == 0 ) res = RES_SXGA;
+ if ( strcasecmp(optarg, "wsxga") == 0 ) res = RES_WSXGA;
+ break;
+ }
+
+ case 'f' : {
+ video_flags = video_flags | SDL_FULLSCREEN;
+ break;
+ }
+
+ case 'h' : {
+ printf("Syntax: %s [-h] [-r <res>] [-f]\n\n", argv[0]);
+ printf("A silly game.\n\n");
+ printf(" -h Display this help message.\n");
+ printf(" -r <res> Set display resolution. <res> can be one of: vga, sxga or wsxga.\n");
+ printf(" -f Use the full screen.\n");
+ return 0;
+ }
+
+ default : {
+ return 1;
+ }
+
+ }
+
+ }
/* SDL initial setup */
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 ) {
@@ -42,17 +91,17 @@ int main(int argc, char *argv[]) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- width = 1680; height = 1050;
- width=640;height=480;
- screen = SDL_SetVideoMode(width, height, 16, SDL_OPENGL);// | SDL_FULLSCREEN);
+ switch ( res ) {
+ case RES_VGA : { width = 640; height = 480; break; }
+ case RES_SXGA : { width = 1280; height = 1024; break; }
+ case RES_WSXGA : { width = 1680; height = 1050; break; }
+ default : { assert(NOT_REACHED); break; }
+ }
+ screen = SDL_SetVideoMode(width, height, 16, video_flags);
if ( screen == NULL ) {
- width = 1280; height = 1024;
- screen = SDL_SetVideoMode(width, height, 16, SDL_OPENGL | SDL_FULLSCREEN);
- if (screen == NULL) {
- fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
- SDL_Quit();
- return 1;
- }
+ fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
+ SDL_Quit();
+ return 1;
}
SDL_WM_SetCaption("Thrust3D", "Thrust3D");