StrechRectangle DirecX3D in Windowed mode

LDV

Freshman
Joined
Dec 29, 2003
Messages
31
Hi Guys,

I'm trying to use the StretchRectangle of DirectX3D in window mode, and it throws and exception.

Any ideas?

Here is the relevant code parts:

d3dpp.Windowed = true;
m_localDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, m_owner, CreateFlags.SoftwareVertexProcessing, d3dpp);

---------------------------
m_deviceSurface = m_localDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
Bitmap bmpLayout = new Bitmap("layout.png");

// make sure we have the background viewed
m_srfcLayout = new Surface(m_localDevice, bmpLayout, Pool.Default);

----------------------------------------------------

m_localDevice.BeginScene();

//viewBmp(ref m_srfcLayout, 0, 0);
m_localDevice.Clear(ClearFlags.Target, Color.Blue, 0, 0);
//m_localDevice.StretchRectangle(m_srfcLayout, new Rectangle(1, 1, 100, 100), m_deviceSurface, new Rectangle(m_owner.Left + 100, m_owner.Top + 20, 100, 100), TextureFilter.None);
m_localDevice.StretchRectangle(m_srfcLayout, new Rectangle(1, 1, 100, 100), m_deviceSurface, new Rectangle(100, 20, 100, 100), TextureFilter.None);

m_localDevice.EndScene();
m_localDevice.Present();
 
What part throws an exception? And I recommend using a Texture and the Sprite class, rather than surfaces, for one thing it's easier to use the textures over surfaces and textures can be alphablended.
 
Hi,

First - thanks for your answer.

The exception thrown is general: "Error in the application".
It is thrown in the .StretchRectangle line.

But i found the error, i tried blitting from diffrent PixelFormat surfaces.
The best thing is to use .CreateOffPlainSurface method and use the same PixelFormat.

A few more questions:
1. How do i convert the Images i use from diffrent pixel-formats?
2. You suggested using Sprite class - which is better than surfaces, i agree. The problem is that i need to create a picture off screen and then show the full thing on screen, Sprite class draws directly on the device. Is there another way i can use it?

Thanks - LDV
 
The SurfaceLoader class may be able to convert image's pixelformats, the TextureLoader does anyway.

The Sprite class draws to the device using screen coordinates which saves the trouble in trying to calculate billboards(The sprite class can render billboards too). If you're combining different pictures, can't you do that on the BackBuffer instead of an offscreen surface? The Texture class also has a function(GetSurfaceLevel) which allows you to edit the underlying surface directly if you want to, I've never needed to use it so I don't know how it works though.
 
Back
Top