Rendering to a section of a window, while still using Win32 controls (MDX)

Started by
6 comments, last by Tera_Dragon 18 years, 5 months ago
I've just started to look at using DX with C# and decided to make a simple level editor with it as a learning project. I can set up a window with DX, though what I really want is to be able to only set a section of the window for use with DX, and use the rest of the window with the Win32 controls. As some editors such as milkshape do. I've tried setting the viewport to smaller than the window, but this doesn't work as I want as the Win32 controls are not rendered. Can anyone point me in the right direction for some info or tutorials no how to do what I want?
____________________________________________________________Programmers Resource Central
Advertisement
Im no expert but maybe you could have like a popup window that displays the level and then the editor window. Basiclly render it to one window and have the other up at the same time.
Create a smaller child window. (ie: WS_CHILD and pass the main HWND as the parent window)

Give D3D this child window in the D3DPRESENT_PARAMETERS. (d3dpp.hDeviceWindow = thechildwindow), while still giving the top level window to CreateDevice.

a Fantastic yet simple way to do this is start a new project. Place a splitter control on the window and then on the one side place a panel control on the form and make it expand to the full size and on the other side you can use whatever control you wish, such as buttons etc... from the toolbox. This means you have the functionality of the Form designer and the control of DirectX on the panel.

PS: Remember to explicitly pass the Handle of the Panel to the device creation as it won't work another way.

I hope this helps.
Take care.
Thanks Armadon, that's exactly what I was looking for :D
____________________________________________________________Programmers Resource Central
I've tried rendering a colored triangle though the triangle is rendered black.
I'm not sure if this is because I am only rendering to a section of the window in a panel, so I'm putting it in this thread just in case.

Here is the code:
Device device = null;private VertexBuffer vb;protected bool InitializeGraphics(){    PresentParameters pres = new PresentParameters();    pres.Windowed = true;    pres.SwapEffect = SwapEffect.Discard;    device = new Device(0, DeviceType.Hardware, this.splitContainer1.Panel1.Handle,        CreateFlags.SoftwareVertexProcessing, pres);    CreateTriangle();    return true;}protected void Render(){    device.Clear(ClearFlags.Target, Color.Aqua, 1.0f, 0);    device.BeginScene();    // Draw the scene    device.SetStreamSource(0, vb, 0);    device.VertexFormat = CustomVertex.PositionColored.Format;    device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 1);    device.EndScene();    device.Present();}public void CreateTriangle(){    CustomVertex.PositionColored[] triangle = new CustomVertex.PositionColored[3];    triangle[0] = new CustomVertex.PositionColored(-0.3f, 0.0f, 1.0f, Color.Blue.ToArgb());    triangle[1] = new CustomVertex.PositionColored(-0.3f, 0.6f, 1.0f, Color.Red.ToArgb());    triangle[2] = new CustomVertex.PositionColored(0.3f, 0.0f, 1.0f, Color.Green.ToArgb());    vb = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, device, Usage.WriteOnly,        CustomVertex.PositionColored.Format, Pool.Managed);    GraphicsStream stm;    stm = vb.Lock(0, 0, LockFlags.None);    stm.Write(triangle);    vb.Unlock();}
____________________________________________________________Programmers Resource Central
Quote:
I've tried rendering a colored triangle though the triangle is rendered black.

Make sure that your device isn't getting lost. This might happen due to a number of reasons but I am almost sure that your device is lost as soon as your window is created. Just check to make sure that you are creating your device after the window has been created. If you want some more information on Lost Devices look here.

I Quickly hacked together a simple demo that will utilize a splitter control and then also implement a rich text box on the left hand side. You will see the triangle on the right hand side rendered to a panel. The source for the Spitter Control demo can be found here.

I hope this helps.
Take care.
I found what the error was. I was not setting Device.RenderState.Lighting, so it must have been automatically set to true. [embarrass]
____________________________________________________________Programmers Resource Central

This topic is closed to new replies.

Advertisement