ld33_umonster

changeset 2:35349df5392d

wtf?
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 22 Aug 2015 23:55:21 +0300
parents bed0e207acb6
children 93ff21458a16
files sdr/shadow-notex.p.glsl src/game.cc src/mesh.cc src/mesh.h src/meshgen.cc src/object.cc src/room.cc src/room.h src/scene.cc
diffstat 9 files changed, 124 insertions(+), 26 deletions(-) [+]
line diff
     1.1 --- a/sdr/shadow-notex.p.glsl	Sat Aug 22 23:17:57 2015 +0300
     1.2 +++ b/sdr/shadow-notex.p.glsl	Sat Aug 22 23:55:21 2015 +0300
     1.3 @@ -1,5 +1,5 @@
     1.4  /* vi: set ft=glsl */
     1.5 -uniform sampler2DShadow shadowmap;
     1.6 +//uniform sampler2DShadow shadowmap;
     1.7  
     1.8  varying vec3 vdir, ldir, normal;
     1.9  varying vec4 shadow_tc;
    1.10 @@ -10,10 +10,10 @@
    1.11  
    1.12  void main()
    1.13  {
    1.14 -	float shadow = shadow2DProj(shadowmap, shadow_tc).x;
    1.15 +	float shadow = 1.0;//shadow2DProj(shadowmap, shadow_tc).x;
    1.16  
    1.17  	vec3 n = normalize(normal);
    1.18 -	vec3 v = normalize(vdir);
    1.19 +	/*vec3 v = normalize(vdir);
    1.20  	vec3 l = normalize(ldir);
    1.21  	vec3 h = normalize(l + v);
    1.22  
    1.23 @@ -21,9 +21,12 @@
    1.24  	float ndoth = max(dot(n, h), 0.0);
    1.25  
    1.26  	vec3 diffuse = KD * gl_LightSource[0].diffuse.rgb * ndotl;
    1.27 -	vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW);
    1.28 +	vec3 specular = vec3(0.0, 0.0, 0.0);//KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW);
    1.29  
    1.30  	vec3 ambient = gl_LightModel.ambient.rgb * KD;
    1.31  	gl_FragColor.rgb = ambient + (diffuse + specular) * shadow;
    1.32  	gl_FragColor.a = gl_FrontMaterial.diffuse.a;
    1.33 +	*/
    1.34 +	gl_FragColor.rgb = n * 0.5 + 0.5;
    1.35 +	gl_FragColor.a = 1.0;
    1.36  }
     2.1 --- a/src/game.cc	Sat Aug 22 23:17:57 2015 +0300
     2.2 +++ b/src/game.cc	Sat Aug 22 23:55:21 2015 +0300
     2.3 @@ -7,6 +7,8 @@
     2.4  #include "shadow.h"
     2.5  #include "opt.h"
     2.6  
     2.7 +#include "room.h"
     2.8 +
     2.9  static void draw_scene();
    2.10  
    2.11  int win_width, win_height;
    2.12 @@ -35,7 +37,7 @@
    2.13  	glEnable(GL_LIGHTING);
    2.14  	glEnable(GL_LIGHT0);
    2.15  
    2.16 -	float amb[] = {0.3, 0.3, 0.3, 1.0};
    2.17 +	float amb[] = {0.1, 0.1, 0.1, 1.0};
    2.18  	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
    2.19  
    2.20  	if(glcaps.sep_spec) {
    2.21 @@ -58,6 +60,9 @@
    2.22  	}
    2.23  	set_uniform_int(sdr_shadow_notex, "shadowmap", 1);
    2.24  
    2.25 +	if(!init_room()) {
    2.26 +		return false;
    2.27 +	}
    2.28  
    2.29  	assert(glGetError() == GL_NO_ERROR);
    2.30  	return true;
    2.31 @@ -65,6 +70,7 @@
    2.32  
    2.33  void game_cleanup()
    2.34  {
    2.35 +	cleanup_room();
    2.36  }
    2.37  
    2.38  void game_update(unsigned long time_msec)
    2.39 @@ -82,9 +88,10 @@
    2.40  	glRotatef(cam_phi, 1, 0, 0);
    2.41  	glRotatef(cam_theta, 0, 1, 0);
    2.42  
    2.43 -	float lpos[] = {-10, 20, 10, 1};
    2.44 +	float lpos[] = {-0, 0, 0, 1};
    2.45  	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    2.46  
    2.47 +	opt.shadows = false;
    2.48  	if(opt.shadows && sdr_shadow) {
    2.49  		begin_shadow_pass(Vector3(lpos[0], lpos[1], lpos[2]), Vector3(0, 0, 0), 5);
    2.50  		draw_scene();
    2.51 @@ -100,7 +107,7 @@
    2.52  		glActiveTexture(GL_TEXTURE0);
    2.53  		glMatrixMode(GL_MODELVIEW);
    2.54  
    2.55 -		set_shader(sdr_shadow_notex);
    2.56 +		override_shader(sdr_shadow_notex);
    2.57  
    2.58  		draw_scene();
    2.59  
    2.60 @@ -109,6 +116,7 @@
    2.61  		glActiveTexture(GL_TEXTURE0);
    2.62  		glBindTexture(GL_TEXTURE_2D, 0);
    2.63  	} else {
    2.64 +		override_shader(sdr_shadow_notex);
    2.65  		draw_scene();
    2.66  	}
    2.67  }
    2.68 @@ -124,23 +132,15 @@
    2.69  
    2.70  static void draw_scene()
    2.71  {
    2.72 +	draw_room();
    2.73 +
    2.74  	glPushMatrix();
    2.75 -	glTranslatef(0, -1, 0);
    2.76 -
    2.77 -	glmaterial(0.5, 0.5, 0.5, 0.8, 40.0);
    2.78 -
    2.79 -	glBegin(GL_QUADS);
    2.80 -	glNormal3f(0, 1, 0);
    2.81 -	glVertex3f(-10, 0, 10);
    2.82 -	glVertex3f(10, 0, 10);
    2.83 -	glVertex3f(10, 0, -10);
    2.84 -	glVertex3f(-10, 0, -10);
    2.85 -	glEnd();
    2.86 -
    2.87 -	glPopMatrix();
    2.88 +	glTranslatef(0, 0.75, 0);
    2.89  
    2.90  	glmaterial(0.2, 0.3, 1.0, 0.8, 60.0);
    2.91  	draw_teapot();
    2.92 +
    2.93 +	glPopMatrix();
    2.94  }
    2.95  
    2.96  
     3.1 --- a/src/mesh.cc	Sat Aug 22 23:17:57 2015 +0300
     3.2 +++ b/src/mesh.cc	Sat Aug 22 23:55:21 2015 +0300
     3.3 @@ -472,7 +472,7 @@
     3.4  
     3.5  void Mesh::apply_xform(const Matrix4x4 &xform)
     3.6  {
     3.7 -	Matrix4x4 dir_xform = xform;
     3.8 +	Matrix4x4 dir_xform;// = xform.inverse().transposed();
     3.9  	dir_xform[0][3] = dir_xform[1][3] = dir_xform[2][3] = 0.0f;
    3.10  	dir_xform[3][0] = dir_xform[3][1] = dir_xform[3][2] = 0.0f;
    3.11  	dir_xform[3][3] = 1.0f;
    3.12 @@ -982,6 +982,43 @@
    3.13  	}
    3.14  }
    3.15  
    3.16 +void Mesh::dump(FILE *fp) const
    3.17 +{
    3.18 +	if(!has_attrib(MESH_ATTR_VERTEX)) {
    3.19 +		return;
    3.20 +	}
    3.21 +
    3.22 +	fprintf(fp, "VERTEX ATTRIBUTES\n");
    3.23 +	static const char *label[] = { "pos", "nor", "tan", "tex", "col", "bw", "bid" };
    3.24 +	static const char *elemfmt[] = { 0, " %s(%g)", " %s(%g, %g)", " %s(%g, %g, %g)", " %s(%g, %g, %g, %g)", 0 };
    3.25 +
    3.26 +	for(int i=0; i<(int)nverts; i++) {
    3.27 +		fprintf(fp, "%5u:", i);
    3.28 +		for(int j=0; j<NUM_MESH_ATTR; j++) {
    3.29 +			if(has_attrib(j)) {
    3.30 +				Vector4 v = get_attrib(j, i);
    3.31 +				int nelem = vattr[j].nelem;
    3.32 +				fprintf(fp, elemfmt[nelem], label[j], v.x, v.y, v.z, v.w);
    3.33 +			}
    3.34 +		}
    3.35 +		fputc('\n', fp);
    3.36 +	}
    3.37 +
    3.38 +	if(is_indexed()) {
    3.39 +		const unsigned int *idx = get_index_data();
    3.40 +		int numidx = get_index_count();
    3.41 +		int numtri = numidx / 3;
    3.42 +		assert(numidx % 3 == 0);
    3.43 +
    3.44 +		fprintf(fp, "FACES\n");
    3.45 +
    3.46 +		for(int i=0; i<numtri; i++) {
    3.47 +			fprintf(fp, "%5d: %d %d %d\n", i, idx[0], idx[1], idx[2]);
    3.48 +			idx += 3;
    3.49 +		}
    3.50 +	}
    3.51 +}
    3.52 +
    3.53  // ------ private member functions ------
    3.54  
    3.55  void Mesh::calc_aabb()
     4.1 --- a/src/mesh.h	Sat Aug 22 23:17:57 2015 +0300
     4.2 +++ b/src/mesh.h	Sat Aug 22 23:55:21 2015 +0300
     4.3 @@ -1,6 +1,7 @@
     4.4  #ifndef MESH_H_
     4.5  #define MESH_H_
     4.6  
     4.7 +#include <stdio.h>
     4.8  #include <string>
     4.9  #include <vector>
    4.10  #include "vmath/vmath.h"
    4.11 @@ -231,6 +232,8 @@
    4.12  	void texcoord_apply_xform(const Matrix4x4 &xform);
    4.13  	void texcoord_gen_plane(const Vector3 &norm, const Vector3 &tang);
    4.14  	void texcoord_gen_box();
    4.15 +
    4.16 +	void dump(FILE *fp) const;
    4.17  };
    4.18  
    4.19  #endif	// MESH_H_
     5.1 --- a/src/meshgen.cc	Sat Aug 22 23:17:57 2015 +0300
     5.2 +++ b/src/meshgen.cc	Sat Aug 22 23:55:21 2015 +0300
     5.3 @@ -412,13 +412,14 @@
     5.4  	mesh->clear();
     5.5  
     5.6  	for(int i=0; i<6; i++) {
     5.7 -		Matrix4x4 xform;
     5.8 +		Matrix4x4 xform, dir_xform;
     5.9  		Mesh m;
    5.10  
    5.11  		gen_plane(&m, 1, 1, usub, vsub);
    5.12  		xform.rotate(Vector3(face_angles[i][1], face_angles[i][0], 0));
    5.13 +		dir_xform = xform;
    5.14  		xform.translate(Vector3(0, 0, 0.5));
    5.15 -		m.apply_xform(xform);
    5.16 +		m.apply_xform(xform, dir_xform);
    5.17  
    5.18  		mesh->append(m);
    5.19  	}
     6.1 --- a/src/object.cc	Sat Aug 22 23:17:57 2015 +0300
     6.2 +++ b/src/object.cc	Sat Aug 22 23:55:21 2015 +0300
     6.3 @@ -1,6 +1,7 @@
     6.4  #include "object.h"
     6.5  #include "opengl.h"
     6.6  #include "shadow.h"
     6.7 +#include "shader.h"
     6.8  
     6.9  Material::Material()
    6.10  	: diffuse(1, 1, 1), specular(0, 0, 0)
    6.11 @@ -102,10 +103,10 @@
    6.12  	if(glcaps.shaders) {
    6.13  		if(sdr) {
    6.14  			if(!shadow_pass) {
    6.15 -				glUseProgram(sdr);
    6.16 +				::set_shader(sdr);
    6.17  			}
    6.18  		} else {
    6.19 -			glUseProgram(0);
    6.20 +			::set_shader(0);
    6.21  		}
    6.22  	}
    6.23  
    6.24 @@ -140,7 +141,7 @@
    6.25  	}
    6.26  
    6.27  	if(sdr) {
    6.28 -		glUseProgram(0);
    6.29 +		::set_shader(0);
    6.30  	}
    6.31  
    6.32  	glMatrixMode(GL_MODELVIEW);
    6.33 @@ -187,6 +188,10 @@
    6.34  
    6.35  void Object::draw_normals(float len, const Vector4 &col) const
    6.36  {
    6.37 +	int cur_sdr;
    6.38 +	glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr);
    6.39 +	glUseProgram(0);
    6.40 +
    6.41  	glPushAttrib(GL_ENABLE_BIT);
    6.42  	glDisable(GL_LIGHTING);
    6.43  
    6.44 @@ -200,6 +205,8 @@
    6.45  
    6.46  	glPopMatrix();
    6.47  	glPopAttrib();
    6.48 +
    6.49 +	glUseProgram(cur_sdr);
    6.50  }
    6.51  
    6.52  void Object::draw_tangents(float len, const Vector4 &col) const
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/room.cc	Sat Aug 22 23:55:21 2015 +0300
     7.3 @@ -0,0 +1,38 @@
     7.4 +#include <stdio.h>
     7.5 +#include "opengl.h"
     7.6 +#include "room.h"
     7.7 +#include "game.h"
     7.8 +#include "object.h"
     7.9 +#include "scene.h"
    7.10 +#include "meshgen.h"
    7.11 +
    7.12 +static Scene scn;
    7.13 +
    7.14 +bool init_room()
    7.15 +{
    7.16 +	Matrix4x4 xform;
    7.17 +
    7.18 +	// generate room
    7.19 +	Mesh *mroom = new Mesh;
    7.20 +	gen_box(mroom, 100, 100, 100);
    7.21 +	//xform.set_translation(Vector3(0, 12.5, 0));
    7.22 +	mroom->apply_xform(xform);
    7.23 +	mroom->flip();
    7.24 +
    7.25 +	Object *oroom = new Object;
    7.26 +	oroom->set_mesh(mroom);
    7.27 +	oroom->rop.cast_shadows = false;
    7.28 +
    7.29 +	scn.add_object(oroom);
    7.30 +	return true;
    7.31 +}
    7.32 +
    7.33 +void cleanup_room()
    7.34 +{
    7.35 +	scn.clear();
    7.36 +}
    7.37 +
    7.38 +void draw_room()
    7.39 +{
    7.40 +	scn.draw();
    7.41 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/room.h	Sat Aug 22 23:55:21 2015 +0300
     8.3 @@ -0,0 +1,8 @@
     8.4 +#ifndef ROOM_H_
     8.5 +#define ROOM_H_
     8.6 +
     8.7 +bool init_room();
     8.8 +void cleanup_room();
     8.9 +void draw_room();
    8.10 +
    8.11 +#endif	// ROOM_H_
     9.1 --- a/src/scene.cc	Sat Aug 22 23:17:57 2015 +0300
     9.2 +++ b/src/scene.cc	Sat Aug 22 23:55:21 2015 +0300
     9.3 @@ -51,6 +51,7 @@
     9.4  				objects[i]->draw_wire();
     9.5  			} else {
     9.6  				objects[i]->draw();
     9.7 +				objects[i]->draw_normals();
     9.8  			}
     9.9  		}
    9.10  	}