dbf-udg

changeset 8:f0a47f46ee45

lalala
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Feb 2013 06:53:44 +0200
parents 603656331514
children 7056437a361b
files sdr/phong.p.glsl src/mballs.cc src/udg.cc
diffstat 3 files changed, 91 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/sdr/phong.p.glsl	Mon Feb 18 05:44:17 2013 +0200
     1.2 +++ b/sdr/phong.p.glsl	Mon Feb 18 06:53:44 2013 +0200
     1.3 @@ -4,18 +4,25 @@
     1.4  {
     1.5  	vec3 n = normalize(normal);
     1.6  	vec3 v = -normalize(vpos);
     1.7 -	vec3 l = normalize(gl_LightSource[0].position.xyz);
     1.8  
     1.9 -	vec3 h = normalize(v + l);
    1.10 +	vec3 color = vec3(0.0, 0.0, 0.0);
    1.11  
    1.12 -	float ndotl = max(dot(n, l), 0.0);
    1.13 -	float ndoth = max(dot(n, h), 0.0);
    1.14 -	float spec = pow(ndoth, gl_FrontMaterial.shininess);
    1.15 +	for(int i=0; i<2; i++) {
    1.16 +		vec3 l = normalize(gl_LightSource[i].position.xyz);
    1.17 +		vec3 h = normalize(v + l);
    1.18 +
    1.19 +		float ndotl = max(dot(n, l), 0.0);
    1.20 +		float ndoth = max(dot(n, h), 0.0);
    1.21 +		float spec = pow(ndoth, gl_FrontMaterial.shininess);
    1.22 +
    1.23 +		vec3 dcol = gl_FrontMaterial.diffuse.xyz * gl_LightSource[i].diffuse.xyz;
    1.24 +		vec3 scol = gl_FrontMaterial.specular.xyz * gl_LightSource[i].diffuse.xyz;
    1.25 +
    1.26 +		color += dcol * ndotl + scol * spec;
    1.27 +	}
    1.28  
    1.29  	vec3 acol = gl_FrontMaterial.ambient.xyz * gl_LightModel.ambient.xyz;
    1.30 -	vec3 dcol = gl_FrontMaterial.diffuse.xyz * gl_LightSource[0].diffuse.xyz;
    1.31 -	vec3 scol = gl_FrontMaterial.specular.xyz * gl_LightSource[0].specular.xyz;
    1.32  
    1.33 -	gl_FragColor.xyz = acol + dcol * ndotl + scol * spec;
    1.34 +	gl_FragColor.xyz = acol + color;
    1.35  	gl_FragColor.w = 1.0;
    1.36  }
     2.1 --- a/src/mballs.cc	Mon Feb 18 05:44:17 2013 +0200
     2.2 +++ b/src/mballs.cc	Mon Feb 18 06:53:44 2013 +0200
     2.3 @@ -23,6 +23,7 @@
     2.4  static float grid[MBALL_GRID_SZ][MBALL_GRID_SZ][MBALL_GRID_SZ];
     2.5  static std::vector<MetaBall> balls;
     2.6  static struct metasurface *msurf;
     2.7 +static float floor_height = -0.95;
     2.8  
     2.9  bool mball_init()
    2.10  {
    2.11 @@ -54,14 +55,61 @@
    2.12  {
    2.13  	update();
    2.14  
    2.15 +	const float blue[] = {0.4, 0.45, 1.0, 1};
    2.16 +	const float dark_red[] = {0.6, 0.2, 0.1, 1};
    2.17 +	const float white[] = {1, 1, 1, 1};
    2.18 +	const float black[] = {0, 0, 0, 1};
    2.19 +
    2.20  	glMatrixMode(GL_MODELVIEW);
    2.21  	glPushMatrix();
    2.22  	glScalef(4.0, 4.0, 4.0);
    2.23  
    2.24 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
    2.25 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
    2.26 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0);
    2.27 +
    2.28  	glBegin(GL_TRIANGLES);
    2.29  	msurf_polygonize(msurf);
    2.30  	glEnd();
    2.31  
    2.32 +	// floor
    2.33 +	glBegin(GL_QUADS);
    2.34 +	glNormal3f(0, 1, 0);
    2.35 +	glVertex3f(-5, -1, 5);
    2.36 +	glVertex3f(5, -1, 5);
    2.37 +	glVertex3f(5, -1, -5);
    2.38 +	glVertex3f(-5, -1, -5);
    2.39 +	glEnd();
    2.40 +
    2.41 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dark_red);
    2.42 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
    2.43 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0);
    2.44 +
    2.45 +	// box
    2.46 +	glPushMatrix();
    2.47 +	glTranslatef(0, -1.7, 1);
    2.48 +	glScalef(1.05, 1, 0.05);
    2.49 +	glutSolidCube(2.0);
    2.50 +	glPopMatrix();
    2.51 +
    2.52 +	glPushMatrix();
    2.53 +	glTranslatef(0, -1.7, -1);
    2.54 +	glScalef(1.05, 1, 0.05);
    2.55 +	glutSolidCube(2.0);
    2.56 +	glPopMatrix();
    2.57 +
    2.58 +	glPushMatrix();
    2.59 +	glTranslatef(1, -1.7, 0);
    2.60 +	glScalef(0.05, 1, 1);
    2.61 +	glutSolidCube(2.0);
    2.62 +	glPopMatrix();
    2.63 +
    2.64 +	glPushMatrix();
    2.65 +	glTranslatef(-1, -1.7, 0);
    2.66 +	glScalef(0.05, 1, 1);
    2.67 +	glutSolidCube(2.0);
    2.68 +	glPopMatrix();
    2.69 +
    2.70  	glPopMatrix();
    2.71  }
    2.72  
    2.73 @@ -103,6 +151,15 @@
    2.74  			sum += 1000.0;
    2.75  		}
    2.76  	}
    2.77 +
    2.78 +	// floor
    2.79 +	float height = y - floor_height;
    2.80 +	if(height > 1e-6) {
    2.81 +		sum += 1.0 / height;
    2.82 +	} else {
    2.83 +		sum += 1000.0;
    2.84 +	}
    2.85 +
    2.86  	return sum;
    2.87  }
    2.88  
     3.1 --- a/src/udg.cc	Mon Feb 18 05:44:17 2013 +0200
     3.2 +++ b/src/udg.cc	Mon Feb 18 06:53:44 2013 +0200
     3.3 @@ -36,12 +36,13 @@
     3.4  void destroy_rtarg(struct render_target *rt);
     3.5  
     3.6  int xsz, ysz;
     3.7 -float cam_theta, cam_phi = 25, cam_dist = 9;
     3.8 +float cam_theta, cam_phi = 25, cam_dist = 11;
     3.9  unsigned int dither_tex;
    3.10  struct render_target *rtarg;
    3.11  unsigned int post_prog, phong_prog;
    3.12  
    3.13  int opt_highres, opt_regular_render;
    3.14 +bool opt_autorot = true;
    3.15  
    3.16  
    3.17  int main(int argc, char **argv)
    3.18 @@ -130,6 +131,7 @@
    3.19  	glEnable(GL_DEPTH_TEST);
    3.20  	glEnable(GL_LIGHTING);
    3.21  	glEnable(GL_LIGHT0);
    3.22 +	glEnable(GL_LIGHT1);
    3.23  	glEnable(GL_NORMALIZE);
    3.24  
    3.25  	return true;
    3.26 @@ -168,7 +170,13 @@
    3.27  void disp()
    3.28  {
    3.29  	float ldir[] = {-1, 1, 2, 0};
    3.30 +	float ldir2[] = {0.0, 0.35, -0.9, 0};
    3.31 +
    3.32 +	float lcol[] = {1, 1, 1, 1};
    3.33 +	float lcol2[] = {0.35, 0.3, 0.15, 1};
    3.34 +
    3.35  	int xres, yres;
    3.36 +	float auto_angle = glutGet(GLUT_ELAPSED_TIME) / 100.0;
    3.37  
    3.38  	if(opt_highres) {
    3.39  		xres = xsz;
    3.40 @@ -198,11 +206,15 @@
    3.41  	glMatrixMode(GL_MODELVIEW);
    3.42  	glLoadIdentity();
    3.43  
    3.44 -	glTranslatef(0, 0, -cam_dist);
    3.45 +	glTranslatef(0, 0.8, -cam_dist);
    3.46  	glRotatef(cam_phi, 1, 0, 0);
    3.47 -	glRotatef(cam_theta, 0, 1, 0);
    3.48 +	glRotatef(opt_autorot ? auto_angle : cam_theta, 0, 1, 0);
    3.49  
    3.50  	glLightfv(GL_LIGHT0, GL_POSITION, ldir);
    3.51 +	glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol);
    3.52 +
    3.53 +	glLightfv(GL_LIGHT1, GL_POSITION, ldir2);
    3.54 +	glLightfv(GL_LIGHT1, GL_DIFFUSE, lcol2);
    3.55  
    3.56  	const float blue[] = {0.4, 0.45, 1.0, 1};
    3.57  	const float white[] = {1, 1, 1, 1};
    3.58 @@ -298,6 +310,10 @@
    3.59  	case 27:
    3.60  		exit(0);
    3.61  
    3.62 +	case 'a':
    3.63 +		opt_autorot = !opt_autorot;
    3.64 +		break;
    3.65 +
    3.66  	case 'f':
    3.67  		{
    3.68  			static bool fullscreen;