From: Michel Pollet Date: Fri, 15 Jun 2012 08:21:44 +0000 (+0100) Subject: c3gl: Implemements lights X-Git-Tag: v1.0~74 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=99dffcc6be6ba995efc9f1fa47f4813bb759bd40;p=sx%2Fsimavr.git c3gl: Implemements lights Handles (some) fo the light parameters Signed-off-by: Michel Pollet --- diff --git a/examples/shared/libc3/srcgl/c3gl.c b/examples/shared/libc3/srcgl/c3gl.c index e9cbc7a..f6923a2 100644 --- a/examples/shared/libc3/srcgl/c3gl.c +++ b/examples/shared/libc3/srcgl/c3gl.c @@ -36,6 +36,7 @@ #include "c3.h" #include "c3lines.h" #include "c3sphere.h" +#include "c3light.h" #include "c3program.h" #include "c3driver_context.h" @@ -219,6 +220,8 @@ static void _c3_load_vbo( c3geometry_p g) { + if (!g->vertice.count) + return ; if (!g->bid) { GLuint vao; glGenVertexArrays(1, &vao); @@ -321,6 +324,14 @@ _c3_geometry_project( if (g->mat.texture) g->type.subtype = (c3apiobject_t)GL_TRIANGLE_FAN; } break; + case C3_LIGHT_TYPE: { + c3light_p l = (c3light_p)g; + GLuint lid = GL_LIGHT0 + (int)l->light_id; + if (l->color.specular.w > 0) + glLightfv(lid, GL_SPECULAR, l->color.specular.n); + if (l->color.ambiant.w > 0) + glLightfv(lid, GL_AMBIENT, l->color.ambiant.n); + } break; default: break; } @@ -341,15 +352,28 @@ _c3_geometry_draw( const struct c3driver_context_t *d, c3geometry_p g ) { - glColor4fv(g->mat.color.n); - dumpError("glColor"); -// glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, g->mat.color.n); - c3mat4 eye = c3mat4_mul( &g->object->world, &c3context_view_get(g->object->context)->cam.mtx); glLoadMatrixf(eye.n); + switch(g->type.type) { + case C3_LIGHT_TYPE: { + c3light_p l = (c3light_p)g; + GLuint lid = GL_LIGHT0 + (int)l->light_id; + glLightfv(lid, GL_POSITION, l->position.n); + if (c3context_view_get(c)->type != C3_CONTEXT_VIEW_LIGHT) + glEnable(lid); + else + glDisable(lid); + } break; + } + if (!g->bid) + return; + + glColor4fv(g->mat.color.n); + dumpError("glColor"); + GLCHECK(glBindVertexArray((GLuint)g->bid)); glDisable(GL_TEXTURE_2D);