• Advertisement
Sign in to follow this  

Problem using a non-FVF vertexbuffer

This topic is 4614 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

Hi, I want to use a non-FVF (FVF=0) vertexbuffer. I tried this code, modified from a book example and it works just fine when creating an FVF buffer (the commented VB creation). But as soon as I try to change it to a non-FVF buffer it just renders "nothing without errors". In the beginning I was using a shader effect but I simplified the code to use fixed function and it still doesn't work. I know it should work in principle because I know that others have used non-FVF buffers both with the fixed function and the programmable pipeline. The problem is just that I can't get it to work. Am I missing something trivial? As I understand the vertexdeclaration substitutes the setvertexformat (SetFVF in c++) call. Here's the code. It's in C# and uses DX9.
private VertexBuffer vb = null;
private VertexDeclaration decl = null;
private Device device = null;

// Our matrices
private Matrix worldMatrix;
private Matrix viewMatrix;
private Matrix projMatrix;
private float angle = 0.0f;

public void InitializeGraphics()
	PresentParameters presentParams = new PresentParameters();

	presentParams.Windowed = true;
	presentParams.SwapEffect = SwapEffect.Discard;
	presentParams.AutoDepthStencilFormat = DepthFormat.D16;
	presentParams.EnableAutoDepthStencil = true;

	device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);

	// Create our vertex data
	/*vb = new VertexBuffer(typeof(CustomVertex.PositionOnly), 3, device,
		Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionOnly.Format,
	vb = new VertexBuffer(device, 3*12, Usage.Dynamic | Usage.WriteOnly, 0, Pool.Default);

	vb.Created += new EventHandler(this.OnVertexBufferCreate);
	OnVertexBufferCreate(vb, null);

	projMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 4,
		this.Width / this.Height, 1.0f, 100.0f);

	viewMatrix = Matrix.LookAtLH(new Vector3(0,0, 5.0f), new Vector3(),
		new Vector3(0,1,0));

	VertexElement[] elements = new VertexElement[]
		new VertexElement(0, 0, DeclarationType.Float3,
		DeclarationUsage.Position, 0),

	decl = new VertexDeclaration(device, elements);

private void OnVertexBufferCreate(object sender, EventArgs e)
	VertexBuffer buffer = (VertexBuffer)sender;

	CustomVertex.PositionOnly[] verts = new CustomVertex.PositionOnly[3];
	verts[0].Position = new Vector3(0.0f, 1.0f, 1.0f);
	verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f);
	verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f);

	buffer.SetData(verts, 0, LockFlags.None);

private void UpdateWorld()
	worldMatrix = Matrix.RotationAxis(new Vector3(angle / ((float)Math.PI * 2.0f),
		angle / ((float)Math.PI * 4.0f), angle / ((float)Math.PI * 6.0f)),
		angle / (float)Math.PI);

	angle += 0.1f;

	device.Transform.View = viewMatrix;
	device.Transform.Projection = projMatrix;
	device.Transform.World = worldMatrix;

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
	device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0);


	device.SetStreamSource(0, vb, 0);
	device.VertexDeclaration = decl;

	device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);




Hoping for some help or hints in the right direction...

Share this post

Link to post
Share on other sites
Original post by andi_bold2
As I understand the vertexdeclaration substitutes the setvertexformat (SetFVF in c++) call.

You can still use SetFVF with non-FVF buffers. It's worth a shot, if you're drawing with the fixed pipe.

Share this post

Link to post
Share on other sites
Ok, solved it. I told you it probably was a trivial thing, and it was. (Problem is those simple things are the hardest ones to find [smile]). I had to specify the stride in setstreamsource... Well now my triangle is just where it should be and I just hope it was the only problem so I can move on with my real engine.

Share this post

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

  • Advertisement