Tech Off Thread

119 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Discuss the Beginning Game Development series on Coding 4 Fun

Back to Forum: Tech Off
  • User profile image

    The Coding4Fun Dev Center is all about writing code for the sheer joy of it. The 'Beginning Game Development' series by Derek Pierson is all about helping you learn the ins and outs of creating a game using .NET Framework 2.0. Here's the place to discuss those articles, and to suggest new topics.

    Current articles in the series:
      Beginning Game Development
      Introduction to DirectX

  • User profile image

    I just read the third part of this series and checked out the code for the article and it seems to be running awfully slow. The frame rate hangs around 5. This seems pretty odd since the CreateFlags for the device do specify HardwareVertexProcessing and PureDevice. I don't see how displaying a single rotating cube can be this slow.

    Any ideas how to get this to run faster?


  • User profile image

    If you're running it within Visual Studio & the Debug DX runtime, then watch the debug window. If you see lots of debug statements, then that could cause it to slow down.

    Try running it from outside of VS.

  • User profile image

    Well, I gotta admit it was a good bet on your part, but unfortunately, I get the exact same performance when running the actual application outside of the VS.NET debug environment.

    Also, while running it in the debug environment, I didn't see any particular output in the debug window. I noticed there is a "Start with D3D debug support" option in the menu (or something similar). However, I've never used that option.

    Any other advice?

  • User profile image

    Just so I can try it out too, which code are you running?

  • User profile image

    Well wouldn't know it! I was trying to determine the exact lines of code I had uncommented, and upon running the code this morning, I get around 35 fps instead of 5!

    I don't know what happened, because I did try it yesterday (following your post), and it was still running awfully slow.

    So how good is 35fps? It doesn't seem very high to me for a simple spinning cube, so maybe you could try it out.

    Get the C# code from Part III, comment lines 122, 123 and 95, and uncomment lines 98, 101 and 120. You should get a spinning cube.

  • User profile image

    I get about 45 fps, but not all the sides of the cube display. Some sides disapear so you can see the inside of the cube. Is this normal?

  • User profile image

    I get the same frame rate for some of the samples, too. Both in the C# AND the C++ version. My theory is that one of the UI classes is extremely expensive here -- because, using the included mesh viewer, I can view Tiger.x at 800 fps, so surely, a cube should be able to do the same. We'll just have to isolate that control & watch the framerate go up.

  • User profile image

    brussell wrote:
    I get about 45 fps, but not all the sides of the cube display. Some sides disapear so you can see the inside of the cube. Is this normal?
    Not sure... are you zooming in very close?

  • User profile image

    I'm seeing the same thing - as the cube spins different faces are getting rendered in the fore-ground which should be in the background etc. I remember reading up about 3d progamming in the olden days ('95) and they always were talking about depth sorting, and z-buffers, and bsp something-somethings that were used to determine which vertices should be rendered in which order.

    I reckon this is what will be covered in the next tutorial (I hope so anyway Smiley

  • User profile image

    Well in the last article, he mentioned that DirectX will not draw the side facing the camera so to make sure you use the correct culling. I figured he would have done it correctly in the example, but maybe I'm wrong.

    I'm not zoomed in anymore than the example starts out as.

    This is from the last article: "When drawing a three-dimensional object, DirectX does not render the primitives (triangles) that comprise the faces of those objects that do not face the camera. This is called back face culling.

    DirectX determines which side of an object is facing the camera by using the order (winding) of the vertices. If you choose either clockwise or counterclockwise, then the vertices that are wound the opposite are on the back of the object and are culled. The default mode is counterclockwise culling, so you need to make sure to define your vertices in a clockwise order."

  • User profile image

    I get the same problem with the cube, some faces do seem to disappear while it is spinning. I didn't think much of it, since it was put there simply to "experiment" anyway.

    So how do we go about finding which control or what exactly is slowing us down?

  • User profile image

    Does anyone know when the next lesson will be out, or how often they are released? The anticipation is killing me, and now that I know how to spin triangles,  I reaaaally want to know how to spin my objects independently of each other Smiley

  • User profile image

    I think the problem isn't that sides are missing or disapearing. It looks like the problem is that you can see through the top color to the color behind it. This is making it appear as though sides are missing. Any ideas on how to make it not do this? I was experimenting with drawing triangles and the bottom one would sometimes draw on top of the top one. I went back to the cube and only displayed a couple sides and could see that is what is happening there too.

  • User profile image

    With regard to the different faces of the cube getting rendered problem, I've found that that some of the faces in the CreateTestCube() method do not obey the clockwise winding rule that was briefly talked about in the article. If you want to see these faces correctly you have to do a couple of things...

    First you have to fix up the offending faces so that when the camera is looking at each face from outside the cube, the vertices that form each individual triangle trace out a clockwise path.

    Second, since back-face culling is currently turned off you have to turn it on and set it to cull faces that have counter-clockwise orientation (imagine being inside the cube and trying to look out...all of the faces will be oriented the wrong way so wont be drawn etc). To do this, replace line 108 with

    device.RenderState.CullMode = Cull.CounterClockwise;

    If you do these two step you should get a normal-looking spinning cube that only shows the faces that are visible to the camera and not obstructed by the rest of the cube.

    Without making these changes what you get is an attempt to draw the cube without any knowlege of what faces/colours should be on top of each other. If you run it again without culling turned on you'll notice that the last colours defined in the function that generates the cube are the colours that are on top and hence drawn most often, and the first colours are generally obscured (that is, you get more purple and red than aqua and yellow).

    In case anybody is interested, here is my modified code for constructing the triangles so that they obey the clockwise winding rule.

    // face 1
    verts[0].Position = new Vector3 ( 0.0f, 0.0f, 0.0f );
    verts[1].Position = new Vector3 ( 0.0f, 10.0f, 0.0f );
    verts[2].Position = new Vector3 ( 10.0f, 0.0f, 0.0f );
    verts[3].Position = new Vector3 ( 10.0f, 0.0f, 0.0f );
    verts[4].Position = new Vector3 ( 0.0f, 10.0f, 0.0f );
    verts[5].Position = new Vector3 ( 10.0f, 10.0f, 0.0f );
    // face 2
    verts[6].Position = new Vector3 ( 10.0f, 0.0f, 0.0f );
    verts[7].Position = new Vector3 ( 10.0f, 10.0f, 0.0f );
    verts[8].Position = new Vector3 ( 10.0f, 0.0f, 10.0f );
    verts[9].Position = new Vector3 ( 10.0f, 0.0f, 10.0f );
    verts[10].Position = new Vector3 ( 10.0f, 10.0f, 0.0f );
    verts[11].Position = new Vector3 ( 10.0f, 10.0f, 10.0f );
    // face 3
    verts[12].Position = new Vector3 ( 0.0f, 0.0f, 0.0f );
    verts[13].Position = new Vector3 ( 10.0f, 0.0f, 0.0f );
    verts[14].Position = new Vector3 ( 0.0f, 0.0f, 10.0f );
    verts[15].Position = new Vector3 ( 0.0f, 0.0f, 10.0f );
    verts[16].Position = new Vector3 ( 10.0f, 0.0f, 0.0f );
    verts[17].Position = new Vector3 ( 10.0f, 0.0f, 10.0f );
    // face 4
    verts[18].Position = new Vector3 ( 0.0f, 0.0f, 0.0f );
    verts[19].Position = new Vector3 ( 0.0f, 0.0f, 10.0f );
    verts[20].Position = new Vector3 ( 0.0f, 10.0f, 0.0f );
    verts[21].Position = new Vector3 ( 0.0f, 10.0f, 0.0f );
    verts[22].Position = new Vector3 ( 0.0f, 0.0f, 10.0f );
    verts[23].Position = new Vector3 ( 0.0f, 10.0f, 10.0f );
    // face 5
    verts[24].Position = new Vector3 ( 0.0f, 0.0f, 10.0f );
    verts[25].Position = new Vector3 ( 10.0f, 0.0f, 10.0f );
    verts[26].Position = new Vector3 ( 0.0f, 10.0f, 10.0f );
    verts[27].Position = new Vector3 ( 0.0f, 10.0f, 10.0f );
    verts[28].Position = new Vector3 ( 10.0f, 0.0f, 10.0f );
    verts[29].Position = new Vector3 ( 10.0f, 10.0f, 10.0f );
    // face 6
    verts[30].Position = new Vector3 ( 0.0f, 10.0f, 0.0f );
    verts[31].Position = new Vector3 ( 0.0f, 10.0f, 10.0f );
    verts[32].Position = new Vector3 ( 10.0f, 10.0f, 0.0f );
    verts[33].Position = new Vector3 ( 10.0f, 10.0f, 0.0f );
    verts[34].Position = new Vector3 ( 0.0f, 10.0f, 10.0f );
    verts[35].Position = new Vector3 ( 10.0f, 10.0f, 10.0f );

  • User profile image

    i like opengl

  • User profile image

    im getting some error while comiling the code in Article III (DirectX II):
    Im using VS.NEt 2004 and i have .NET Framework 1.1 redistrutable installed.
    The eroor i get is this...
    An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in

  • User profile image

    This is a great tutorial. I just got visual C# express. Was using VC++ 6 before this. Wow, i was so behind the times. Finally i think i'll be able to learn directX. So anyways, ive been playing with the tutorial code and thought i'd share my findings (as i understand them so far).
            The tutorial uses PositionColored vectors which specify a location in World Space. And it's rendering them using the gfxdevice.DrawUserPrimitives method which doesn't use the vectorBuffer. The alternative method is to use gfxdevice.DrawPrimitives, which assumes you ARE using the vectorBuffer and you've already loaded the primitive into the buffer. I'm guessing there are situations where it's difficult to use the buffering method and rendering your primitives straight from system memory is more flexible.
           A TransformedColored vector specifies a location in Screen Space. And when such a primitive is rendered, viola, it's flat on the screen. So there's the first step to a 2D vector application. I've presented the code below to initialize the vertexBuffer with a TransformedColored primitive and render it to the screen. You'll notice that im using an alternate method of creating vertices, instead of creating the Position and Color separately, they can be created together. I dont know why a Vector4 is required (and its z, w values).
           I hope this code works for you, i'm just learning, so i may have left something out. Let me know how it goes.


    VertexBuffer vertexBuffer;

                this.InitializeVertexBuffer();     // initialize 2d primitive

     protected void Draw2dScene()
                gfxdevice.SetStreamSource(0, vertexBuffer, 0);
                gfxdevice.VertexFormat = CustomVertex.TransformedColored.Format;
                gfxdevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

    public void InitializeVertexBuffer()
                CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
                verts[0] = new CustomVertex.TransformedColored(new Vector4(150, 50, 1, 1), Color.Red.ToArgb());
                verts[1] = new CustomVertex.TransformedColored(new Vector4(250, 250, 1, 1), Color.Blue.ToArgb());
                verts[2] = new CustomVertex.TransformedColored(new Vector4(50, 250, 1, 1), Color.Green.ToArgb());

                vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), verts.Length,
                    gfxdevice, 0, CustomVertex.TransformedColored.Format, Pool.Default);
                GraphicsStream graphicsStream = vertexBuffer.Lock(0, 0, LockFlags.None);

    // END CODE

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.