dungeon_crawler

changeset 43:3fef65352b0b

- added mipmap generation
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 30 Aug 2012 05:58:09 +0300
parents 6d71dd4760f9
children c45c42c3d32e
files prototype/sdr/fallback.p.glsl prototype/src/texman.cc
diffstat 2 files changed, 42 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/prototype/sdr/fallback.p.glsl	Thu Aug 30 05:38:03 2012 +0300
     1.2 +++ b/prototype/sdr/fallback.p.glsl	Thu Aug 30 05:58:09 2012 +0300
     1.3 @@ -5,6 +5,11 @@
     1.4  const float fog_start = 3.0;
     1.5  const float fog_end = 6.0;
     1.6  
     1.7 +const vec3 lpos = vec3(0.0, 0.0, -0.5);
     1.8 +const vec3 vdir = vec3(0.0, 0.0, 1.0);
     1.9 +
    1.10 +const vec3 lcol = vec3(1.0, 0.732, 0.437);
    1.11 +
    1.12  void main()
    1.13  {
    1.14  	vec3 texel = texture2D(tex_dif, gl_TexCoord[0].st).xyz;
    1.15 @@ -18,11 +23,7 @@
    1.16  			t.y, b.y, n.y,
    1.17  			t.z, b.z, n.z);
    1.18  
    1.19 -
    1.20 -	const vec3 lpos = vec3(0.0, 0.0, -0.5);
    1.21  	vec3 ldir = tbn_mat * normalize(lpos - pos);
    1.22 -
    1.23 -	const vec3 vdir = vec3(0.0, 0.0, 1.0);
    1.24  	vec3 hvec = normalize(vdir + ldir);
    1.25  
    1.26  	n = normalize(texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
    1.27 @@ -34,5 +35,5 @@
    1.28  
    1.29  	float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0);
    1.30  
    1.31 -	gl_FragColor = vec4((diffuse + specular) * fog, 1.0);
    1.32 +	gl_FragColor = vec4((diffuse + specular) * lcol * fog, 1.0);
    1.33  }
     2.1 --- a/prototype/src/texman.cc	Thu Aug 30 05:38:03 2012 +0300
     2.2 +++ b/prototype/src/texman.cc	Thu Aug 30 05:58:09 2012 +0300
     2.3 @@ -4,6 +4,8 @@
     2.4  #include "texman.h"
     2.5  #include "datapath.h"
     2.6  
     2.7 +unsigned int load_texture(const char *fname);
     2.8 +
     2.9  TextureSet::~TextureSet()
    2.10  {
    2.11  	for(auto iter : textures) {
    2.12 @@ -25,7 +27,7 @@
    2.13  	path = datafile_path(path);
    2.14  
    2.15  	printf("loading texture: %s\n", path);
    2.16 -	unsigned int tex = img_gltexture_load(path);
    2.17 +	unsigned int tex = load_texture(path);
    2.18  	if(tex) {
    2.19  		textures[fname] = tex;
    2.20  	} else {
    2.21 @@ -33,3 +35,36 @@
    2.22  	}
    2.23  	return tex;
    2.24  }
    2.25 +
    2.26 +unsigned int load_texture(const char *fname)
    2.27 +{
    2.28 +	struct img_pixmap img;
    2.29 +
    2.30 +	img_init(&img);
    2.31 +	if(img_load(&img, fname) == -1) {
    2.32 +		img_destroy(&img);
    2.33 +		return 0;
    2.34 +	}
    2.35 +
    2.36 +	unsigned int intfmt = img_glintfmt(&img);
    2.37 +	unsigned int fmt = img_glfmt(&img);
    2.38 +	unsigned int type = img_gltype(&img);
    2.39 +
    2.40 +	unsigned int tex;
    2.41 +	glGenTextures(1, &tex);
    2.42 +	glBindTexture(GL_TEXTURE_2D, tex);
    2.43 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    2.44 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    2.45 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    2.46 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    2.47 +
    2.48 +	if(GLEW_SGIS_generate_mipmap) {
    2.49 +		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
    2.50 +		glTexImage2D(GL_TEXTURE_2D, 0, intfmt, img.width, img.height, 0, fmt, type, img.pixels);
    2.51 +	} else {
    2.52 +		gluBuild2DMipmaps(GL_TEXTURE_2D, intfmt, img.width, img.height, fmt, type, img.pixels);
    2.53 +	}
    2.54 +
    2.55 +	img_destroy(&img);
    2.56 +	return tex;
    2.57 +}