goat3dgfx
view 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 |
line source
1 #include "material.h"
2 #include "unistate.h"
4 Material::Material()
5 : diffuse(1, 1, 1), specular(0, 0, 0)
6 {
7 alpha = 1.0;
8 shininess = 1.0;
10 for(int i=0; i<MAX_MTL_TEXTURES; i++) {
11 tex[i] = 0;
12 }
13 }
16 void Material::setup(bool use_textures) const
17 {
18 static bool done_init;
19 static int st_diffuse_idx, st_specular_idx, st_shininess_idx, st_alpha_idx;
20 static int st_tex_diffuse_idx, st_tex_specular_idx, st_tex_normal_idx;
21 static int st_tex_idx[MAX_MTL_TEXTURES];
23 if(!done_init) {
24 st_diffuse_idx = add_unistate("st_mtl_diffuse", ST_FLOAT3);
25 st_specular_idx = add_unistate("st_mtl_specular", ST_FLOAT3);
26 st_shininess_idx = add_unistate("st_mtl_shininess", ST_FLOAT);
27 st_alpha_idx = add_unistate("st_mtl_alpha", ST_FLOAT);
28 st_tex_diffuse_idx = add_unistate("st_tex_diffuse", ST_INT);
29 st_tex_specular_idx = add_unistate("st_tex_specular", ST_INT);
30 st_tex_normal_idx = add_unistate("st_tex_normal", ST_INT);
32 for(int i=0; i<MAX_MTL_TEXTURES; i++) {
33 char name[32];
34 sprintf(name, "st_tex%d", i);
35 st_tex_idx[i] = add_unistate(name, ST_INT);
36 }
37 done_init = true;
38 }
40 set_unistate(st_diffuse_idx, diffuse);
41 set_unistate(st_specular_idx, specular);
42 set_unistate(st_shininess_idx, shininess);
43 set_unistate(st_alpha_idx, alpha);
45 if(!use_textures) {
46 return; // we're done
47 }
49 const int tex_named_idx[] = {
50 st_tex_diffuse_idx, st_tex_specular_idx, st_tex_normal_idx, -1
51 };
53 int tex_unit = 0;
54 for(int i=0; i<MAX_MTL_TEXTURES; i++) {
55 if(tex[i]) {
56 tex[i]->bind(tex_unit);
58 if(tex_named_idx[i]) {
59 set_unistate(tex_named_idx[i], tex_unit);
60 }
61 set_unistate(st_tex_idx[i], tex_unit);
62 tex_unit++;
63 }
64 }
65 }