volmetrics

view src/main.cc @ 4:1fbbe10c8e08

quick backup
author Eleni Maria Stea <elene.mst@gmail.com>
date Sat, 11 Jan 2014 23:49:58 +0200
parents 88d390af583f
children e6485ef45e6e
line source
1 #include <GL/glew.h>
2 #include <GL/glut.h>
4 #include <stdio.h>
5 #include <assert.h>
7 #include "image.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();
22 Image img;
23 unsigned int tex;
25 int main(int argc, char **argv)
26 {
27 glutInit(&argc, argv);
28 glutInitWindowSize(1280, 720);
29 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
31 //TODO parse arguments
33 glutCreateWindow("My Colonoscopie OEO!");
35 glutDisplayFunc(display);
36 glutReshapeFunc(reshape);
37 glutKeyboardFunc(keyboard);
38 glutMouseFunc(mouse);
39 glutMotionFunc(motion);
41 glewInit();
42 if(!init()) {
43 fprintf(stderr, "Failed to initialize La votre Colonoscopie\n");
44 return 1;
45 }
47 //call init
49 glutMainLoop();
50 return 0;
51 }
53 void display(void)
54 {
55 //render
56 glBindTexture(GL_TEXTURE_2D, tex);
57 glEnable(GL_TEXTURE_2D);
58 glBegin(GL_QUADS);
59 glTexCoord2f(0, 0); glVertex3f(-1, -1, 0);
60 glTexCoord2f(0, 1); glVertex3f(-1, 1, 0);
61 glTexCoord2f(1, 1); glVertex3f(1, 1, 0);
62 glTexCoord2f(1, 0); glVertex3f(1, -1, 0);
63 glEnd();
64 glDisable(GL_TEXTURE_2D);
66 glutSwapBuffers();
67 assert(glGetError() == GL_NO_ERROR);
68 }
70 void reshape(int x, int y)
71 {
72 glViewport(0, 0, x, y);
73 if(x != win_xsz || y != win_ysz) {
74 //TODO raytex_needs_recalc = 1;
75 win_xsz = x;
76 win_ysz = y;
77 }
78 }
80 void keyboard(unsigned char key, int x, int y)
81 {
82 switch(key) {
83 case 27:
84 exit(0);
85 default:
86 break;
87 }
88 }
90 static int prev_x, prev_y;
91 void mouse(int bn, int state, int x, int y)
92 {
93 prev_x = x;
94 prev_y = y;
95 }
97 void motion(int x, int y)
98 {
99 int dx = x - prev_x;
100 int dy = y - prev_y;
101 prev_x = x;
102 prev_y = y;
103 }
105 bool init()
106 {
107 if(!img.load("data/la_colonoscopie/IM-0001-0248.png")) {
108 fprintf(stderr, "Failed to load votre Colonoscopie\n");
109 return false;
110 }
112 glGenTextures(1, &tex);
113 glBindTexture(GL_TEXTURE_2D, tex);
114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
116 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, img.get_width(),
117 img.get_height(), 0, GL_LUMINANCE, GL_FLOAT, img.get_pixels());
119 return true;
120 }