Thanks for the quick reply.
After doing more tests, I realized that the Photon Image Viewer doesn't
support transparent pngs. Loading my png with firefox gives a transparent
background while the image viewer gives me whatever background color I
had in the surface (from glClear()). ...am I making any sense here?
The last problem I'm having is that the same surface blitted to the PtRaw
gives a black background. It looks like the PgContextBlit() call doesn't
handle the alpha channel of the gf_surface. Do you have a hint on how to
do this?
For the record, here's what I have (error handling removed):
gf_dev_t gf_dev;
gf_dev_info_t info;
gf_dev_attach(&gf_dev, 0, &info);
gf_display_t gf_display;
gf_display_info_t gf_display_info;
gf_display_attach(&gf_display, gf_dev, 0, &gf_display_info);
gf_surface_create(
&g_gf_surface, gf_dev, 100, 100,
gf_display_info.format, 0, 0);
EGLDisplay display = eglGetDisplay(gf_dev);
eglInitialize(display, 0, 0);
EGLint attributes[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
EGLConfig config;
EGLint num_config = 0;
eglChooseConfig(display, attributes, &config, 1, &num_config);
EGLContext context =
eglCreateContext(display, config, EGL_NO_CONTEXT, 0);
EGLSurface surface =
eglCreatePixmapSurface(display, config, g_gf_surface, 0);
eglMakeCurrent(display, surface, surface, context);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, 100, 100);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glOrthox(fix(0), fix(100), fix(0), fix(100), fix(-1), fix(1));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
After this, I create a PtWindow containing a PtRaw:
PtInit(0);
PtArg_t args[4];
PhDim_t dim = {100, 100};
PtSetArg(&args[0], Pt_ARG_DIM, &dim, 0);
PtSetArg(&args[1], Pt_ARG_WINDOW_TITLE, "", 0);
PtWidget_t* window =
PtCreateWidget(PtWindow, Pt_NO_PARENT, 2, args);
PtSetArg(&args[1], Pt_ARG_RAW_DRAW_F, raw_draw, 0);
PtWidget_t* raw = PtCreateWidget(PtRaw, Pt_DFLT_PARENT, 2, args);
// g_context is a PdOffscreenContext_t*
g_context = PdCreateOffscreenContextGF(g_gf_surface);
Here's the draw function (where draw_rect() is a wrapper around
glDrawArrays with GL_TRIANGLE_STRIP):
glColor4f(0.0, 0.0, 1.0, 0.5);
draw_rect(20, 20, 70, 70);
glColor4f(0.0, 1.0, 0.0, 0.5);
draw_rect(30, 30, 90, 50);
PhRect_t src_rect = {{0, 0}, {100, 100}};
PhRect_t dest_rect = {{0, 0}, {100, 100}};
PgContextBlit(g_context, &src_rect, PhDCGetCurrent(), &dest_rect);
gf_surface_info_t info;
gf_surface_get_info(g_gf_surface, &info);
img_t img;
memset(&img, 0, sizeof(img_t));
img.access.direct.data = info.vaddr;
img.access.direct.stride = info.stride;
img.w = info.w;
img.h = info.h;
img.format = gf_to_img_format(info.format);
img.npalette = info.palette.ncolors;
img.palette = info.palette.colors;
img.flags =
IMG_FORMAT | IMG_W | IMG_H | IMG_DIRECT | IMG_PALETTE;
img_write_file(ilib, "test.png", 0, &img);