diff --git a/cogl-material.h b/cogl-material.h index 2ad878551..59cb47d04 100644 --- a/cogl-material.h +++ b/cogl-material.h @@ -52,6 +52,19 @@ CoglHandle cogl_material_ref (CoglHandle handle); */ void cogl_material_unref (CoglHandle handle); +/** + * cogl_material_set_color: + * @material: A CoglMaterial object + * @color: The components of the color + * + * This is the basic color of the material, used when no lighting is enabled. + * + * The default value is (1.0, 1.0, 1.0, 1.0) + * + * Since 1.0 + */ +void cogl_material_set_color (CoglHandle material, const CoglColor *color); + /** * cogl_material_set_ambient: * @material: A CoglMaterial object diff --git a/common/cogl-material.c b/common/cogl-material.c index 2e9f5a353..b0b9fd955 100644 --- a/common/cogl-material.c +++ b/common/cogl-material.c @@ -11,6 +11,7 @@ #include "cogl-material-private.h" #include +#include static void _cogl_material_free (CoglMaterial *tex); static void _cogl_material_layer_free (CoglMaterialLayer *layer); @@ -25,6 +26,7 @@ cogl_material_new (void) { /* Create new - blank - material */ CoglMaterial *material = g_new0 (CoglMaterial, 1); + GLfloat *unlit = material->unlit; GLfloat *ambient = material->ambient; GLfloat *diffuse = material->diffuse; GLfloat *specular = material->specular; @@ -33,6 +35,9 @@ cogl_material_new (void) material->ref_count = 1; COGL_HANDLE_DEBUG_NEW (material, material); + /* Use the same defaults as the GL spec... */ + unlit[0] = 1.0; unlit[1] = 1.0; unlit[2] = 1.0; unlit[3] = 1.0; + /* Use the same defaults as the GL spec... */ ambient[0] = 0.2; ambient[1] = 0.2; ambient[2] = 0.2; ambient[3] = 1.0; diffuse[0] = 0.8; diffuse[1] = 0.8; diffuse[2] = 0.8; diffuse[3] = 1.0; @@ -63,6 +68,29 @@ _cogl_material_free (CoglMaterial *material) g_free (material); } +void +cogl_material_set_color (CoglHandle handle, + const CoglColor *unlit_color) +{ + CoglMaterial *material; + GLfloat unlit[4]; + + g_return_if_fail (cogl_is_material (handle)); + + material = _cogl_material_pointer_from_handle (handle); + + unlit[0] = cogl_color_get_red_float (unlit_color); + unlit[1] = cogl_color_get_green_float (unlit_color); + unlit[2] = cogl_color_get_blue_float (unlit_color); + unlit[3] = cogl_color_get_alpha_float (unlit_color); + if (memcmp (unlit, material->unlit, sizeof (unlit)) == 0) + return; + + memcpy (material->unlit, unlit, sizeof (unlit)); + + material->flags |= COGL_MATERIAL_FLAG_DIRTY; +} + void cogl_material_set_ambient (CoglHandle handle, const CoglColor *ambient_color) @@ -667,6 +695,8 @@ cogl_flush_material_gl_state (void) && !(material->flags & COGL_MATERIAL_FLAG_DIRTY)) return; + GE (glColor4fv (material->unlit)); + /* FIXME - we only need to set these if lighting is enabled... */ GE (glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, material->ambient)); GE (glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, material->diffuse));