Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vertex Buffer line Drawing

Started by Bitem2k Aug 1, 2005 at 9:19 AM 0 replies 600+ views
Original Post
Bitem2k
Bitem2k
Hi im using a vertex buffer to draw normal lines efficently. Im writting chunks of data to a vertex buffer and then drawing it to screen. This is working quite nicely however some lines appear to jump around like lasers, all the lines are in the correct places its just that they seem to be drawing before theyre in position! this must be something to do with my code but i cant see anything wrong with it. Can anyone see a problem here? //Variables private VertexBuffer vb; private static int maxVerts=1024; private static int flushSize=maxVerts/4; private static int flushLockSize = flushSize * CustomVertex.PositionColored.StrideSize; private VertexFormats format= CustomVertex.PositionColored.Format ; private int formatStride = CustomVertex.PositionColored.StrideSize; public void Draw() { int vertsToRender=0; if (vb ==null) this.device_DeviceReset (this,null); device.SetStreamSource (0,vb,0,formatStride); device.VertexFormat = CustomVertex.PositionColored.Format; if (nextVert > 0) nextVert += flushSize; if (nextVert > maxVerts) { //Reset nextVert = 0; } GraphicsStream vertexData = vb.Lock(nextVert * formatStride,flushLockSize,(nextVert != 0 ?LockFlags.NoOverwrite : LockFlags.Discard )); foreach(Ray r in rays) { //Write Postion and colour vertexData.Write (r.Position); vertexData.Write (Color.Yellow.ToArgb()); vertexData.Write (r.EndPosition ); vertexData.Write (Color.Yellow.ToArgb()); vertsToRender +=2; if (vertsToRender == flushSize) { //Unlock and draw vb.Unlock(); device.DrawPrimitives (PrimitiveType.LineList,nextVert,(vertsToRender/2)); nextVert += flushSize; if (nextVert > maxVerts) { nextVert = 0; } vertexData = vb.Lock (nextVert * formatStride,flushLockSize,nextVert !=0 ? LockFlags.NoOverwrite : LockFlags.Discard ); vertsToRender = 0; } } vb.Unlock(); //Render remaining if (vertsToRender >0) { device.DrawPrimitives (PrimitiveType.LineList,nextVert,vertsToRender/2); } } Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.