From 9836d52cebef33002b8cea7d2e15d4e0da043e76 Mon Sep 17 00:00:00 2001 From: taw27 Date: Sun, 10 Aug 2008 19:14:40 +0000 Subject: Process texture and Ks components from OBJ files git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@246 84d2e878-0bd5-11dd-ad15-13eda11d74c5 --- src/model.c | 10 ++++++++-- src/obj2model.c | 22 ++++++++++++++++++++++ src/render.c | 15 +++++++++++++-- src/types.h | 2 ++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/model.c b/src/model.c index 570a128..81958ec 100644 --- a/src/model.c +++ b/src/model.c @@ -78,7 +78,7 @@ static Model *model_new(const char *name) { static Primitive *model_add_primitive(Model *model, GLenum type, GLfloat *vertices, GLfloat *normals, GLfloat *texcoords, int n, PrimitiveAttrib attribs, GLfloat r, GLfloat g, GLfloat b, char *texture, GLfloat radius, GLfloat shininess, - int vbos, int coll) { + int vbos, int coll, GLfloat colspec) { Primitive *p; @@ -116,6 +116,7 @@ static Primitive *model_add_primitive(Model *model, GLenum type, GLfloat *vertic p->col_r = r; p->col_g = g; p->col_b = b; + p->colspec = colspec; p->texture = texture; p->radius = radius; p->shininess = shininess; @@ -198,6 +199,7 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render GLfloat col_r = 0.0; GLfloat col_g = 0.0; GLfloat col_b = 0.0; + GLfloat colspec = 0.0; GLfloat radius = 0.0; GLfloat shininess = 100.0; PrimitiveAttrib attribs; @@ -267,7 +269,7 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render if ( num_vertices > 0 ) { model_add_primitive(model, type, vertices, normals, texcoords, num_vertices, attribs, col_r, col_g, col_b, texture, radius, shininess, - render->vbos, coll); + render->vbos, coll, colspec); num_vertices = 0; type = PRIMITIVE_TRIANGLES; attribs = ATTRIB_NONE; @@ -452,6 +454,10 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render attribs = attribs | ATTRIB_COLOUR; col_r = r; col_g = g; col_b = b; } + if ( sscanf(line, "colspec %f %f %f", &r, &g, &b) == 3 ) { + attribs = attribs | ATTRIB_COLSPEC; + colspec = r; + } if ( sscanf(line, "radius %f", &radius) == 1 ) { attribs = attribs | ATTRIB_RADIUS; } diff --git a/src/obj2model.c b/src/obj2model.c index a720273..9b6f9ba 100644 --- a/src/obj2model.c +++ b/src/obj2model.c @@ -22,6 +22,19 @@ #define MAX_VERTICES 65536 +static char *texname(const char *filename) { + int i; + char *rval; + rval = strdup(filename); + for ( i=0; iattribs & ATTRIB_SHINY ) { - GLfloat white[] = {1.0, 1.0, 1.0, 1.0}; - glMaterialfv(GL_FRONT, GL_SPECULAR, white); + GLfloat spec[4]; + if ( p->attribs & ATTRIB_COLSPEC ) { + spec[0] = p->colspec; + spec[1] = p->colspec; + spec[2] = p->colspec; + spec[3] = 1.0; + } else { + spec[0] = 1.0; + spec[1] = 1.0; + spec[2] = 1.0; + spec[3] = 1.0; + } + glMaterialfv(GL_FRONT, GL_SPECULAR, spec); glMaterialf(GL_FRONT, GL_SHININESS, p->shininess); shaderutils_setunf(r->lighting_program, "shininess", p->shininess); shaderutils_setunf(r->fill_program, "shininess", p->shininess); diff --git a/src/types.h b/src/types.h index 7f1119f..1304650 100644 --- a/src/types.h +++ b/src/types.h @@ -49,6 +49,7 @@ typedef enum { ATTRIB_RADIUS = 1<<2, /* Radius is set */ ATTRIB_SHINY = 1<<3, /* Primitive is shiny */ ATTRIB_SWIRLY = 1<<4, /* Primitive is texture with swirlyness */ + ATTRIB_COLSPEC = 1<<5, /* Specular colour specified? */ } PrimitiveAttrib; typedef enum { @@ -71,6 +72,7 @@ typedef struct { GLfloat col_r; GLfloat col_g; GLfloat col_b; + GLfloat colspec; char *texture; GLfloat radius; GLfloat shininess; -- cgit v1.2.3