volmetrics

view src/main.cc @ 7:5455c9723d9e

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