Managed DirectX on Win 7
Hello all,
I'm trying a very simple/quick/dirty Managed DirectX 9 (ancient and obsolete, I know) WinForm program on my Win 7 64-bit box just to see if it would run. I'm just clearing the screen to DarkBlue and manually drawing a triangle in screen coordinates. By compiling to "x86" rather than "Any CPU" everything runs...I see the blue client area of the winform but I don't see the triangle. It's been years since I've done any graphics stuff so I don't know if it's my code that's wrong or whether it's some problem running a 32-bit MDX app on 64-bit Windows. Here's what I've got:
In "Program.cs":
namespace TriangleForm
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualstyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 frm = new Form1();
frm.InitializeGraphics();
Application.Run(frm);
}
}
}
in "Form1.cs ":
namespace TriangleForm
{
public partial class Form1 : Form
{
private Device device = null;
public Form1()
{
InitializeComponent();
}
public void InitializeGraphics()
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
device.Clear(ClearFlags.Target, System.Drawing.Color.DarkBlue, 1.0f, 0);
device.Present();
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
verts[0].X = 600.0f;
verts[0].Y = 50.0f;
verts[0].Color = System.Drawing.Color.Red.ToArgb();
verts[1].X = 300.0f;
verts[1].Y = 500.0f;
verts[1].Color = System.Drawing.Color.Black.ToArgb();
verts[2].X = 800.0f;
verts[2].Y = 500.0f;
verts[2].Color = System.Drawing.Color.Purple.ToArgb();
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts);
device.EndScene();
}
}
}
Anybody see why the triangle should be invisible? Thanks in advance!
-L
You need to call Present() after EndScene(), not after Clear(). You're also failing to clear the Z-Buffer.
Hello Mike,
I've moved the "device.Present()" to the end of the OnPaint handler i.e. the next line after "device.EndScene() as in
.
.
.
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts);
device.EndScene();
device.Present();
but the triangle still doesn't show up on screen. Anything else you can think of? It should at least appear once shouldn't it?
I've moved the "device.Present()" to the end of the OnPaint handler i.e. the next line after "device.EndScene() as in
.
.
.
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts);
device.EndScene();
device.Present();
but the triangle still doesn't show up on screen. Anything else you can think of? It should at least appear once shouldn't it?
But I'm using "Transformed" vertices....the Z and W components should be ignored if they are already transformed to screen coordinates, shouldn't they? If not, what are appropriate values to quickly plug-in for Z and W. Basically, I just need to see the triangle on the screen before moving any further.
z = 0.5, w = 1 should be fine. You need at least w = 1 because the pipeline divides by w to get the actual screen coords.
Okay, now I have the following:
device.Clear(ClearFlags.Target, System.Drawing.Color.DarkBlue, 1.0f, 0);
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
verts[0].X = 600.0f;
verts[0].Y = 50.0f;
verts[0].Z = 0.5f;
verts[0].Rhw = 1.0f;
verts[0].Color = System.Drawing.Color.Red.ToArgb();
verts[1].X = 300.0f;
verts[1].Y = 500.0f;
verts[1].Z = 0.5f;
verts[1].Rhw = 1.0f;
verts[1].Color = System.Drawing.Color.Black.ToArgb();
verts[2].X = 800.0f;
verts[2].Y = 500.0f;
verts[2].Z = 0.5f;
verts[2].Rhw = 1.0f;
verts[2].Color = System.Drawing.Color.Purple.ToArgb();
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts);
device.EndScene();
device.Present();
But still no triangle? Yeesh...
device.Clear(ClearFlags.Target, System.Drawing.Color.DarkBlue, 1.0f, 0);
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
verts[0].X = 600.0f;
verts[0].Y = 50.0f;
verts[0].Z = 0.5f;
verts[0].Rhw = 1.0f;
verts[0].Color = System.Drawing.Color.Red.ToArgb();
verts[1].X = 300.0f;
verts[1].Y = 500.0f;
verts[1].Z = 0.5f;
verts[1].Rhw = 1.0f;
verts[1].Color = System.Drawing.Color.Black.ToArgb();
verts[2].X = 800.0f;
verts[2].Y = 500.0f;
verts[2].Z = 0.5f;
verts[2].Rhw = 1.0f;
verts[2].Color = System.Drawing.Color.Purple.ToArgb();
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts);
device.EndScene();
device.Present();
But still no triangle? Yeesh...
Hi,
I'm using DirectX Managed + Windows 7 RC 64bit and everything is working fine for me. No problems so far...
I'm using DirectX Managed + Windows 7 RC 64bit and everything is working fine for me. No problems so far...
Use source tags when posting code:
[ source ] [ /source ]
(Without spaces of course.)
Your triangle is probably getting culled; change the renderstate CullMode to Cull.None.
[ source ] [ /source ]
(Without spaces of course.)
Your triangle is probably getting culled; change the renderstate CullMode to Cull.None.
Your winding order is backwards, so Direct3D thinks it is a backfacing triangle and culls it. Reverse the winding order.
As far as MDX goes, yes it will run on x64, since x64 contains WOW64 to run 32 bit applications. To get any of the benefits of 64 bit applications you need to use SlimDX.
As far as MDX goes, yes it will run on x64, since x64 contains WOW64 to run 32 bit applications. To get any of the benefits of 64 bit applications you need to use SlimDX.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement