Closed ghost closed 7 years ago
At the first sight everything seems correct: 6 vec2 elements for 2 triangles, packed into an array of floats.
The vanilla example is running correctly on your machine?
I was able to reproduce the problem, and actually I solved it with few actions.
First, you should really care about the overload of the function you use. For example, Gl.Ortho(-1, 1, -aspect, aspect, 0, 1);
will select the glOrthof
function, which is a GL ES 1 function. The correct overload is glOrtho(double,double,double,double,double,double)
; indeed the correct code is Gl.Ortho(-1.0, 1.0, (double)-aspect, (double)aspect, 0.0, 1.0);
. Sadly, the function call throws an AccessViolationException
: quite strange. Indeed I worked around it by playing with LoadMatrix:
OrthoProjectionMatrix projectionMatrix = new OrthoProjectionMatrix(-1.0f / this.scale, 1.0f / this.scale, -aspect / this.scale, aspect / this.scale, 0.0f, 1.0f);
Gl.LoadMatrix(projectionMatrix.ToArray());
The next exception if the one you described: InvalidAccessException
at Gl.DrawArrays
. I converted the list in List<Vertex2f>
: from that point the program is currently working without exceptions.
List<Vertex2f> vertexList = new List<Vertex2f>();
vertexList.Add(new Vertex2f(cell.gridPoint.x - offset, cell.gridPoint.y - offset)); // bl
vertexList.Add(new Vertex2f(cell.gridPoint.x - offset, cell.gridPoint.y + offset)); // tl
vertexList.Add(new Vertex2f(cell.gridPoint.x + offset, cell.gridPoint.y + offset)); // tr
vertexList.Add(new Vertex2f(cell.gridPoint.x - offset, cell.gridPoint.y - offset)); // bl
vertexList.Add(new Vertex2f(cell.gridPoint.x + offset, cell.gridPoint.y - offset)); // br
vertexList.Add(new Vertex2f(cell.gridPoint.x + offset, cell.gridPoint.y + offset)); // tr
That changes the .Length
property, specifying the correct number of elements to draw (i.e. 6 for 2 triangles, not 12).
At the end, cool animation.
Another note on glOrtho
call: avoid calling directly on SizeChanged
event handler before ContextCreated
event handler is run (that's the behavior on my machine, running NVIDIA/Intel driver).
Probably the driver suppose a context created and current for calling Gl.Ortho
, and glControl_SizeChanged
is called one time before glControl_ContextCreated
.
Grazie mille :) Yep, the trick is to use Vertex2f instead of plain float. I am quite new to OpenGL and am focusing on the cool animation (thank you :) ). So I used mainly online opengl examples in cpp and there was no mentioning of Vertex2f :) Thanks for the cool project, it saved me lots of time! Good luck!
Well, you can still use float[]
arrays as vertex arrays: it is sufficient to pass the correct vertex elements count to Gl.DrawArrays
(in your case Array.Length / 2
). The use of Vertex2f
structure it's just a way to be explicit on the vertex input format, making the code more elegant and readable.
Vertex*
structures are very specific to this library, but they are complete and very useful for passing simple vertex attributes to OpenGL.
Yes, they surely are :)
Installed OpenGL.Net version: 0.3.2
The following code causes memory protection fault (but not always):
The following code works fine:
When the faulty code does not crash, from some point on massive visual artifacts appear.
Please check the attached project conway-set.zip .