From 99dffcc6be6ba995efc9f1fa47f4813bb759bd40 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Fri, 15 Jun 2012 09:21:44 +0100 Subject: [PATCH] c3gl: Implemements lights Handles (some) fo the light parameters Signed-off-by: Michel Pollet --- examples/shared/libc3/srcgl/c3gl.c | 32 ++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) 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); -- 2.39.5