need help with StretchRectangle and Surfaces

TripleT

Newcomer
Joined
Oct 20, 2003
Messages
1
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).
 
Back
Top