Jump to content
  • Advertisement
Sign in to follow this  
LTKeene

Managed DirectX on Win 7

This topic is 3254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!