diff options
-rw-r--r-- | src/game.c | 1 | ||||
-rw-r--r-- | src/model.c | 14 | ||||
-rw-r--r-- | src/render.c | 13 | ||||
-rw-r--r-- | src/types.h | 6 |
4 files changed, 26 insertions, 8 deletions
@@ -278,6 +278,7 @@ Game *game_new(int width, int height) { g->lander->x = 0.0; g->lander->y = 0.0; g->lander->z = -4.95; + g->lander->yaw = deg2rad(30.0); g->lander->attribs = OBJ_GRAVITY; return g; diff --git a/src/model.c b/src/model.c index 2f768f5..bb8758f 100644 --- a/src/model.c +++ b/src/model.c @@ -154,7 +154,7 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render FILE *fh; char tmp[64]; Model *model; - GLenum type; + PrimitiveType type; int num_vertices; GLfloat *vertices; GLfloat *normals; @@ -176,7 +176,7 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render normals = malloc(MAX_VERTICES*3*sizeof(GLfloat)); texcoords = malloc(MAX_VERTICES*2*sizeof(GLfloat)); num_vertices = 0; - type = GL_TRIANGLES; + type = PRIMITIVE_TRIANGLES; attribs = ATTRIB_NONE; texture = NULL; while ( !feof(fh) ) { @@ -199,17 +199,17 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render model_add_primitive(model, type, vertices, normals, texcoords, num_vertices, attribs, col_r, col_g, col_b, texture); num_vertices = 0; - type = GL_TRIANGLES; + type = PRIMITIVE_TRIANGLES; attribs = ATTRIB_NONE; texture = NULL; } } if ( strncmp(line, "QUADS", 5) == 0 ) { - type = GL_QUADS; + type = PRIMITIVE_QUADS; } if ( strncmp(line, "TRIANGLES", 9) == 0 ) { - type = GL_TRIANGLES; + type = PRIMITIVE_TRIANGLES; } if ( sscanf(line, "%f %f %f %f %f", &forget, &forget, &forget, &x, &y) == 5 ) { @@ -223,11 +223,11 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render texcoords[2*num_vertices+0] = texx; texcoords[2*num_vertices+1] = texy; num_vertices++; - if ( (type == GL_QUADS) && ((num_vertices % 4)==0) ) { + if ( (type == PRIMITIVE_QUADS) && ((num_vertices % 4)==0) ) { model_calculate_normals(vertices, normals, num_vertices-4, num_vertices-1, num_vertices-4, num_vertices-3, num_vertices-2); } - if ( (type == GL_TRIANGLES) && ((num_vertices % 3)==0) ) { + if ( (type == PRIMITIVE_TRIANGLES) && ((num_vertices % 3)==0) ) { model_calculate_normals(vertices, normals, num_vertices-3, num_vertices-1, num_vertices-3, num_vertices-2, num_vertices-1); } diff --git a/src/render.c b/src/render.c index e2f1197..a68d14c 100644 --- a/src/render.c +++ b/src/render.c @@ -138,6 +138,17 @@ void render_shutdown(RenderContext *ctx) { texture_free_all(ctx); } +static GLenum render_gltype(PrimitiveType type) { + + switch ( type ) { + case PRIMITIVE_QUADS : return GL_QUADS; + case PRIMITIVE_TRIANGLES : return GL_TRIANGLES; + } + + return GL_FALSE; + +} + static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderContext *ctx) { int j; @@ -193,7 +204,7 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC glVertexPointer(3, GL_FLOAT, 0, p->vertices); glNormalPointer(GL_FLOAT, 0, p->normals); glTexCoordPointer(2, GL_FLOAT, 0, p->texcoords); - glDrawArrays(p->type, 0, p->num_vertices); + glDrawArrays(render_gltype(p->type), 0, p->num_vertices); glPopMatrix(); diff --git a/src/types.h b/src/types.h index bb4111f..75b6d30 100644 --- a/src/types.h +++ b/src/types.h @@ -34,6 +34,12 @@ typedef enum { ATTRIB_PULSE = 1<<1, /* Pulsating colour */ } PrimitiveAttrib; +typedef enum { + PRIMITIVE_QUADS, + PRIMITIVE_TRIANGLES, + PRIMITIVE_HEMISPHERE +} PrimitiveType; + typedef struct { GLenum type; |