goat3dgfx

annotate src/material.cc @ 9:25b911c7c35c

fixed some line endings fixed the cubemap2.jpg file in examples/cubemap/data which was resized improperly causing seams...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Nov 2013 04:10:19 +0200
parents
children 7d6b667821cf
rev   line source
nuclear@0 1 #include "material.h"
nuclear@0 2 #include "unistate.h"
nuclear@0 3
nuclear@0 4 Material::Material()
nuclear@0 5 : diffuse(1, 1, 1), specular(0, 0, 0)
nuclear@0 6 {
nuclear@0 7 alpha = 1.0;
nuclear@0 8 shininess = 1.0;
nuclear@0 9
nuclear@0 10 for(int i=0; i<MAX_MTL_TEXTURES; i++) {
nuclear@0 11 tex[i] = 0;
nuclear@0 12 }
nuclear@0 13 }
nuclear@0 14
nuclear@0 15
nuclear@0 16 void Material::setup(bool use_textures) const
nuclear@0 17 {
nuclear@0 18 static bool done_init;
nuclear@0 19 static int st_diffuse_idx, st_specular_idx, st_shininess_idx, st_alpha_idx;
nuclear@0 20 static int st_tex_diffuse_idx, st_tex_specular_idx, st_tex_normal_idx;
nuclear@0 21 static int st_tex_idx[MAX_MTL_TEXTURES];
nuclear@0 22
nuclear@0 23 if(!done_init) {
nuclear@0 24 st_diffuse_idx = add_unistate("st_mtl_diffuse", ST_FLOAT3);
nuclear@0 25 st_specular_idx = add_unistate("st_mtl_specular", ST_FLOAT3);
nuclear@0 26 st_shininess_idx = add_unistate("st_mtl_shininess", ST_FLOAT);
nuclear@0 27 st_alpha_idx = add_unistate("st_mtl_alpha", ST_FLOAT);
nuclear@0 28 st_tex_diffuse_idx = add_unistate("st_tex_diffuse", ST_INT);
nuclear@0 29 st_tex_specular_idx = add_unistate("st_tex_specular", ST_INT);
nuclear@0 30 st_tex_normal_idx = add_unistate("st_tex_normal", ST_INT);
nuclear@0 31
nuclear@0 32 for(int i=0; i<MAX_MTL_TEXTURES; i++) {
nuclear@0 33 char name[32];
nuclear@0 34 sprintf(name, "st_tex%d", i);
nuclear@0 35 st_tex_idx[i] = add_unistate(name, ST_INT);
nuclear@0 36 }
nuclear@0 37 done_init = true;
nuclear@0 38 }
nuclear@0 39
nuclear@0 40 set_unistate(st_diffuse_idx, diffuse);
nuclear@0 41 set_unistate(st_specular_idx, specular);
nuclear@0 42 set_unistate(st_shininess_idx, shininess);
nuclear@0 43 set_unistate(st_alpha_idx, alpha);
nuclear@0 44
nuclear@0 45 if(!use_textures) {
nuclear@0 46 return; // we're done
nuclear@0 47 }
nuclear@0 48
nuclear@0 49 const int tex_named_idx[] = {
nuclear@0 50 st_tex_diffuse_idx, st_tex_specular_idx, st_tex_normal_idx, -1
nuclear@0 51 };
nuclear@0 52
nuclear@0 53 int tex_unit = 0;
nuclear@0 54 for(int i=0; i<MAX_MTL_TEXTURES; i++) {
nuclear@0 55 if(tex[i]) {
nuclear@0 56 tex[i]->bind(tex_unit);
nuclear@0 57
nuclear@0 58 if(tex_named_idx[i]) {
nuclear@0 59 set_unistate(tex_named_idx[i], tex_unit);
nuclear@0 60 }
nuclear@0 61 set_unistate(st_tex_idx[i], tex_unit);
nuclear@0 62 tex_unit++;
nuclear@0 63 }
nuclear@0 64 }
nuclear@0 65 }