textpsys

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