PDA

View Full Version : alpha value when drawing image



remiverdet
06-24-2010, 02:58 AM
Hello,

I work on a freescale IMX51 target under WinCE.
I am not able to activate alpha blending when drawing images.
Can you help?

Here is my EGL config:

static const EGLint s_configAttribs[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_LUMINANCE_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE
};

Here is my image creation:

VGuint *buffer = new VGuint [255*255];
width = 255;
height = 255;
long i = 0;
long size = width * height;

VGuint *pter = buffer;
for(unsigned int i=0; i<height; i++)
{
for(unsigned int j=0; j<width; j++)
{
*pter++ = RGBA(255,0,0,i);
}

}

vgImage = vgCreateImage(VG_sRGBA_8888, width, height, VG_IMAGE_QUALITY_BETTER);
vgImageSubData(vgImage, buffer, 4*width, VG_sRGBA_8888, 0, 0, width, height);

VGErrorCode err = vgGetError ();

free ( buffer );


Here is the image rendering:

float clearColor[4] = {0,0,0,0};
vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
vgClear(0, 0, i32WindowWidth, i32WindowHeight);

vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
vgLoadIdentity();

vgDrawImage (vgImage);
VGErrorCode err = vgGetError ();


I can see a red square without any alpha shading or gradation.
I checked that the image is OK in memory (alpha changes).
I have the same behavior with a png image (image OK but no alpha change).
Do I have to enable blending with a specific command (change VG_IMAGE_MODE? VG_COLOR_TRANSFORM?)

Thank you for your support !

brian.edmond
06-24-2010, 06:06 AM
When I render images I use:
vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL );
If I need to add a global alpha blend then I set:
// set the global alpha in the color
vgSetParameterfv(mgr->paint, VG_PAINT_COLOR, 4, col);
vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY );

This works for png files with per pixel alpha. As a side note I get much better performance when using a pre-multiplied image format.

Brian

belief87
01-05-2011, 10:46 PM
When I render images I use:
vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL );
If I need to add a global alpha blend then I set:
// set the global alpha in the color
vgSetParameterfv(mgr->paint, VG_PAINT_COLOR, 4, col);
vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY );

This works for png files with per pixel alpha. As a side note I get much better performance when using a pre-multiplied image format.

Brian

This works for me. Thanks.