Some basic DirectX questions (C#)

vakuum

Newcomer
Been playing around with some of the basic directx tutorials for a while now.
So i'm wondering on some basic DirectX guidelines..

Q. Almost all the demo's has one VertexBuffer that is in one of the VertexBuffer formats.
Could i create one VertexBuffer pr "modell" i want to draw, or could all my vertex data be in one single VertexBuffer?

I feel it's logical to make a List<VertexBuffer> for each "modell" and do a loop.
So is this the way to go, or am I WAY off when it comes to both speed and how directx api works?
 
It depends how big your models are and how many sub objcets you have.
If you can pack multiple objects into a single Draw call you should to that.
 
I haven't played around with the managed stuff very much but if I correctly understand what you're asking then yes. You can create a list of all the different models you intend on using and reuse the vertex buffers if you draw that model more than once.

Typically you'd have your list of like geometry then set a rotation matrix as a vertex shader constant. That would orient and position the model wherever you wanted it. You'd then only need a separate matrix for each model being rendered.

I'm assuming you're using shaders and not fixed function but they're fairly similar.
 
I've just been playing around with the tutorials, and i'm traying to make a more logical modell.
Only thing is that i seem to overwrite something, instead of add more draw stuff to the scene, not sure what i'm doing wrong inside the beginscene\endscene space..
 
Few things to check:
-Do you have a depth buffer set?
-Do you draw every model between your present and clear calls? Not clearing after each draw call.
-If you're using a matrix some really weird stuff can happen if that goes wrong.
 
Code:
        private void Render()
        {
            if (device == null)
                return;

            if (pause)
                return;

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue, 1.0f, 0);
            device.BeginScene();

            //Render scene...
            SetupLights();
            SetupMatrices();

            device.SetStreamSource(0, vertexBuffer[0], 0);
            device.VertexFormat = CustomVertex.PositionNormal.Format;
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 98);

            device.SetStreamSource(0, vertexBuffer[1], 0);
            device.VertexFormat = CustomVertex.PositionNormal.Format;
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 98);

            device.EndScene();
            device.Present();
        }

Why is this only displaying the last vertexBuffer[1] vertex array?
Sorry for bad code, i'm just trying to understand how the api works, but i can't figure out how to send more than one vertexbuffer to the device for drawing, and therefor also only send one type of vertexbufer.format :\
 
Hmm it looks like it should work. Just to make sure, the vertex buffers are different or at least located at different positions? Or the matrices at least put the geometry at different locations?
 
Hmm, I used a random to generate 2 different meshes, but somehow the looked like one every time..
This time I finally noticed that both get draw'n! :p
*Happy* :)
 
And now I just got very :oops:
I used:
Code:
Random ran = new Random();
int random = ran.Next(50);
inside the vertexbuffer builder.
But since the loop is so quick, and I did't use the same Random..
Therefor I got the same random in both loops (or atleast almost), except the times where i marked of in vs to check if the random's where the same..
 
Back
Top