Jump to content
  • Advertisement
Sign in to follow this  
tadobie

mirror imaging

This topic is 5399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone explain how to make a mirror image of a direct draw surface. I need to flip a charcters direction from facing left to facing right.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

I've never had to do this myself before, and I've also never used DirectDraw that much, but I would imagine you are looking for something like this:


for(int y = 0; y < ImageHeight; y++)
{
for(int x = 0; x < (ImageWidth / 2); x++)
{
int x1 = x, x2 = (ImageWidth - 1) - x;
int Offset1, Offset2;

Offset1 = (y * ImagePitch) + x1;
Offset2 = (y * ImagePitch) + x2;

int Temp = pData[Offset1];
pData[Offset1] = pData[Offset2];
pData[Offset2] = pData[Temp];
}
}




That should about do it. Basically, you loop through each row of the image, and for each row you perform a series of pixel swaps. For any row:

- Get the first pixel in the row
- Get the last pixel in the row
- Swap them over

Then, as we loop through (x) again:

- Get the second pixel in the row
- Get the last but one pixel in the row
- Swap them over

Keep doing this until the pixels meet in the middle, and then move on to the next row.

Share this post


Link to post
Share on other sites
There's a flag (DDBLTFX_MIRRORLEFTRIGHT?) that allows you to perform mirrored blits. That will save you from having to make mirrored copies in memory.

Share this post


Link to post
Share on other sites
Can you explain to me how to implement the DDBLTFX_MIRRORLEFTRIGHT flag? Is it a matter of just:

ps_BackBuffer->BltFast( x, y, pdds, prc, DDBLTFX_MIRRORLEFTRIGHT );

or do I need some other code to set up the flag?

Share this post


Link to post
Share on other sites
I don't think you can do it with BltFast. You need to initialize a structure containing extra parameters and call Blt:


DDBLTFX blitfx;

// in initialization somewhere
memset(&blitfx, 0, sizeof(blitfx));
blitfx.dwSize = sizeof(blitfx);
blitfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT;

// to draw mirrored images
ps_BackBuffer->Blt(&target_rect, source_surface, &source_rect, DDBLT_DDFX, &blitfx);


I think that's right anyhow. It's been a while since I last used DirectDraw.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!