textpsys
view src/main.cc @ 3:b1c8d2784c72
made the timer internal to the effect, fx_draw doesn't take a time value any more
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 20 Aug 2015 06:40:23 +0300 |
parents | 4b1360a5d54d |
children |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #ifndef __APPLE__
5 #include <GL/glut.h>
6 #else
7 #include <GLUT/glut.h>
8 #endif
9 #include "effect.h"
11 void display();
12 void idle();
13 void reshape(int x, int y);
14 void keyboard(unsigned char key, int x, int y);
15 bool parse_args(int argc, char **argv);
17 static int win_width = 1280, win_height = 800;
18 static bool fullscreen;
20 int main(int argc, char **argv)
21 {
22 glutInit(&argc, argv);
23 if(!parse_args(argc, argv)) {
24 return 1;
25 }
26 glutInitWindowSize(win_width, win_height);
27 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
28 glutCreateWindow("textbomb");
30 if(fullscreen) {
31 glutFullScreen();
32 }
34 glutDisplayFunc(display);
35 glutIdleFunc(idle);
36 glutReshapeFunc(reshape);
37 glutKeyboardFunc(keyboard);
39 if(!fx_init()) {
40 return 1;
41 }
42 atexit(fx_cleanup);
44 glutMainLoop();
45 return 0;
46 }
48 void display()
49 {
50 glClear(GL_COLOR_BUFFER_BIT);
52 fx_draw();
54 glutSwapBuffers();
55 assert(glGetError() == GL_NO_ERROR);
56 }
58 void idle()
59 {
60 glutPostRedisplay();
61 }
63 void reshape(int x, int y)
64 {
65 float aspect = (float)x / (float)y;
67 glViewport(0, 0, x, y);
69 glMatrixMode(GL_PROJECTION);
70 glLoadIdentity();
71 glScalef(1.0 / aspect, 1.0, 1.0);
72 }
74 void keyboard(unsigned char key, int x, int y)
75 {
76 switch(key) {
77 case 27:
78 exit(0);
80 case 'f':
81 case 'F':
82 fullscreen = !fullscreen;
83 if(fullscreen) {
84 glutFullScreen();
85 } else {
86 glutReshapeWindow(win_width, win_height);
87 }
88 break;
89 }
90 }
92 bool parse_args(int argc, char **argv)
93 {
94 for(int i=1; i<argc; i++) {
95 if(argv[i][0] == '-' && argv[i][2] == 0) {
96 switch(argv[i][1]) {
97 case 'f':
98 fullscreen = true;
99 break;
101 case 's':
102 if(sscanf(argv[++i], "%dx%d", &win_width, &win_height) != 2) {
103 fprintf(stderr, "-s must be followed by a resolution WxH\n");
104 return false;
105 }
106 break;
108 case 'h':
109 printf("options:\n");
110 printf(" -s WxH set window size\n");
111 printf(" -f fullscreen\n");
112 printf(" -h print this usage info and exit\n");
113 exit(0);
115 default:
116 fprintf(stderr, "invalid option: %s\n", argv[i]);
117 return false;
118 }
119 } else {
120 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
121 return false;
122 }
123 }
124 return true;
125 }