Untitled

Started by
11 comments, last by Programmer16 13 years, 6 months ago
Quote:Original post by Programmer16

Also, for future reference, when posting source code please use the source tags [ source ] and [ /source ] (without spaces of course.)

---------------------------
Where will I write
 and 
?

Advertisement
Ok, I still have some questions:

- Have you localized some errors by stepping through with the debugger (i.e. crashes) ?
- Have you setup the DirectX debug runtimes. This will give you more detailed error messages. In C# you will probably need to use DebugView to grab the messages.

First I'd take a look at your device setup. I doubt it works, or at least I doubt the device is created the way you want. Take a look at the presentation parameters, you only set the backbuffer size.
private void Form1_Paint(object sender, PaintEventArgs e){/* 1*/    Direct3D objDirect3D = new Direct3D ();/* 2*/    PresentParameters pp = new PresentParameters ();/* 3*/    pp.BackBufferHeight = 1080;/* 4*/    pp.BackBufferWidth = 1920;/* 5*/    Device dvc = new Device (objDirect3D, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, pp);/* 6*/    VertexBuffer VrtxBuf = new VertexBuffer (dvc, 3 * 3 * 4, Usage.WriteOnly, VertexFormat.None, Pool.Managed);/* 7*/    DataStream VrtxStrm = VrtxBuf.Lock (0, 0, LockFlags.None);/* 8*/    float [] VrtxData = { 50f, 0f, 0f, 0f, 50f, 0f, 0f, 25f, 0f };/* 9*/    VrtxStrm.WriteRange (VrtxData);/*10*/    VrtxBuf.Unlock ();/*11*/    dvc.Clear (ClearFlags.All, Color.Black, 1f, 0);/*12*/    dvc.BeginScene ();/*13*/    dvc.SetStreamSource (0, VrtxBuf, 0, 12);/*14*/    dvc.DrawPrimitives (PrimitiveType.TriangleList, 0, 1);/*15*/    dvc.EndScene ();/*16*/    dvc.Present ();/*17*/    VrtxStrm.Dispose ();/*18*/    VrtxBuf.Dispose ();/*19*/    dvc.Dispose ();/*20*/    objDirect3D.Dispose ();}

I've added numbers to the above to make it easier to reference.

1) Try to use more descriptive names; pp and dvc really don't cut it. It may not seem apparent now, but once you get into a project and have to skim through a 500 line method to find out what pp is, you'll be sorry. More importantly, it makes it easier on those that have to read your code (like us), so we don't have to try to figure what is what. This is just my opinion though and can be ignored.

2) On line 6, VertexFormat.None tells the device that you're not supplying any data to it (what you're looking for is VertexFormat.Position.)

3) On line 8, you're supplying your vertices' positions in counter-clockwise, which is Direct3D's default culling mode (meaning they won't get rendered.)

4) On line 11, you tell the device to clear everything (via ClearFlags.All) when you've only supplied a target (you didn't setup a stencil or a z-buffer when you created the device.)

5) On line 17, you dispose your vertex stream, which is handled automatically (I don't believe this is a problem though.)

6) You don't set any render-states. You need to at least set RenderStates.Lighting to false so that you can see something (with lighting enabled, everything rendered will be black and you have a black background.)

7) As mentioned, you don't set a projection matrix, so your vertices aren't going to get transformed correctly (and thus, more than likely, won't show up on screen.)

What you need to do is read up on Direct3D's fixed-function rendering pipeline (which will help with points 2, 3, 4, and 6), the transformation pipeline (which will help with point 8), and the documents for whichever SDK you're using. Alternatively, since it seems you're using SlimDX, you could look through the samples supplied with the SDK.

As unbird stated, the only way to really figure out what is going wrong (after you've fixed the problems that were already mentioned) is to step through the program and read the debug output.

HTH!

Quote:Original post by unbird
... Take a look at the presentation parameters, you only set the backbuffer size.
I thought the same thing, but SlimDX sets default values for everything.

This topic is closed to new replies.

Advertisement