glviewvol

annotate src/main.cc @ 12:773f89037a35

added copyright headers
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 31 Dec 2014 07:57:04 +0200
parents 73edd1b7c2da
children
rev   line source
nuclear@12 1 /*
nuclear@12 2 glviewvol is an OpenGL 3D volume data viewer
nuclear@12 3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>
nuclear@12 4
nuclear@12 5 This program is free software: you can redistribute it and/or modify
nuclear@12 6 it under the terms of the GNU General Public License as published by
nuclear@12 7 the Free Software Foundation, either version 3 of the License, or
nuclear@12 8 (at your option) any later version.
nuclear@12 9
nuclear@12 10 This program is distributed in the hope that it will be useful,
nuclear@12 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@12 13 GNU General Public License for more details.
nuclear@12 14
nuclear@12 15 You should have received a copy of the GNU General Public License
nuclear@12 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@12 17 */
nuclear@0 18 // GLUT frontend
nuclear@0 19 #ifdef USE_GLUT
nuclear@0 20
nuclear@0 21 #include <stdlib.h>
nuclear@0 22 #include "opengl.h"
nuclear@0 23
nuclear@0 24 #ifdef __APPLE__
nuclear@0 25 #include <GLUT/glut.h>
nuclear@0 26 #else
nuclear@0 27 #include <GL/glut.h>
nuclear@0 28 #endif
nuclear@0 29
nuclear@11 30 #include "viewer.h"
nuclear@3 31 #include "opt.h"
nuclear@0 32
nuclear@0 33 static void display();
nuclear@0 34 static void reshape(int x, int y);
nuclear@0 35 static void key_down(unsigned char key, int x, int y);
nuclear@0 36 static void key_up(unsigned char key, int x, int y);
nuclear@0 37 static void mouse(int bn, int state, int x, int y);
nuclear@0 38 static void motion(int x, int y);
nuclear@0 39
nuclear@4 40 static int win_width, win_height;
nuclear@7 41 static unsigned int mod;
nuclear@4 42
nuclear@0 43 int main(int argc, char **argv)
nuclear@0 44 {
nuclear@0 45 glutInit(&argc, argv);
nuclear@3 46
nuclear@3 47 if(parse_args(argc, argv) == -1) {
nuclear@3 48 return 1;
nuclear@3 49 }
nuclear@3 50
nuclear@6 51 glutInitWindowSize(opt.xsz, opt.ysz);
nuclear@0 52 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
nuclear@0 53 glutCreateWindow("dicom viewer");
nuclear@0 54
nuclear@0 55 glutDisplayFunc(display);
nuclear@0 56 glutReshapeFunc(reshape);
nuclear@1 57 glutKeyboardFunc(key_down);
nuclear@1 58 glutKeyboardUpFunc(key_up);
nuclear@0 59 glutMouseFunc(mouse);
nuclear@0 60 glutMotionFunc(motion);
nuclear@7 61 glutPassiveMotionFunc(motion);
nuclear@0 62
nuclear@0 63 glewInit();
nuclear@0 64
nuclear@0 65 if(init() == -1) {
nuclear@0 66 return 1;
nuclear@0 67 }
nuclear@0 68
nuclear@0 69 glutMainLoop();
nuclear@0 70 return 0;
nuclear@0 71 }
nuclear@0 72
nuclear@0 73 void swap_buffers()
nuclear@0 74 {
nuclear@0 75 glutSwapBuffers();
nuclear@0 76 }
nuclear@0 77
nuclear@0 78 void redisplay()
nuclear@0 79 {
nuclear@0 80 glutPostRedisplay();
nuclear@0 81 }
nuclear@0 82
nuclear@0 83 void quit()
nuclear@0 84 {
nuclear@0 85 cleanup();
nuclear@0 86 exit(0);
nuclear@0 87 }
nuclear@0 88
nuclear@4 89 void get_window_size(int *xsz, int *ysz)
nuclear@4 90 {
nuclear@4 91 *xsz = win_width;
nuclear@4 92 *ysz = win_height;
nuclear@4 93 }
nuclear@4 94
nuclear@7 95 unsigned int get_modifiers()
nuclear@7 96 {
nuclear@7 97 return mod;
nuclear@7 98 }
nuclear@7 99
nuclear@0 100 static void display()
nuclear@0 101 {
nuclear@0 102 ev_display();
nuclear@0 103 }
nuclear@0 104
nuclear@0 105 static void reshape(int x, int y)
nuclear@0 106 {
nuclear@4 107 win_width = x;
nuclear@4 108 win_height = y;
nuclear@0 109 ev_reshape(x, y);
nuclear@0 110 }
nuclear@0 111
nuclear@0 112 static void key_down(unsigned char key, int x, int y)
nuclear@0 113 {
nuclear@7 114 mod = glutGetModifiers();
nuclear@8 115
nuclear@8 116 switch(key) {
nuclear@8 117 case 'i':
nuclear@8 118 {
nuclear@8 119 static bool fullrate;
nuclear@8 120 fullrate = !fullrate;
nuclear@8 121 glutIdleFunc(fullrate ? glutPostRedisplay : 0);
nuclear@8 122 }
nuclear@8 123 break;
nuclear@8 124 }
nuclear@8 125
nuclear@0 126 ev_keyboard(key, 1, x, y);
nuclear@0 127 }
nuclear@0 128
nuclear@0 129 static void key_up(unsigned char key, int x, int y)
nuclear@0 130 {
nuclear@7 131 mod = glutGetModifiers();
nuclear@0 132 ev_keyboard(key, 0, x, y);
nuclear@0 133 }
nuclear@0 134
nuclear@0 135 static void mouse(int bn, int state, int x, int y)
nuclear@0 136 {
nuclear@7 137 mod = glutGetModifiers();
nuclear@0 138 ev_mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
nuclear@0 139 }
nuclear@0 140
nuclear@0 141 static void motion(int x, int y)
nuclear@0 142 {
nuclear@0 143 ev_mouse_motion(x, y);
nuclear@0 144 }
nuclear@0 145
nuclear@0 146 #endif // USE_GLUT