DirectDraw problem
Hi,
I am trying to animate a character using the primary surface and a backbuffer.
The animation consists of 4 frames.
First, I blit frame 1 into back buffer, and flip it with primary surface. Then I blit frame 2 into the back buffer, and flip it with the primary and so on.
However, when I run the program, all four frames can be seen on the primary, instead of being animated.. Am I missing a step or doing something wrong?
I'm a newbie, please don't hurt me!
Perhaps if you post the code...
Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development
Im sorry I didnt post it since I don''t know how to make that cool little box but here it is.
to keep the code short, this is only the first 2 frames
// ANIMATING ROBOT
LPDIRECTDRAWSURFACE7 lpRobot = DDLoadBitmap(lpdd, "Dedsp0.bmp", 0, 0);
DDSetColorKey(lpRobot, RGB(0, 0, 0));
source.left = 1;
source.top = 1;
source.right = 72;
source.bottom = 80;
lpddsback->BltFast(100, 100, lpRobot, &source,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
lpddsprimary->Flip(NULL, DDFLIP_WAIT);
source.left = 74;
source.top = 1;
source.right = 145;
source.bottom = 80;
lpddsback->BltFast(100, 100, lpRobot, &source,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
lpddsprimary->Flip(NULL, DDFLIP_WAIT);
to keep the code short, this is only the first 2 frames
// ANIMATING ROBOT
LPDIRECTDRAWSURFACE7 lpRobot = DDLoadBitmap(lpdd, "Dedsp0.bmp", 0, 0);
DDSetColorKey(lpRobot, RGB(0, 0, 0));
source.left = 1;
source.top = 1;
source.right = 72;
source.bottom = 80;
lpddsback->BltFast(100, 100, lpRobot, &source,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
lpddsprimary->Flip(NULL, DDFLIP_WAIT);
source.left = 74;
source.top = 1;
source.right = 145;
source.bottom = 80;
lpddsback->BltFast(100, 100, lpRobot, &source,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
lpddsprimary->Flip(NULL, DDFLIP_WAIT);
I'm a newbie, please don't hurt me!
December 10, 2002 11:17 AM
hi. i`m not sure but tey to clear the buffer before you fill it again.
That''s what I suspected. But this may be a dumb question, but how do you clear it? It doesnt tell me how to in my book...
I'm a newbie, please don't hurt me!
ok.
lock the buffer first:
lpDDSBuffer->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL)
then try this function.
ddsd is a DDSURFACEDESC2
void clear(int width,int hight,DDSURFACEDESC2 ddsd)
{
LPVOID vidStart = 0;
vidStart = ddsd.lpSurface;
_asm
{
push esi
pushf
mov esi,vidStart
mov eax,width
mov ebx,hight
mul ebx
mov dh,0
jump1:
mov ebx,4
jump2:
mov [esi],dh ;b
inc esi
dec ebx
jnz jump2
dec eax
jnz jump1
popf
pop esi
}
}
there should be a faster way but this should work fine
try it
lock the buffer first:
lpDDSBuffer->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL)
then try this function.
ddsd is a DDSURFACEDESC2
void clear(int width,int hight,DDSURFACEDESC2 ddsd)
{
LPVOID vidStart = 0;
vidStart = ddsd.lpSurface;
_asm
{
push esi
pushf
mov esi,vidStart
mov eax,width
mov ebx,hight
mul ebx
mov dh,0
jump1:
mov ebx,4
jump2:
mov [esi],dh ;b
inc esi
dec ebx
jnz jump2
dec eax
jnz jump1
popf
pop esi
}
}
there should be a faster way but this should work fine
try it
December 10, 2002 11:46 AM
I would clear it using the DDBLTFX_COLORFILL and if i remember correctly, ddbltfx.dwColor = color; Anyhow the correct syntax is described in the SDK.
(don''t know how fast it is, but atleast it easier to understand if something goes wrong
(don''t know how fast it is, but atleast it easier to understand if something goes wrong
Although the way your doing your animation will work, you should consider doing all your rendering in a loop. Clear the back buffer at the beginning of the loop, blt one frame of the animation, and flip to the primary at the end of the loop. When you want to display the next frame update the coordinates.
digital radiation
digital radiation
You can use the BLT function. I found this in the docs for you (DirectX 6.1):
Color Fills
In order to fill all or part of a surface with a single color, you can use the IDirectDrawSurface4::Blt method with the DDBLT_COLORFILL flag. This technique allows you to quickly erase an area or draw a solid-colored background.
The following example fills an entire surface with the color blue, after obtaining the numerical value for blue from the pixel format:
Color Fills
In order to fill all or part of a surface with a single color, you can use the IDirectDrawSurface4::Blt method with the DDBLT_COLORFILL flag. This technique allows you to quickly erase an area or draw a solid-colored background.
The following example fills an entire surface with the color blue, after obtaining the numerical value for blue from the pixel format:
/* It is assumed that lpDDS is a valid pointer to an IDirectDrawSurface4 interface. */ HRESULT ddrval;DDPIXELFORMAT ddpf; ddpf.dwSize = sizeof(ddpf);if (SUCCEEDED(lpDSS->GetPixelFormat(&ddpf)){ DDBLTFX ddbltfx; ddbltfx.dwSize = sizeof(ddbltfx); ddbltfx.dwFillColor = ddpf.dwBBitMask; // Pure blue ddrval = lpDDS->Blt( NULL, // Destination is entire surface NULL, // No source surface NULL, // No source rectangle DDBLT_COLORFILL, &ddbltfx); switch(ddrval) { case DDERR_WASSTILLDRAWING: . . . case DDERR_SURFACELOST: . . . case DD_OK: . . . default: } }
-------------Ban KalvinB !
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement