Re: Updating the colour of a vertexbuffer



ZMan,
Thanks for the reply.

I'm found the problem. Changing the vertexbuffer Usage from Usage.Dynamic |
Usage.WriteOnly to 0 fixed it. I think I better read up on the Usage flags.

Thanks for your help.

"ZMan" wrote:

> What is colour set to ? If its 0 then your object may be there it just may
> be all black. Set the background of you DX device to blue and you should see
> that.
>
> Otherwise your code should work fine. I pasted the following
> Color colour = Color.Gray;
>
> CustomVertex.PositionColored[] vertices =
> (CustomVertex.PositionColored[])vb.Lock(0, LockFlags.None);
>
>
> for (int i = 0; i < vertices.Length; i++)
>
> {
>
> vertices[ i ].Color = colour.ToArgb();
>
> }
>
>
> vertexBuffer.Unlock();
>
>
>
> into the end of the OnCreateVertexBuffer() in tutorial3 from the OctoberSDK
> and I got a greay triangle.
>
> Is your vertex buffer PositionColored already? If not then you have to
> ..Clone it to change the vertextype (though I'm sure you get an exception if
> you try to do this).
>
>
>
>
> --
> Zman
> http://www.thezbuffer.com - News and information for Managed DirectX
>
>
>
> "Phil Williams" <PhilWilliams@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:00150E30-2509-4571-9868-6563FACB860F@xxxxxxxxxxxxxxxx
> > I'm a newcomer to managed DirectX.
> >
> > I'm trying to change the colours in a existing vertexbuffer using the
> > following code.
> >
> > CustomVertex.PositionColored[] vertices =
> > (CustomVertex.PositionColored[])vertexBuffer.Lock(0, LockFlags.None);
> >
> > for (int i = 0; i < vertices.Length; i++)
> > {
> > vertices[ i ].Color = colour;
> > }
> >
> > vertexBuffer.Unlock();
> >
> > But the object just disappears. Everything else still renders find. I've
> > tried the same code in a simple example from Tom Miller's book, with the
> > same
> > result.
> >
> > I would be grateful of any help.
> >
> > Cheers,
> > Phil.
>
>
>
.