SFML community forums

Bindings - other languages => DotNet => Topic started by: marko on December 28, 2014, 10:47:27 am

Title: Drawing a triangle in C#
Post by: marko on December 28, 2014, 10:47:27 am
I'm trying to learn to SFML and C# programming language.

At address http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php is following code:

// create an array of 3 vertices that define a triangle primitive
sf::VertexArray triangle(sf::Triangles, 3);

// define the position of the triangle's points
triangle[0].position = sf::Vector2f(10, 10);
triangle[1].position = sf::Vector2f(100, 10);
triangle[2].position = sf::Vector2f(100, 100);

// define the color of the triangle's points
triangle[0].color = sf::Color::Red;
triangle[1].color = sf::Color::Blue;
triangle[2].color = sf::Color::Green;

// no texture coordinates here, we'll see that later

 


I managed to get a similar triangle drawn using C# with the following code:

           

VertexArray triangle = new VertexArray(PrimitiveType.Triangles, 3);

Vertex vtx = triangle[0];
vtx.Position = new Vector2f(10, 10);

triangle[0] = new Vertex(new Vector2f(10, 10), Color.Red);
triangle[1] = new Vertex(new Vector2f(100, 10), Color.Blue);
triangle[2] = new Vertex(new Vector2f(100, 100), Color.Green);
 


Is this way I made the correct way to do this? I hardly understand C++ and have experience of Java, that's why I'm trying to learn C# programming.
Title: Re: Drawing a triangle in C#
Post by: Laurent on December 28, 2014, 12:08:37 pm
Yes, but these 2 lines are totally useless:

Vertex vtx = triangle[0];
vtx.Position = new Vector2f(10, 10);