// Adds a rectangle shape to the current frame public void DrawRect(RVIVector2 pos, float width, float height) { if (_currentFrame != null) { RVIShape rect = RVIShape.CreateRect(new RVIRectangle(pos.x, pos.y, width, height), _currentColorRGBA); lock (_framesLock) { _frames[_currentFrame].Add(rect); } } }
// Adds a line shape to the current frame public void DrawLine(RVIVector2 posA, RVIVector2 posB) { if (_currentFrame != null) { RVIShape line = RVIShape.CreateLine(posA, posB, _currentColorRGBA); lock (_framesLock) { _frames[_currentFrame].Add(line); } } }
private void openGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args) { // Shape count to show on the corner int shapeCount = 0; // Vertex count to show on the corner int vertexCount = 0; // Get the openGL object from the args OpenGL gl = args.OpenGL; // Clear color buffer and depth buffer gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear matrix modifications gl.LoadIdentity(); // GL.Begin on line drawing mode gl.Begin(OpenGL.GL_LINES); // Lock the frame dictionary lock to read from it lock (_framesLock) { // Iterate through every frame for (int frameIdx = 0; frameIdx < _frames.Count; frameIdx++) { // Get the frame for the current index List <RVIShape> frame = _frames.ElementAt(frameIdx).Value; // Iterate through every shape in the current frame for (int shapeIdx = 0; shapeIdx < frame.Count; shapeIdx++) { // Get the shape for the current index RVIShape shape = frame[shapeIdx]; // Get the color of the shape byte r = (byte)(shape.Color32 >> 24); byte g = (byte)(shape.Color32 >> 16); byte b = (byte)(shape.Color32 >> 8); byte a = (byte)(shape.Color32 >> 0); // Set the openGL color to the shape color gl.Color(r, g, b, a); // Iterate through every vertex in the shape for (int vertexIdx = 0; vertexIdx < shape.VertexList.Count; vertexIdx++) { // Set the openGL vertex for the current vertex index gl.Vertex(shape.VertexList[vertexIdx].x, shape.VertexList[vertexIdx].y); vertexCount++; } // Increment the shape count shapeCount++; } } } // End drawing lines gl.End(); // Flush any remaining openGL commands gl.Flush(); // Draw vertex and shape count DrawTextGL(gl, "Shape count = " + shapeCount.ToString(), new RVIVector2(5, 20), .50f, .2f, 1f, "Courier New", 1.0f); DrawTextGL(gl, "Vertex count = " + vertexCount.ToString(), new RVIVector2(5, 35), .50f, .2f, 1f, "Courier New", 1.0f); }