On Wed, 2008-08-27 at 13:10 +0200, Arnaud VALLAT wrote:
> I've played with cogl_texture_polygon and succeeded to render a
> gradient. But I can't make a gradient from a color (blue for example)
> and a clear color (black with alpha at 0) because I have filled the
> texture with white. Is there a way to clear a texture ? like a memset
> it ?
I'm not sure what you mean. You should be able to leave the texture as
all white and the just change the colour using the color member of
CoglTextureVertex. The final alpha drawn to the screen is the alpha of
the vertex colour multiplied by the alpha value of the texture, so at
vertices where you specify a zero alpha it should result in a fully
transparent image. Please see the attached example.
- Neil
#include <clutter/clutter.h>
static void
on_paint (ClutterActor *actor, CoglHandle tex)
{
ClutterActor *stage;
guint width, height;
stage = clutter_actor_get_stage (actor);
clutter_actor_get_size (stage, &width, &height);
{
CoglTextureVertex verts[]
= { { CLUTTER_INT_TO_FIXED (0), CLUTTER_INT_TO_FIXED (0), 0,
CFX_ONE / 2, CFX_ONE / 2,
{ 0xff, 0x00, 0x00, 0xff } },
{ CLUTTER_INT_TO_FIXED (width / 2), CLUTTER_INT_TO_FIXED (0), 0,
CFX_ONE / 2, CFX_ONE / 2,
{ 0x00, 0xff, 0x00, 0xff } },
{ CLUTTER_INT_TO_FIXED (width / 2), CLUTTER_INT_TO_FIXED (height), 0,
CFX_ONE / 2, CFX_ONE / 2,
{ 0x00, 0xff, 0x00, 0x00 } },
{ CLUTTER_INT_TO_FIXED (0), CLUTTER_INT_TO_FIXED (height), 0,
CFX_ONE / 2, CFX_ONE / 2,
{ 0xff, 0x00, 0x00, 0x00 } } };
cogl_texture_polygon (tex, 4, verts, TRUE);
}
}
int
main (int argc, char **argv)
{
ClutterActor *stage = stage;
guchar white_image_data[] = { 0xff, 0xff, 0xff, 0xff };
CoglHandle tex;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage),
&(ClutterColor) { 0x80, 0x80, 0xff, 0xff });
tex = cogl_texture_new_from_data (1, 1, -1, FALSE,
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
4, white_image_data);
g_signal_connect_after (stage, "paint", G_CALLBACK (on_paint), tex);
clutter_actor_show (stage);
clutter_main ();
cogl_texture_unref (tex);
return 0;
}