Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BeanDog

Can anyone actually tell me how to use ->Lock?

This topic is 6935 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

You know, hundreds of messages on here every week are about this, but I searched here and the DX documentation and directxfaq.com and others and NOBODY ACTUALLY SAYS HOW TO DO IT!!! Here''s my try without much help: DDSURFACEDESC2 ddsd; DDSURFACEDESC2 ddsd2; Back->Lock(NULL, &ddsd, DDLOCK_WRITEONLY, NULL); CreaturePics[picnum]->Lock(NULL, &ddsd2, DDLOCK_READONLY, NULL); for (int sy = 0; sy < ddsd2.dwHeight; sy++) { for (int sx = sy%2; sx < ddsd2.dwWidth; sx+=2) { if( ((BYTE*) ddsd2.lpSurface)[sy*ddsd2.lPitch + sx] != 0) ((BYTE*)ddsd.lpSurface)[(y+sy+8)*ddsd.lPitch + (x+sx)] = 0; } } CreaturePics[picnum]->Unlock(NULL); Back->Unlock(NULL); This locks up every time I try it. It is trying to dither anything on the CreaturePics[picnum] surface that is not black onto the backbuffer as black. This is for a shadow effect for my creature. This locks up the system. Why? ~BenDilts( very stinking angry );

Share this post


Link to post
Share on other sites
Advertisement
I can see 2 problems already!

1. You cannot lock within another lock.
2. You must GET the ddsd variable from the device.

You could lock one surface then get the values and put them in an array. After that lock the other surface and put the values that were in the array onto the surface.

Please help this person everyone. I do not know C++, so I''m not too much help.

Share this post


Link to post
Share on other sites
quote:
Original post by BeanDog

for (int sx = sy%2; sx < ddsd2.dwWidth; sx+=2)


Shouldn't that be ddsd2.lPitch, not .dwWidth? Also, you could try

DDSURFACEDESC2 ddsd;
DDSURFACEDESC2 ddsd2;

memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
memset(&ddsd2, 0, sizeof(DDSURFACEDESC2));


It's always wise to zero structure memory before (filling in the members) and passing it around.

quote:
Original post by BeanDog

((BYTE*)ddsd.lpSurface)[(y+sy+8)*ddsd.lPitch + (x+sx)] = 0;


What are x and y?

It would be good for performance to do, after the Locks and before the nested fors

BYTE* lpBack = (BYTE*)ddsd.lpSurface;
BYTE* lpCreature = (BYTE*)ddsd2.lpSurface;


And refer to those in the fors. All that casting is nasty; it will be done /every/ loop - unless your compiler is different to mine.

quote:
Original post by nes8bit

1. You cannot lock within another lock.


Is that true? If so, it's pretty stupid.

quote:
Original post by nes8bit
2. You must GET the ddsd variable from the device.


Are you sure? I can't remember how my code does it (I wrote it ages ago, in a class), but I know that GetSurfaceDesc doesn't return a surface pointer. Lock fills that in; it's why you pass a surfacedesc pointer into it.


TheTwistedOne
http://www.angrycake.com

Edited by - TheTwistedOne on 4/27/00 5:38:08 AM

Share this post


Link to post
Share on other sites
Thanks for the input, but a few things.

x and y are the sprite''s position - on my map, not the screen (man is my face red - I''ll fix that).

You can (i''m pretty sure) lock between locks, so long as it''s not the same surface, correct?

I''ll try the memset idea.

If, say, dx and dy are the final pixel coords on a surface I want to read/write to/from, then how do I figure out what the offset thingy ought to be? For instance, if I wanted to access the point 50, 150 (x,y) on a surface, would it be:
((BYTE*)ddsd.lpSurface)[(150)*ddsd.lPitch + (50)]
?

Also, do I have to use the GetSurfDesc or whatever before I call the lock? I need someone that really knows for sure. Reboots take 12 minutes on my machine (like 100 peripherals).

~BenDilts( int Thanks_Guys ) {delete [] myCode;}


Share this post


Link to post
Share on other sites

  • 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!