--- libgender/material.C 2005/01/06 03:09:24 1.55 +++ libgender/material.C 2005/02/11 14:54:55 1.60 @@ -57,8 +57,7 @@ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - glTexImage2D (GL_TEXTURE_2D, - 0, + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); SDL_FreeSurface (image); /* No longer needed */ @@ -129,7 +128,7 @@ i->second->enable (); if (ctx.pass->l) - ctx.pass->l->enable (); + ctx.pass->l->enable (ctx); } void material::disable (view &ctx) @@ -143,8 +142,83 @@ { } -static shader::varying_3f normal; + +void mat_timed::enable (view &ctx) +{ + material::enable (ctx); + + time->set (timer::now - (int)timer::now); + sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F)); +} + +void mat_timed::disable (view &ctx) +{ + material::disable (ctx); +} + +void mat_timed::vsh (view &ctx) +{ + using namespace shader::compile; + std_vsh (); + + if (ctx.pass->l) + f_normal = normal_matrix * vin.normal; +} + +void mat_timed::fsh (view &ctx) +{ + using namespace shader::compile; + + if (ctx.pass->l) + { + temp_1f fac; + + fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); + + //fac = (fac / 100) * (mod (time, 100)) ; + fac = time; + + xyz (fout.frag_color) = sin (time * 3.14159265*2);//ctx.pass->l->sh_colour * sh_colour * fac; + } +} + +void mat_gouraud_shaded::enable (view &ctx) +{ + material::enable (ctx); + + sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); +} + +void mat_gouraud_shaded::disable (view &ctx) +{ + material::disable (ctx); +} + +void mat_gouraud_shaded::vsh (view &ctx) +{ + using namespace shader::compile; + std_vsh (); + + if (ctx.pass->l) + f_normal = normal_matrix * vin.normal; +} + +void mat_gouraud_shaded::fsh (view &ctx) +{ + using namespace shader::compile; + + if (ctx.pass->l) + { + temp_1f fac; + + fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); + + xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; + } +} + static shader::varying_2f texcoord; +static shader::varying_3f normal; void test_material::vsh (view &ctx) { @@ -202,4 +276,6 @@ } test_material *testmat; +mat_gouraud_shaded *testmat2; +mat_timed *testmat3;