SharpGL: Can't draw all lines from List
Posted
by
Miko Kronn
on Stack Overflow
See other posts from Stack Overflow
or by Miko Kronn
Published on 2011-01-08T19:50:54Z
Indexed on
2011/01/08
19:53 UTC
Read the original article
Hit count: 242
I have:
float[,] nodesN = null; //indexes:
//number of node;
//value index 0->x, 1->y, 2->temperature
int[,] elements = null; //indexes:
//indexof element (triangle)
//1, 2, 3 - vertexes (from nodesN)
List<Pair> edges = null; //Pair is a class containing two int values which are
//indexes of nodesN
And function which is supposed do all elements and edges on SharpGL.OpenGLCtrl
private void openGLCtrl1_Load(object sender, EventArgs e)
{
gl = this.glCtrl.OpenGL;
gl.ClearColor(this.BackColor.R / 255.0f,
this.BackColor.G / 255.0f,
this.BackColor.B / 255.0f, 1.0f);
gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);
}
float glMinX = -2f;
float glMaxX = 2f;
float glMinY = -2f;
float glMaxY = 2f;
private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
{
gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.Translate(0.0f, 0.0f, -6.0f);
if (!draw) return;
bool drawElements = false;
if (drawElements)
{
gl.Begin(OpenGL.TRIANGLES);
for (int i = 0; i < elementNo; i++)
{
for (int j = 0; j < 3; j++)
{
float x, y, t;
x = nodesN[elements[i, j], 0];
y = nodesN[elements[i, j], 1];
t = nodesN[elements[i, j], 2];
gl.Color(t, 0.0f, 1.0f - t);
gl.Vertex(x, y, 0.0f);
}
}
gl.End();
}
gl.Color(0f, 0f, 0f);
gl.Begin(OpenGL.LINES);
//for(int i=edges.Count-1; i>=0; i--)
for(int i=0; i<edges.Count; i++)
{
float x1, y1, x2, y2;
x1 = nodesN[edges[i].First, 0];
y1 = nodesN[edges[i].First, 1];
x2 = nodesN[edges[i].Second, 0];
y2 = nodesN[edges[i].Second, 1];
gl.Vertex(x1, y1, 0.0f);
gl.Vertex(x2, y2, 0.0f);
}
gl.End();
}
But it doesn't draw all the edges. If i change drawElements
it draws different number of edges. Changing for(int i=0; i<edges.Count; i++)
to for(int i=edges.Count-1; i>=0; i--)
shows that esges are generated correctly, but they are not drawn.
Images:
for(int i=0; i<edges.Count; i++)
drawElements=false
for(int i=edges.Count-1; i>=0; i--)
drawElements=false
for(int i=0; i<edges.Count; i++)
drawElements=true
for(int i=edges.Count-1; i>=0; i--)
drawElements=true
What is wrong with this? How can I draw all edges?
© Stack Overflow or respective owner