volmetrics

diff src/main.cc @ 0:88d390af583f

Image loader
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sat, 11 Jan 2014 17:22:36 +0200
parents
children cca2e05dbabe
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main.cc	Sat Jan 11 17:22:36 2014 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +#include <GL/glew.h>
     1.5 +#include <GL/glut.h>
     1.6 +
     1.7 +#include <stdio.h>
     1.8 +#include <assert.h>
     1.9 +
    1.10 +//static void init(void);
    1.11 +static void display(void);
    1.12 +static void reshape(int x, int y);
    1.13 +static void keyboard(unsigned char key, int x, int y);
    1.14 +static void mouse(int button, int state, int x, int y);
    1.15 +static void motion(int x, int y);
    1.16 +
    1.17 +static int win_xsz, win_ysz;
    1.18 +
    1.19 +int main(int argc, char **argv)
    1.20 +{
    1.21 +	glutInit(&argc, argv);
    1.22 +	glutInitWindowSize(1280, 720);
    1.23 +	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    1.24 +
    1.25 +	//TODO parse arguments
    1.26 +
    1.27 +	glutCreateWindow("My Colonoscopie OEO!");
    1.28 +
    1.29 +	glutDisplayFunc(display);
    1.30 +	glutReshapeFunc(reshape);
    1.31 +	glutKeyboardFunc(keyboard);
    1.32 +	glutMouseFunc(mouse);
    1.33 +	glutMotionFunc(motion);
    1.34 +
    1.35 +	glewInit();
    1.36 +
    1.37 +	//call init
    1.38 +
    1.39 +	glutMainLoop();
    1.40 +	return 0;
    1.41 +}
    1.42 +
    1.43 +int init(void)
    1.44 +{
    1.45 +	//TODO
    1.46 +	return 0;
    1.47 +}
    1.48 +
    1.49 +void display(void)
    1.50 +{
    1.51 +	//render
    1.52 +
    1.53 +	glutSwapBuffers();
    1.54 +	assert(glGetError() == GL_NO_ERROR);
    1.55 +}
    1.56 +
    1.57 +void reshape(int x, int y)
    1.58 +{
    1.59 +	glViewport(0, 0, x, y);
    1.60 +	if(x != win_xsz || y != win_ysz) {
    1.61 +		//TODO raytex_needs_recalc = 1;
    1.62 +		win_xsz = x;
    1.63 +		win_ysz = y;
    1.64 +	}
    1.65 +}
    1.66 +
    1.67 +void keyboard(unsigned char key, int x, int y)
    1.68 +{
    1.69 +	switch(key) {
    1.70 +		case 27:
    1.71 +			exit(0);
    1.72 +		default:
    1.73 +			break;
    1.74 +	}
    1.75 +}
    1.76 +
    1.77 +static int prev_x, prev_y;
    1.78 +void mouse(int bn, int state, int x, int y)
    1.79 +{
    1.80 +	prev_x = x;
    1.81 +	prev_y = y;
    1.82 +}
    1.83 +
    1.84 +void motion(int x, int y)
    1.85 +{
    1.86 +	int dx = x - prev_x;
    1.87 +	int dy = y - prev_y;
    1.88 +	prev_x = x;
    1.89 +	prev_y = y;
    1.90 +}