Jump to content
  • Advertisement
Sign in to follow this  
Bitem2k

Vertex Buffer line Drawing

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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!