# HG changeset patch # User John Tsiombikas # Date 1346295489 -10800 # Node ID 3fef65352b0b61712f6ae3e69c9d4cc1ff9dd21d # Parent 6d71dd4760f966eb4ffac734ea5a0909cef0cb37 - added mipmap generation diff -r 6d71dd4760f9 -r 3fef65352b0b prototype/sdr/fallback.p.glsl --- a/prototype/sdr/fallback.p.glsl Thu Aug 30 05:38:03 2012 +0300 +++ b/prototype/sdr/fallback.p.glsl Thu Aug 30 05:58:09 2012 +0300 @@ -5,6 +5,11 @@ const float fog_start = 3.0; const float fog_end = 6.0; +const vec3 lpos = vec3(0.0, 0.0, -0.5); +const vec3 vdir = vec3(0.0, 0.0, 1.0); + +const vec3 lcol = vec3(1.0, 0.732, 0.437); + void main() { vec3 texel = texture2D(tex_dif, gl_TexCoord[0].st).xyz; @@ -18,11 +23,7 @@ t.y, b.y, n.y, t.z, b.z, n.z); - - const vec3 lpos = vec3(0.0, 0.0, -0.5); vec3 ldir = tbn_mat * normalize(lpos - pos); - - const vec3 vdir = vec3(0.0, 0.0, 1.0); vec3 hvec = normalize(vdir + ldir); n = normalize(texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0); @@ -34,5 +35,5 @@ float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0); - gl_FragColor = vec4((diffuse + specular) * fog, 1.0); + gl_FragColor = vec4((diffuse + specular) * lcol * fog, 1.0); } diff -r 6d71dd4760f9 -r 3fef65352b0b prototype/src/texman.cc --- a/prototype/src/texman.cc Thu Aug 30 05:38:03 2012 +0300 +++ b/prototype/src/texman.cc Thu Aug 30 05:58:09 2012 +0300 @@ -4,6 +4,8 @@ #include "texman.h" #include "datapath.h" +unsigned int load_texture(const char *fname); + TextureSet::~TextureSet() { for(auto iter : textures) { @@ -25,7 +27,7 @@ path = datafile_path(path); printf("loading texture: %s\n", path); - unsigned int tex = img_gltexture_load(path); + unsigned int tex = load_texture(path); if(tex) { textures[fname] = tex; } else { @@ -33,3 +35,36 @@ } return tex; } + +unsigned int load_texture(const char *fname) +{ + struct img_pixmap img; + + img_init(&img); + if(img_load(&img, fname) == -1) { + img_destroy(&img); + return 0; + } + + unsigned int intfmt = img_glintfmt(&img); + unsigned int fmt = img_glfmt(&img); + unsigned int type = img_gltype(&img); + + unsigned int tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + if(GLEW_SGIS_generate_mipmap) { + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, intfmt, img.width, img.height, 0, fmt, type, img.pixels); + } else { + gluBuild2DMipmaps(GL_TEXTURE_2D, intfmt, img.width, img.height, fmt, type, img.pixels); + } + + img_destroy(&img); + return tex; +}