I was about to point you to the document of Lock & Unlock in the Managed
DirectX SDK, but I immediately realized that the document is so preliminary
that it gives you virtually no information
So I sat down with the C# SpriteAnimate sample and modified its
ProcessNextFrame method a bit to show how to lock and modify the surface
memory. My modification starts after the DisplayFrame call. All it does is
to modify the surfaceAnimation sufrace into random horizontal lines.
Note that it seems the Lock method returns the array in wrong ranks. So I
used an unsafe pointer to workaround it (and boost up the performance). I
will go ahead and check if it is a real bug.
If you are not familiar with unsafe code, you can check Eric Gunnerson's
unsafe private void ProcessNextFrame()
// Figure how much time has passed since the last time.
int tickCurrent = Environment.TickCount;
int tickDifference = tickCurrent - tickLast;
// Don't update if no time has passed.
if (0 == tickDifference)
tickLast = tickCurrent;
// Move the sprites according to how much time has passed.
for (int i = 0; i < numSprites; i++)
UpdateSprite(ref sprite[i], tickDifference / 1000.0f);
//Draw the sprites and text to the screen.
short[,] buf1 = (short[,]) surfaceAnimation.Lock(LockFlags.Wait |
fixed(short* buf = &buf1[0,0])
int width = surfaceAnimation.SurfaceDescription.Width;
for(int y = 0; y < surfaceAnimation.SurfaceDescription.Height; y++)
short color = (short)(GetNextRand() & 65535);
for(int x = 0; x < width; x++)
*(buf + y * width + x) = color;
Hope this helps.
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? Visit http://www.yqcomputer.com/
to get the latest
critical updates and service packs available for your computer's Windows