J
Jon Rea
I have an MDI application that has multiple different "modular documents".
Each document can own multiple MDI windows that are managaed by a manager
class that uses the singleton pattern and holds a link to the MDI container.
Currently some of these MDI windows implement a simple 3D view using the
CSGL openGL graphics wrapper.
I want to have a play with direct3D. I have downloaded the SDK and all the
samples and these are working, however all the tutorials use the following.
All source code is taken unmodified from the Direct3D SDK Tutorial 1 ... I
just would like help applying this to my prog ....
Main()
{
using (CreateDevice frm = new CreateDevice())
{
if (!frm.InitializeGraphics()) // Initialize Direct3D
{
MessageBox.Show("Could not initialize Direct3D. This
tutorial will exit.");
return;
}
frm.Show();
// While the form is still valid, render and process
messages
while(frm.Created)
{
frm.Render();
Application.DoEvents();
}
}
}
}
The render function performs the maths for changing the scene per frame ...
public CreateDevice()
{
// Set the initial size of our form
this.ClientSize = new System.Drawing.Size(400,300);
// And it's caption
this.Text = "D3D Tutorial 01: CreateDevice";
// Load our icon from the resources of the .exe
this.Icon = new Icon(this.GetType(), "directx.ico");
}
public bool InitializeGraphics()
{
try
{
// Now let's setup our D3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
private void Render()
{
if (device == null)
return;
//Clear the backbuffer to a blue color
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
//Begin the scene
device.BeginScene();
// Rendering of scene objects can happen here
//End the scene
device.EndScene();
device.Present();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.Render(); // Render on painting
}
Now for my question .....
As my MDI prog can have multiple 3D view windows, what is the best way to
implement each form rendering itself (ive tried having a thread running
render with a wait statement, but i dont like this solution), i.e.
triggering a paint event when there is free CPU time. I dont want to have to
implement a messy loop from the main document manager class (remembering
that each "Document" can own multiple MDI windows) to trawl through each of
the child documents and call render if the child is a 3D window.
Many thanks for any help
Jon Rea
Each document can own multiple MDI windows that are managaed by a manager
class that uses the singleton pattern and holds a link to the MDI container.
Currently some of these MDI windows implement a simple 3D view using the
CSGL openGL graphics wrapper.
I want to have a play with direct3D. I have downloaded the SDK and all the
samples and these are working, however all the tutorials use the following.
All source code is taken unmodified from the Direct3D SDK Tutorial 1 ... I
just would like help applying this to my prog ....
Main()
{
using (CreateDevice frm = new CreateDevice())
{
if (!frm.InitializeGraphics()) // Initialize Direct3D
{
MessageBox.Show("Could not initialize Direct3D. This
tutorial will exit.");
return;
}
frm.Show();
// While the form is still valid, render and process
messages
while(frm.Created)
{
frm.Render();
Application.DoEvents();
}
}
}
}
The render function performs the maths for changing the scene per frame ...
public CreateDevice()
{
// Set the initial size of our form
this.ClientSize = new System.Drawing.Size(400,300);
// And it's caption
this.Text = "D3D Tutorial 01: CreateDevice";
// Load our icon from the resources of the .exe
this.Icon = new Icon(this.GetType(), "directx.ico");
}
public bool InitializeGraphics()
{
try
{
// Now let's setup our D3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
private void Render()
{
if (device == null)
return;
//Clear the backbuffer to a blue color
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
//Begin the scene
device.BeginScene();
// Rendering of scene objects can happen here
//End the scene
device.EndScene();
device.Present();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.Render(); // Render on painting
}
Now for my question .....
As my MDI prog can have multiple 3D view windows, what is the best way to
implement each form rendering itself (ive tried having a thread running
render with a wait statement, but i dont like this solution), i.e.
triggering a paint event when there is free CPU time. I dont want to have to
implement a messy loop from the main document manager class (remembering
that each "Document" can own multiple MDI windows) to trawl through each of
the child documents and call render if the child is a 3D window.
Many thanks for any help
Jon Rea