context blit

Hi,

I am using an off-screen context to create an image and then blitting this
image to the screen in a PtRaw widget’s draw function. For some reason, the
image only flashes up momemtarily. If I move the blitting part outside of
the draw function, it works okay.
I am using the following code to create the image:

context = PdCreateOffscreenContext( 0, WIDTH, HEIGHT, 0 );

olddc = PhDCSetCurrent( context );
//draw image
PhDCSetCurrent( olddc );

and the following code to draw the image:

area.pos.x = area.pos.y = 0;
area.size.w = WIDTH;
area.size.h = HEIGHT;
PgContextBiltArea( context, &area, NULL, &area );
PgFlush();

Any ideas why this might be happening?

Hello, Will!

WO> PgContextBiltArea( context, &area, NULL, &area );

You are blitting directly to display and it’s wrong. After blitting some
widgets redraws itself and your image will gone. So if you are using
blitters - use them everywhere, if you are using widgets - use them only.
That’s one small rule - don’t mix Pg and Pt functions.

With best regards, Mike Gorchak. E-mail: mike@malva.com.ua

Will O’Neill wrote:

I am using an off-screen context to create an image and then blitting this
image to the screen in a PtRaw widget’s draw function. For some reason, the
image only flashes up momemtarily. If I move the blitting part outside of
the draw function, it works okay.
I am using the following code to create the image:

context = PdCreateOffscreenContext( 0, WIDTH, HEIGHT, 0 );

olddc = PhDCSetCurrent( context );
//draw image
PhDCSetCurrent( olddc );

and the following code to draw the image:

area.pos.x = area.pos.y = 0;
area.size.w = WIDTH;
area.size.h = HEIGHT;
PgContextBiltArea( context, &area, NULL, &area );
PgFlush();

Any ideas why this might be happening?

Possibly because your raw widget is not positioned at 0,0?

The following draw function works for me:

void rawdraw( PtWidget_t *widget, PhTile_t *damage ) {
static const PhArea_t srcarea = { { 0, 0 }, { WIDTH, HEIGHT } };
PhRect_t canvas;
PhArea_t dstarea;

PtSuperClassDraw( PtBasic, widget, damage );

PtCalcCanvas( widget, &canvas );
dstarea.pos = canvas.ul;
dstarea.size = srcarea.size;

PgContextBlitArea( context, &srcarea, NULL, &dstarea );
}

Hi Mike,

So is it possible to copy the image from the offscreen context to the raw
widget instead of directly to the display?
Or if you are using offscreen contexts, do you have to write directly to the
display, instead of using raw widgets.

Thanks,
Will.


Hello, Will!

WO> PgContextBiltArea( context, &area, NULL, &area );

You are blitting directly to display and it’s wrong. After blitting some
widgets redraws itself and your image will gone. So if you are using
blitters - use them everywhere, if you are using widgets - use them only.
That’s one small rule - don’t mix Pg and Pt functions.

With best regards, Mike Gorchak. E-mail: > mike@malva.com.ua