\r\n\r\n
DirectX Topics include: Managed DirectX (DX9)

Go Back  Xtreme .NET Talk > .NET > Graphics and Multimedia > DirectX > need help with StretchRectangle and Surfaces


\r\n \r\n \r\n \r\n
 
 
Thread Tools Display Modes
\r\n \r\n
\r\n
\r\n \r\n I am on a mission to produce a user control that is a scrollable zoomable window containing a loaded image using Direct3D.
\r\n
\r\nI have exhausted all avenues I know of for getting Device.StretchRectangle to work. I am trying to keep it as simple as possible and basically my approach has been to utilize two surfaces. One is large and contains the entire image and I create it (tried many surface creation choices); the other is the back buffer taken from the device which is a smaller area on a form. A rectangle "floats" around the larger image surface and tries to write the inner contents to the back buffer. A few days ago I was able to accomplish the scrolling part by using Device.UpdateSurface and it worked fabulous but it cannot help me with the zooming so I switched back to using Device.StretchRectangle and cannot get it to work as needed.
\r\n
\r\nThe symtoms I am getting with Device.StretchRectangle is that when the source and destination rectangles are of equal size and positon the expected top-left portion of the image appears fine; as soon as the source rectangle begins to change position (scroll) the \'same\' image portion displays expanded. Scroll over enough and it crashes with dbmon.exe saying source rectangle has no area. Even though I can confirm my image surface size is correct and larger than the back buffer area the behavior is as though my source rectangle is not allowed to float over that source surface but rather is confined to the back buffer area and as I alter the source rectangle x,y it just results in a smaller rectangle and not as I expect which is a relocated rectangle of equal size (for scrolling). I hope that made sense.
\r\n
\r\nHere is the code I currently have in use:
\r\n...
\r\nprivate Image imageValue = null;
\r\nprivate String imageFile = null;
\r\nprivate Device device = null;
\r\nprivate PresentParameters presentParams = null;
\r\nprivate Surface backBuf = null;
\r\nprivate Surface imgSurf = null;
\r\nprivate Rectangle backRect;
\r\nprivate Point viewLoc;
\r\nprivate Size viewSize;
\r\n
\r\n...
\r\n
\r\n// create the device
\r\npresentParams = new PresentParameters();
\r\npresentParams.Windowed = true;
\r\npresentParams.SwapEffect = SwapEffect.Discard;
\r\npresentParams.BackBufferCount = 1;
\r\npresentParams.BackBufferWidth = IVPictureBox.Width;
\r\npresentParams.BackBufferHeight = IVPictureBox.Height;
\r\npresentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format;
\r\npresentParams.MultiSample = MultiSampleType.None;
\r\npresentParams.MultiSampleQuality = 0;
\r\npresentParams.EnableAutoDepthStencil = false;
\r\npresentParams.AutoDepthStencilFormat = 0;
\r\npresentParams.PresentFlag = PresentFlag.None;
\r\npresentParams.FullScreenRefreshRateInHz = 0;
\r\npresentParams.PresentationInterval = PresentInterval.Immediate;
\r\npresentParams.DeviceWindow = IVPictureBox;
\r\npresentParams.DeviceWindowHandle = IVPictureBox.Handle;
\r\n
\r\ndevice = new Device(0, DeviceType.Hardware, IVPictureBox, CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded, presentParams);
\r\n
\r\n// store the back buffer information
\r\nbackBuf = device.GetBackBuffer(0, 0, BackBufferType.Mono);
\r\nbackRect = new Rectangle(0, 0, IVPictureBox.Width, IVPictureBox.Height);
\r\n
\r\n...
\r\n
\r\n// create the source surface with the image
\r\n// NOTE: commented lines were part of other surface attempts
\r\nimgSurf = device.CreateRenderTarget(imageValue.Width, imageValue.Height, backBuf.Description.Format, MultiSampleType.None, 0, false);
\r\n// imgSurf = device.CreateOffscreenPlainSurface(imageValue.Width, imageValue.Height, backBuf.Description.Format, Pool.Default);
\r\n// imgSurf = Surface.FromBitmap(device, (Bitmap)imageValue, Pool.Default);
\r\nSurfaceLoader.FromFile(imgSurf, imageFile, Filter.None, 0);
\r\n
\r\nviewSize.Width = IVPictureBox.Width;
\r\nviewSize.Height = IVPictureBox.Height;
\r\n
\r\n...
\r\n
\r\n// render scene
\r\ndevice.Clear(ClearFlags.Target, Color.Black, 1.0F, 0);
\r\ndevice.BeginScene();
\r\n
\r\ndevice.StretchRectangle(imgSurf, new Rectangle(viewLoc, viewSize), backBuf, backRect, TextureFilter.None);
\r\n
\r\ndevice.EndScene();
\r\ndevice.Present();
\r\n
\r\n
\r\nThank you in advance for any assistence, I have been trying to get these few lines of code to work now for two weeks (I have read and tried all I could find on the web, in the help, and books).\r\n
\r\n
\r\n \r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; // next/previous post info pn[388153] = "388153,388153"; pn[0] = ",388153"; // cached usernames pu[0] = guestphrase; pu[29044] = "TripleT"; // -->
Prev Previous Post   Next Post Next
  #1  
Old 10-20-2003, 11:54 AM
TripleT TripleT is offline
Newcomer

Preferred language:
C#
 
Join Date: Oct 2003
Posts: 1
TripleT is on a distinguished road
Unhappy need help with StretchRectangle and Surfaces

I am on a mission to produce a user control that is a scrollable zoomable window containing a loaded image using Direct3D.

I have exhausted all avenues I know of for getting Device.StretchRectangle to work. I am trying to keep it as simple as possible and basically my approach has been to utilize two surfaces. One is large and contains the entire image and I create it (tried many surface creation choices); the other is the back buffer taken from the device which is a smaller area on a form. A rectangle "floats" around the larger image surface and tries to write the inner contents to the back buffer. A few days ago I was able to accomplish the scrolling part by using Device.UpdateSurface and it worked fabulous but it cannot help me with the zooming so I switched back to using Device.StretchRectangle and cannot get it to work as needed.

The symtoms I am getting with Device.StretchRectangle is that when the source and destination rectangles are of equal size and positon the expected top-left portion of the image appears fine; as soon as the source rectangle begins to change position (scroll) the 'same' image portion displays expanded. Scroll over enough and it crashes with dbmon.exe saying source rectangle has no area. Even though I can confirm my image surface size is correct and larger than the back buffer area the behavior is as though my source rectangle is not allowed to float over that source surface but rather is confined to the back buffer area and as I alter the source rectangle x,y it just results in a smaller rectangle and not as I expect which is a relocated rectangle of equal size (for scrolling). I hope that made sense.

Here is the code I currently have in use:
...
private Image imageValue = null;
private String imageFile = null;
private Device device = null;
private PresentParameters presentParams = null;
private Surface backBuf = null;
private Surface imgSurf = null;
private Rectangle backRect;
private Point viewLoc;
private Size viewSize;

...

// create the device
presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.BackBufferCount = 1;
presentParams.BackBufferWidth = IVPictureBox.Width;
presentParams.BackBufferHeight = IVPictureBox.Height;
presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format;
presentParams.MultiSample = MultiSampleType.None;
presentParams.MultiSampleQuality = 0;
presentParams.EnableAutoDepthStencil = false;
presentParams.AutoDepthStencilFormat = 0;
presentParams.PresentFlag = PresentFlag.None;
presentParams.FullScreenRefreshRateInHz = 0;
presentParams.PresentationInterval = PresentInterval.Immediate;
presentParams.DeviceWindow = IVPictureBox;
presentParams.DeviceWindowHandle = IVPictureBox.Handle;

device = new Device(0, DeviceType.Hardware, IVPictureBox, CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded, presentParams);

// store the back buffer information
backBuf = device.GetBackBuffer(0, 0, BackBufferType.Mono);
backRect = new Rectangle(0, 0, IVPictureBox.Width, IVPictureBox.Height);

...

// create the source surface with the image
// NOTE: commented lines were part of other surface attempts
imgSurf = device.CreateRenderTarget(imageValue.Width, imageValue.Height, backBuf.Description.Format, MultiSampleType.None, 0, false);
// imgSurf = device.CreateOffscreenPlainSurface(imageValue.Width, imageValue.Height, backBuf.Description.Format, Pool.Default);
// imgSurf = Surface.FromBitmap(device, (Bitmap)imageValue, Pool.Default);
SurfaceLoader.FromFile(imgSurf, imageFile, Filter.None, 0);

viewSize.Width = IVPictureBox.Width;
viewSize.Height = IVPictureBox.Height;

...

// render scene
device.Clear(ClearFlags.Target, Color.Black, 1.0F, 0);
device.BeginScene();

device.StretchRectangle(imgSurf, new Rectangle(viewLoc, viewSize), backBuf, backRect, TextureFilter.None);

device.EndScene();
device.Present();


Thank you in advance for any assistence, I have been trying to get these few lines of code to work now for two weeks (I have read and tried all I could find on the web, in the help, and books).
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
StretchRectangle example wima DirectX 0 09-21-2005 10:01 AM
Surfaces Vs. Textures please help LDV DirectX 2 04-12-2004 07:52 PM
How to create big surfaces? Liu Junfeng DirectX 11 09-28-2003 07:53 AM
Surfaces? mutant Graphics and Multimedia 6 05-12-2003 01:24 PM
Controls and GDI+ surfaces eisman Graphics and Multimedia 0 02-27-2003 10:59 AM

Advertisement:

Powered by liquidweb