glviewvol
view src/main.cc @ 8:fb6d93471352
main thing done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 30 Dec 2014 20:03:32 +0200 |
parents | 71b479ffb9f7 |
children | 73edd1b7c2da |
line source
1 // GLUT frontend
2 #ifdef USE_GLUT
4 #include <stdlib.h>
5 #include "opengl.h"
7 #ifdef __APPLE__
8 #include <GLUT/glut.h>
9 #else
10 #include <GL/glut.h>
11 #endif
13 #include "dicomview.h"
14 #include "opt.h"
16 static void display();
17 static void reshape(int x, int y);
18 static void key_down(unsigned char key, int x, int y);
19 static void key_up(unsigned char key, int x, int y);
20 static void mouse(int bn, int state, int x, int y);
21 static void motion(int x, int y);
23 static int win_width, win_height;
24 static unsigned int mod;
26 int main(int argc, char **argv)
27 {
28 glutInit(&argc, argv);
30 if(parse_args(argc, argv) == -1) {
31 return 1;
32 }
34 glutInitWindowSize(opt.xsz, opt.ysz);
35 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
36 glutCreateWindow("dicom viewer");
38 glutDisplayFunc(display);
39 glutReshapeFunc(reshape);
40 glutKeyboardFunc(key_down);
41 glutKeyboardUpFunc(key_up);
42 glutMouseFunc(mouse);
43 glutMotionFunc(motion);
44 glutPassiveMotionFunc(motion);
46 glewInit();
48 if(init() == -1) {
49 return 1;
50 }
52 glutMainLoop();
53 return 0;
54 }
56 void swap_buffers()
57 {
58 glutSwapBuffers();
59 }
61 void redisplay()
62 {
63 glutPostRedisplay();
64 }
66 void quit()
67 {
68 cleanup();
69 exit(0);
70 }
72 void get_window_size(int *xsz, int *ysz)
73 {
74 *xsz = win_width;
75 *ysz = win_height;
76 }
78 unsigned int get_modifiers()
79 {
80 return mod;
81 }
83 static void display()
84 {
85 ev_display();
86 }
88 static void reshape(int x, int y)
89 {
90 win_width = x;
91 win_height = y;
92 ev_reshape(x, y);
93 }
95 static void key_down(unsigned char key, int x, int y)
96 {
97 mod = glutGetModifiers();
99 switch(key) {
100 case 'i':
101 {
102 static bool fullrate;
103 fullrate = !fullrate;
104 glutIdleFunc(fullrate ? glutPostRedisplay : 0);
105 }
106 break;
107 }
109 ev_keyboard(key, 1, x, y);
110 }
112 static void key_up(unsigned char key, int x, int y)
113 {
114 mod = glutGetModifiers();
115 ev_keyboard(key, 0, x, y);
116 }
118 static void mouse(int bn, int state, int x, int y)
119 {
120 mod = glutGetModifiers();
121 ev_mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
122 }
124 static void motion(int x, int y)
125 {
126 ev_mouse_motion(x, y);
127 }
129 #endif // USE_GLUT