tavli

changeset 5:e48b40a3c82a

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 25 Jun 2015 20:43:34 +0300
parents b41ceead1708
children a0d30f6f20d4
files src/board.cc src/game.cc src/main.cc
diffstat 3 files changed, 38 insertions(+), 18 deletions(-) [+]
line diff
     1.1 --- a/src/board.cc	Thu Jun 25 05:58:35 2015 +0300
     1.2 +++ b/src/board.cc	Thu Jun 25 20:43:34 2015 +0300
     1.3 @@ -141,6 +141,22 @@
     1.4  	return true;
     1.5  }
     1.6  
     1.7 +static float wood(float x, float y)
     1.8 +{
     1.9 +	float u = x;
    1.10 +	float v = y;
    1.11 +	x += 1.0;
    1.12 +	x *= 10.0;
    1.13 +	y *= 20.0;
    1.14 +
    1.15 +	float len = sqrt(x * x + y * y) + turbulence2(u * 6.0, v * 12.0, 2) * 1.2 +
    1.16 +		turbulence2(u * 0.5, v, 2) * 15.0;
    1.17 +	float val = fmod(len, 1.0);
    1.18 +
    1.19 +	//val = val * 0.5 + 0.5;
    1.20 +	return val < 0.0 ? 0.0 : (val > 1.0 ? 1.0 : val);
    1.21 +}
    1.22 +
    1.23  static bool spike(float x, float y)
    1.24  {
    1.25  	x = fmod(x * 5.0, 1.0);
    1.26 @@ -169,14 +185,15 @@
    1.27  
    1.28  bool Board::generate_textures()
    1.29  {
    1.30 +	static const Vector3 wcol1 = Vector3(0.6, 0.4, 0.2);
    1.31 +	static const Vector3 wcol2 = Vector3(0.53, 0.32, 0.1);//Vector3(0.38, 0.25, 0.08);
    1.32 +
    1.33  	const int xsz = 512;
    1.34  	const int ysz = 1024;
    1.35  
    1.36  	img_field.create(xsz, ysz);
    1.37 -	clear_image(&img_field, 0, 0, 0);
    1.38  
    1.39  	unsigned char *pptr = img_field.pixels;
    1.40 -
    1.41  	for(int i=0; i<ysz; i++) {
    1.42  		float v = (float)i / (float)ysz;
    1.43  
    1.44 @@ -185,6 +202,9 @@
    1.45  
    1.46  			int r = 0, g = 0, b = 0;
    1.47  
    1.48 +			float wood_val = wood(u, v);
    1.49 +
    1.50 +			// pattern mask
    1.51  			float x = u;
    1.52  			float y = v < 0.5 ? v * 2.0 : 2.0 - v * 2.0;
    1.53  			bool inside = false;
    1.54 @@ -196,13 +216,18 @@
    1.55  				(diamond(x, y - 0.023) && !diamond(x, y - 0.028));
    1.56  			inside |= center_circle(x, y, 0.03);
    1.57  
    1.58 +			Vector3 wood_color = lerp(wcol1, wcol2, wood_val) * 0.9;
    1.59  			if(inside) {
    1.60 -				r = g = b = 255;
    1.61 +				wood_color = lerp(wcol1, wcol2, 1.0 - wood_val) * 2.0;
    1.62  			}
    1.63  
    1.64 -			pptr[0] = r;
    1.65 -			pptr[1] = g;
    1.66 -			pptr[2] = b;
    1.67 +			r = (int)(wood_color.x * 255.0);
    1.68 +			g = (int)(wood_color.y * 255.0);
    1.69 +			b = (int)(wood_color.z * 255.0);
    1.70 +
    1.71 +			pptr[0] = r > 255 ? 255 : r;
    1.72 +			pptr[1] = g > 255 ? 255 : g;
    1.73 +			pptr[2] = b > 255 ? 255 : b;
    1.74  			pptr += 3;
    1.75  		}
    1.76  	}
     2.1 --- a/src/game.cc	Thu Jun 25 05:58:35 2015 +0300
     2.2 +++ b/src/game.cc	Thu Jun 25 20:43:34 2015 +0300
     2.3 @@ -9,7 +9,7 @@
     2.4  
     2.5  static Board board;
     2.6  
     2.7 -static float cam_theta, cam_phi = 25, cam_dist = 6;
     2.8 +static float cam_theta, cam_phi = 25, cam_dist = 3;
     2.9  static bool bnstate[8];
    2.10  static int prev_x, prev_y;
    2.11  
    2.12 @@ -22,6 +22,10 @@
    2.13  	glEnable(GL_LIGHTING);
    2.14  	glEnable(GL_LIGHT0);
    2.15  
    2.16 +	if(GLEW_ARB_multisample) {
    2.17 +		glEnable(GL_MULTISAMPLE);
    2.18 +	}
    2.19 +
    2.20  	if(!board.init()) {
    2.21  		return false;
    2.22  	}
    2.23 @@ -51,15 +55,6 @@
    2.24  	draw_backdrop();
    2.25  
    2.26  	board.draw();
    2.27 -
    2.28 -	/*
    2.29 -	glBegin(GL_QUADS);
    2.30 -	glNormal3f(0, 1, 0);
    2.31 -	glVertex3f(-1, 0, 1);
    2.32 -	glVertex3f(1, 0, 1);
    2.33 -	glVertex3f(1, 0, -1);
    2.34 -	glVertex3f(-1, 0, -1);
    2.35 -	glEnd();*/
    2.36  }
    2.37  
    2.38  static void draw_backdrop()
    2.39 @@ -96,7 +91,7 @@
    2.40  {
    2.41  	glMatrixMode(GL_PROJECTION);
    2.42  	glLoadIdentity();
    2.43 -	gluPerspective(50, (float)x / (float)y, 0.2, 200.0);
    2.44 +	gluPerspective(45, (float)x / (float)y, 0.2, 200.0);
    2.45  
    2.46  	glViewport(0, 0, x, y);
    2.47  }
     3.1 --- a/src/main.cc	Thu Jun 25 05:58:35 2015 +0300
     3.2 +++ b/src/main.cc	Thu Jun 25 20:43:34 2015 +0300
     3.3 @@ -20,7 +20,7 @@
     3.4  {
     3.5  	glutInit(&argc, argv);
     3.6  	glutInitWindowSize(1280, 800);
     3.7 -	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
     3.8 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
     3.9  	glutCreateWindow("Tavli");
    3.10  
    3.11  	glutDisplayFunc(display);