Commit 99dffcc6be6ba995efc9f1fa47f4813bb759bd40
authorMichel Pollet <buserror@gmail.com>
Fri, 15 Jun 2012 08:21:44 +0000 (09:21 +0100)
committerMichel Pollet <buserror@gmail.com>
Fri, 15 Jun 2012 08:21:44 +0000 (09:21 +0100)
Handles (some) fo the light parameters

Signed-off-by: Michel Pollet <buserror@gmail.com>
examples/shared/libc3/srcgl/c3gl.c

index e9cbc7a6a9ec68fb17ad0f7ebfae12b0841b5224..f6923a2e6e2e79db838c1597bf359c986d3da2cc 100644 (file)
@@ -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);