goat3d

changeset 20:f5fdefbb7a1d

added materials loading to goatview
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Sep 2013 07:06:07 +0300
parents b35427826b60
children 44a20d72f3a6
files goatview/src/main.c
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/goatview/src/main.c	Fri Sep 27 06:58:37 2013 +0300
     1.2 +++ b/goatview/src/main.c	Fri Sep 27 07:06:07 2013 +0300
     1.3 @@ -102,7 +102,24 @@
     1.4  	int *vidx;
     1.5  
     1.6  	if((mtl = goat3d_get_mesh_mtl(mesh))) {
     1.7 -		/* TODO */
     1.8 +		float white[] = {1, 1, 1, 1};
     1.9 +		float black[] = {0, 0, 0, 0};
    1.10 +		float zero = 0.0;
    1.11 +		const float *diffuse, *specular, *shininess;
    1.12 +
    1.13 +		if(!(diffuse = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_DIFFUSE))) {
    1.14 +			diffuse = white;
    1.15 +		}
    1.16 +		if(!(specular = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SPECULAR))) {
    1.17 +			specular = black;
    1.18 +		}
    1.19 +		if(!(shininess = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SHININESS))) {
    1.20 +			shininess = &zero;
    1.21 +		}
    1.22 +
    1.23 +		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuse);
    1.24 +		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
    1.25 +		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, *shininess);
    1.26  	}
    1.27  
    1.28  	vnum = goat3d_get_mesh_attrib_count(mesh, GOAT3D_MESH_ATTR_VERTEX);