Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# plotting pixels on a backbuffer surface.

Started by Ghhetto Mar 8, 2003 at 8:37 PM 5 replies 4.5k views
Original Post
Ghhetto
Ghhetto
Hello, I am in need of some newbie help. I simply want to plot some pixels to a surface but, C# directx documentation has me confused. I am attempting to convert the Zen of Direct3d to C#, so the RenderPoints code I show below has some of that code commented out. In my code, I think I need to: 1. Clear back buffer 2. Lock the back buffer 3. Plot the pixels onto the back buffer 4. Unlock back buffer 5. Present back buffer My surface is 800 X 600. I am confused on how to call the BackSurf.LockedRectangle method and then plot the pixels. Could anyone provide some sample code of locking the backbuffer and plotting a couple of pixels that I could digest and learn from? Here is my current code: private void RenderPoints() { if (device == null) return; if (pause) return; //Clear the backbuffer to a blue color device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Blue, 1.0f, 0); device.BeginScene(); // Get back buffer Surface BackSurf; BackSurf = device.GetBackBuffer(0,0, Microsoft.DirectX.Direct3D.BackBufferType.Mono); /* Lock the back buffer No idea what to do here. Dont understand the ranks, typelock and and what LockRectangle array is returning. */ //byte[] data = BackSurf.LockRectangle(?????); /* Set 10,000 pixels at random locations to a shade of red Not sure yet what to do, but when i figure out lockedrectangle, will turn my attention to this. */ // Unlock the back buffer BackSurf.UnlockRectangle(0); // Release the back buffer BackSurf.ReleaseGraphics(); // Present the back buffer to the primary surface //End the scene device.EndScene(); device.Present(); }
aftermath
aftermath
not everyone knows C#
Rate me up.
Nypyren
Nypyren
Documentation: "Surface.LockRectangle: Locks the surface."

You: "THANKS, ***!"


I''m rabidly experimenting with the LockRectangle function... so far all I get are exceptions.

BTW -- there are NO results on Google for this other than the shitty MSDN.

So far, I can tell you what "rank" is. In relation to an array, "rank" is the number of dimensions. Maybe the function is asking whether we want a 1d or 2d array.

But that doesn''t make any sense... the "ranks" parameter is an int[]... maybe it really means dimensions. I gave it:

typeof(byte), LockFlags.None, new int[]{10,10}

and it threw an exception.

I''ll tell you when I get it working.
Nypyren
Nypyren
Every call to LockRectangle exceptions for me. Maybe backbuffers can't be locked in C#?

BTW -- "ReleaseGraphics" is if you used "GetGraphics".

Unfortunately, GetGraphics ALSO exceptions for me.

The exception I get is:


Microsoft.DirectX.Direct3D.InvalidCallException
Error in the application.
-2146232832 (Unknown)
at Microsoft.DirectX.Direct3D.Surface.LockRectangleInternal(tagRECT* rect, LockFlags flags)
at Microsoft.DirectX.Direct3D.Surface.LockRectangleInternal(tagRECT* rect, LockFlags flags, Int32& pitch)
at Microsoft.DirectX.Direct3D.Surface.LockRectangle(LockFlags flags, Int32& pitch)
at Tester.MainForm.Render() in d:\coding\worldgen\3d.cs:line 196


VERY HELPFUL! (Fires a few rounds off in the general direction of the DirectX documentation-writers)

500*1


[edit] -- OK, I'm a freaking numbnuts... All I needed to do was "presentparams.PresentFlag |= PresentFlag.LockableBackBuffer;".

[edited by - Nypyren on March 10, 2003 1:47:07 AM]
Nypyren
Nypyren
Allright! I got it working. Here's the syntax I used:


Surface s=null;
try
{
s = device.GetBackBuffer(0, 0, BackBufferType.Mono);
uint[,] a = (uint[,])s.LockRectangle(typeof(uint), new Rectangle(0,0,10,1), LockFlags.None, new int[]{10, 1});
a[0,0] = 0xFFFFFFFF;
}
catch (Exception e) {Debug.Print("" + e.GetType() + "\r\n" + e.ToString());}

try
{
s.UnlockRectangle();
}
catch {Debug.Print("Blarg");}


make SURE that your PresentParameters structure has PresentFlag.LockableBackBuffer set!

[edited by - Nypyren on March 10, 2003 1:51:22 AM]
Nypyren
Nypyren
So far, it looks like the "new Rectangle" bit doesn't do anything with a backbuffer... so far it seems like the entire screen is locked no matter what, and all you get to decide is how you want the area divided up.

I'm using


uint[,] a = (uint[,])s.LockRectangle(typeof(uint), LockFlags.None, new int[]{768,1024});

a[y,x] = color;


which seems to be how it works.

and locking that big of an area on my box is really slow.

[edited by - Nypyren on March 10, 2003 2:05:00 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.