rev |
line source |
eleni@0
|
1 #include <GL/glew.h>
|
eleni@0
|
2 #include <GL/glut.h>
|
eleni@0
|
3
|
eleni@0
|
4 #include <stdio.h>
|
eleni@0
|
5 #include <assert.h>
|
eleni@0
|
6
|
elene@6
|
7 #include "volume.h"
|
eleni@1
|
8
|
eleni@0
|
9 //static void init(void);
|
eleni@0
|
10 static void display(void);
|
eleni@0
|
11 static void reshape(int x, int y);
|
eleni@0
|
12 static void keyboard(unsigned char key, int x, int y);
|
eleni@0
|
13 static void mouse(int button, int state, int x, int y);
|
eleni@0
|
14 static void motion(int x, int y);
|
eleni@0
|
15
|
eleni@0
|
16 static int win_xsz, win_ysz;
|
eleni@0
|
17
|
eleni@1
|
18 /////////////////////////////
|
eleni@1
|
19 // debug TODO remove
|
eleni@1
|
20 ////////////////////////////
|
eleni@1
|
21 static bool init();
|
elene@6
|
22
|
elene@6
|
23 static Volume *vol;
|
elene@6
|
24 static float cur_z;
|
eleni@1
|
25
|
eleni@0
|
26 int main(int argc, char **argv)
|
eleni@0
|
27 {
|
eleni@0
|
28 glutInit(&argc, argv);
|
elene@7
|
29 glutInitWindowSize(512, 512);
|
eleni@0
|
30 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
|
eleni@0
|
31
|
eleni@0
|
32 //TODO parse arguments
|
eleni@0
|
33
|
eleni@0
|
34 glutCreateWindow("My Colonoscopie OEO!");
|
eleni@0
|
35
|
eleni@0
|
36 glutDisplayFunc(display);
|
eleni@0
|
37 glutReshapeFunc(reshape);
|
eleni@0
|
38 glutKeyboardFunc(keyboard);
|
eleni@0
|
39 glutMouseFunc(mouse);
|
eleni@0
|
40 glutMotionFunc(motion);
|
eleni@0
|
41
|
eleni@0
|
42 glewInit();
|
eleni@1
|
43 if(!init()) {
|
eleni@1
|
44 fprintf(stderr, "Failed to initialize La votre Colonoscopie\n");
|
eleni@1
|
45 return 1;
|
eleni@1
|
46 }
|
eleni@0
|
47
|
eleni@0
|
48 //call init
|
eleni@0
|
49
|
eleni@0
|
50 glutMainLoop();
|
eleni@0
|
51 return 0;
|
eleni@0
|
52 }
|
eleni@0
|
53
|
eleni@0
|
54 void display(void)
|
eleni@0
|
55 {
|
eleni@0
|
56 //render
|
elene@6
|
57 glBindTexture(GL_TEXTURE_3D, vol->get_texture());
|
elene@6
|
58 glEnable(GL_TEXTURE_3D);
|
eleni@1
|
59 glBegin(GL_QUADS);
|
elene@6
|
60 glTexCoord3f(0, 0, cur_z); glVertex3f(-1, -1, 0);
|
elene@6
|
61 glTexCoord3f(0, 1, cur_z); glVertex3f(-1, 1, 0);
|
elene@6
|
62 glTexCoord3f(1, 1, cur_z); glVertex3f(1, 1, 0);
|
elene@6
|
63 glTexCoord3f(1, 0, cur_z); glVertex3f(1, -1, 0);
|
eleni@1
|
64 glEnd();
|
elene@6
|
65 glDisable(GL_TEXTURE_3D);
|
eleni@0
|
66
|
eleni@0
|
67 glutSwapBuffers();
|
eleni@0
|
68 assert(glGetError() == GL_NO_ERROR);
|
eleni@0
|
69 }
|
eleni@0
|
70
|
eleni@0
|
71 void reshape(int x, int y)
|
eleni@0
|
72 {
|
eleni@0
|
73 glViewport(0, 0, x, y);
|
eleni@0
|
74 if(x != win_xsz || y != win_ysz) {
|
eleni@0
|
75 //TODO raytex_needs_recalc = 1;
|
eleni@0
|
76 win_xsz = x;
|
eleni@0
|
77 win_ysz = y;
|
eleni@0
|
78 }
|
eleni@0
|
79 }
|
eleni@0
|
80
|
eleni@0
|
81 void keyboard(unsigned char key, int x, int y)
|
eleni@0
|
82 {
|
eleni@0
|
83 switch(key) {
|
eleni@0
|
84 case 27:
|
eleni@0
|
85 exit(0);
|
eleni@0
|
86 default:
|
eleni@0
|
87 break;
|
eleni@0
|
88 }
|
eleni@0
|
89 }
|
eleni@0
|
90
|
eleni@0
|
91 static int prev_x, prev_y;
|
eleni@0
|
92 void mouse(int bn, int state, int x, int y)
|
eleni@0
|
93 {
|
eleni@0
|
94 prev_x = x;
|
eleni@0
|
95 prev_y = y;
|
eleni@0
|
96 }
|
eleni@0
|
97
|
eleni@0
|
98 void motion(int x, int y)
|
eleni@0
|
99 {
|
eleni@0
|
100 int dx = x - prev_x;
|
eleni@0
|
101 int dy = y - prev_y;
|
eleni@0
|
102 prev_x = x;
|
eleni@0
|
103 prev_y = y;
|
elene@6
|
104
|
elene@6
|
105 if(dx != 0) {
|
elene@6
|
106 cur_z = (float)x / (float)win_xsz;
|
elene@6
|
107 glutPostRedisplay();
|
elene@6
|
108 }
|
eleni@0
|
109 }
|
eleni@1
|
110
|
eleni@1
|
111 bool init()
|
eleni@1
|
112 {
|
elene@6
|
113 vol = new Volume;
|
elene@6
|
114 if(!vol->load("data/test1.vol")) {
|
elene@6
|
115 fprintf(stderr, "Failed to load test1.vol");
|
eleni@1
|
116 return false;
|
eleni@1
|
117 }
|
elene@6
|
118 cur_z = 0.5;
|
eleni@1
|
119
|
eleni@1
|
120 return true;
|
eleni@1
|
121 }
|