volmetrics

annotate src/main.cc @ 5:92c163c939be

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