Line list rendering problem.

Started by
3 comments, last by sumit381 17 years ago
I am making a data visualization program which basically display data on a 3D grid. I am making the grid using a line list. Also, the data points are created in two ways. 1st: using actual 3D mesh spheres. 2nd: using point sprites. When I use the 3D sphere my grid displays correctly. Here is a link to what it looks like: http://img115.imageshack.us/my.php?image=gridlinesappearnv2.gif But when I tried using the point sprites, the grid lines do not seem to appear. Except when I move in closer on the grid I can see that the grid are rendering but they are blending into the background color. Here are links to pictures of what that looks like: http://img48.imageshack.us/my.php?image=gridlinesdontappearju8.gif http://img240.imageshack.us/my.php?image=gridlinecloseupxh3.gif The following is the method that creates the data points: private void DrawDataPoints() { //d3dDevice.SetTexture(0, null); d3dDevice.SetTexture(0, sphereSpriteTexture); myownvertexformat[] spritecoordsarray = new myownvertexformat[dataList.Length]; for (int i = 0; i <= dataList.Length - 1; i++) { #region 3D Spheres - lower framerate // //If a data point is selected then the color sphere covering the // //selected sphere should also move with it. //if (hitColored && hitPos.X == dataList.X && hitPos.Y == dataList.Y && hitPos.Z == dataList.Z) //{ // d3dDevice.Transform.World = Matrix.Translation(currentXHit, currentYHit, currentZHit); // coverMesh.DrawSubset(0); //} //d3dDevice.Transform.World = Matrix.Translation((float)dataList.X, (float)dataList.Y, (float)dataList.Z); //dataSphereMesh.DrawSubset(0); #endregion #region 2D Sprites - higher framerate spritecoordsarray = new myownvertexformat((float)dataList.X, (float)dataList.Y, (float)dataList.Z, 1f, Color.Red.ToArgb()); #endregion } d3dDevice.VertexFormat = CustomVertex.PositionColored.Format | VertexFormats.PointSize | VertexFormats.Diffuse; d3dDevice.DrawUserPrimitives(PrimitiveType.PointList, dataList.Length - 1, spritecoordsarray); } Here is the myownvertexformat struct: struct myownvertexformat { public float xval; public float yval; public float zval; public float PointSize; public int icolor; public myownvertexformat(float fxval, float fyval, float fzval, float psize, int color) { xval = fxval; yval = fyval; zval = fzval; PointSize = psize; icolor = color; } } The following method draws the line grid: private void DrawLineGrid() { lineList = new VertexBuffer(typeof(CustomVertex.PositionColored), numOfVerts, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[numOfVerts]; // x-axis verts[0].Position = new Vector3((float)minX - 1, 0.0f, 0.0f); verts[1].Position = new Vector3((float)maxX + 1, 0.0f, 0.0f); // y-axis verts[2].Position = new Vector3((float)maxX, (float)maxY + 1, 0.0f); verts[3].Position = new Vector3((float)maxX, (float)minY - 1, 0.0f); // z-axis verts[4].Position = new Vector3((float)maxX, 0.0f, (float)minZ - 1); verts[5].Position = new Vector3((float)maxX, 0.0f, (float)maxZ + 1); // X-Z Grid int counter = 1; for (int v = 6; v <= (numOfZLines * 2) + 6; v += 2) { verts[v].Position = new Vector3((float)minX, 0, (float)minZ + counter); verts[v + 1].Position = new Vector3((float)maxX, 0, (float)minZ + counter); counter++; } // Y-Z Grid counter = 1; for (int v = (numOfZLines * 2) + 6; v <= (numOfZLines * 4) + 6; v += 2) { verts[v].Position = new Vector3((float)maxX, (float)minY, (float)minZ + counter); verts[v + 1].Position = new Vector3((float)maxX, (float)maxY, (float)minZ + counter); counter++; } // X-Y Grid counter = 0; for (int v = (numOfXLines * 4) + 6; v <= (numOfXLines * 6) + 6; v += 2) { verts[v].Position = new Vector3((float)minX + counter, (float)minY, 0); verts[v + 1].Position = new Vector3((float)minX + counter, (float)maxY, 0); counter++; } counter = 0; for (int v = (numOfZLines * 6) + 6; v <= (numOfZLines * 8) + 6; v += 2) { verts[v].Position = new Vector3((float)minX + counter, 0, (float)minZ); verts[v + 1].Position = new Vector3((float)minX + counter, 0, (float)maxZ); counter++; } counter = 1; for (int v = (numOfZLines * 8) + 6; v <= (numOfZLines * 10) + 6; v += 2) { verts[v].Position = new Vector3((float)maxX, (float)minY + counter, (float)minZ); verts[v + 1].Position = new Vector3((float)maxX, (float)minY + counter, (float)maxZ); counter++; } counter = 1; for (int v = (numOfXLines * 10) + 6; v <= (numOfXLines * 12) + 4; v += 2) { verts[v].Position = new Vector3((float)minX, (float)minY + counter, 0); verts[v + 1].Position = new Vector3((float)maxX, (float)minY + counter, 0); counter++; } for (int i = 0; i <= 5; i++) verts.Color = Color.Red.ToArgb(); for (int i = 6; i <= numOfVerts - 1; i++) verts.Color = Color.Green.ToArgb(); lineList.SetData(verts, 0, LockFlags.None); lineList.Unlock(); } The following code is in my render method: // Draws line grid d3dDevice.VertexFormat = CustomVertex.PositionColored.Format; d3dDevice.SetStreamSource(0, lineList, 0); d3dDevice.DrawPrimitives(PrimitiveType.LineList, 0, numOfVerts / 2); Please help in any way you can. Thanks!!!
Advertisement
i had the same issue once, try this, it helped me.

// Draws line grid
d3dDevice.RenderState.Lighting = false;
d3dDevice.VertexFormat = CustomVertex.PositionColored.Format;
d3dDevice.SetStreamSource(0, lineList, 0);
d3dDevice.DrawPrimitives(PrimitiveType.LineList, 0, numOfVerts / 2);
d3dDevice.RenderState.Lighting = true;

dunno if that is the problem of yours tho, going to dentist now, so had no time to check it all.
It looks like you've got alpha blending enabled, or the material is not set. Try turning alpha blending off and setting a white material before rendering the lines.
Thank you for your input NightMarez but that unfortunately did not fix the problem. My lighting is by default set to false in my device creation method. When I set the lighting to true, the sprites also disappear.
Hey, EvilSteve I tried turning off alpha blending but it didn't work. Also, how can I apply a material to my grid. I thought a material can only be applied to a mesh but my grid is a primitive type of LineList. Please inform me more in this matter. Thanks.

This is the new code that I used:

Material m = new Material();
m.Ambient = Color.White;
m.AmbientColor = ColorValue.FromColor(Color.White);
m.Diffuse = Color.White;
m.Diffuse = Color.White;
d3dDevice.RenderState.AlphaBlendEnable = false;
d3dDevice.Material = m;
// Draws line grid
d3dDevice.VertexFormat = CustomVertex.PositionColored.Format;
d3dDevice.SetStreamSource(0, lineList, 0);
d3dDevice.DrawPrimitives(PrimitiveType.LineList, 0, numOfVerts / 2);
d3dDevice.RenderState.AlphaBlendEnable = true;

This topic is closed to new replies.

Advertisement