Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing a triangle in C#  (Read 4623 times)

0 Members and 1 Guest are viewing this topic.

marko

  • Newbie
  • *
  • Posts: 1
    • View Profile
Drawing a triangle in C#
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing a triangle in C#
« Reply #1 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);
Laurent Gomila - SFML developer

 

anything