Hello,
I’m sorry to bother you for something that you could find trivial but I have a trouble with the function vgReadPixels :
I draw several Paths but when I use the fonction vgReadPixels, i have no data in my destination buffer (only 0).
I thought that it is because the function don’t use the correct drawing surface. Do you see any other reason that disabled the reading of my drawing surface.
I think I have to precise that I cannot use the EGL library.
For be more clear I give you my source code :
int main(int argc, char** argv)
{
int i;
const short WIDTH = 744;
const short HEIGHT = 1052;
const char* outName = "dump.tga";
float clearColor[4] = {1.0f,0.0f,1.0f,1.0f};
VGPath paths[NUM_PATHS];
VGPaint paint;
/* Initialize */
paint = vgCreatePaint();
vgSetPaint(paint, VG_FILL_PATH);
vgSeti(VG_FILL_RULE, VG_NON_ZERO);
vgFinish();
for(i=0;i<NUM_PATHS;i++)
{
paths[i] = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, (unsigned int)VG_PATH_CAPABILITY_ALL);
vgAppendPathData(paths[i], obj_paths[i].nCommands, (VGubyte*)obj_paths[i].cmds, (VGubyte*)obj_paths[i].floats);
vgFinish();
}
/* Render */
vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
vgClear(0, 0, WIDTH, HEIGHT);
vgFinish();
for(i = 0; i < NUM_PATHS; i++)
{
vgSetColor(paint, obj_paths[i].color | 255);
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
vgLoadIdentity();
vgScale(0.2f, 0.2f);
vgMultMatrix(obj_paths[i].transform);
vgDrawPath(paths[i], VG_FILL_PATH);
vgFinish();
switch(vgGetError())
{
case VG_BAD_HANDLE_ERROR :
fprintf(stderr, "erreur : VG_BAD_HANDLE_ERROR
");
break;
}
}
/* Save framebuffer to disk */
VGubyte *dst;
dst = malloc(WIDTH*HEIGHT*4*sizeof(VGubyte));
vgReadPixels(dst, WIDTH *4* sizeof(VGubyte), VG_sARGB_8888, 0, 0, WIDTH, HEIGHT);
switch(vgGetError())
{
case VG_UNSUPPORTED_IMAGE_FORMAT_ERROR :
fprintf(stderr, "erreur : VG_UNSUPPORTED_IMAGE_FORMAT_ERROR
");
break;
}
for(i=0;i<WIDTH*HEIGHT;i++)
{
//dst[4*i]=255; //A
//dst[(4*i)+1]=255; //R
//dst[(4*i)+2]=0; //G
//dst[(4*i)+3]=255; //B
printf("[%d,%d,%d,%d]
",dst[4*i],dst[(4*i)+1],dst[(4*i)+2],dst[(4*i)+3]);
}
if(!exportTGA(outName, WIDTH, HEIGHT, (VGuint*)dst))
fprintf(stderr, "Failed to save framebuffer!
");
/* Cleanup */
vgDestroyPaint(paint);
for(i = 0; i < NUM_PATHS; i++)
vgDestroyPath(paths[i]);
free(dst);
return 0;
}