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

Author Topic: help drawing line in static class (SFML.Net)  (Read 1132 times)

0 Members and 1 Guest are viewing this topic.

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
help drawing line in static class (SFML.Net)
« on: September 15, 2018, 09:18:32 pm »
can someone tell me why my line is not showing up in my window?
I made a graphics class that has a line drawing function
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Graphics;
using SFML.System;

namespace SFMLTest.Library
{
    struct Graphics
    {
        static RenderWindow RenderWindow;
        static RectangleShape RectangleShape;

        static public void Init(RenderWindow renderWindow)
        {
            RenderWindow = renderWindow;
            RectangleShape = new RectangleShape();
        }

        static public void Line(Color color, int x1,int y1,int x2, int y2, int thickness)
        {
            float rx1 = x1;
            float rx2 = x2;
            float ry1 = y1 - thickness;
            float ry2 = y2 + thickness;

            float rw1 = rx2 - rx1;
            float rh1 = ry2 - ry1;

            float rr1 = (float)Math.Atan2(rx2 - rx1, ry2 - ry1);

            RectangleShape.Position  = new Vector2f(rx1, ry1);
            RectangleShape.Size      = new Vector2f(rw1, rh1);
            RectangleShape.Rotation  = rr1;
            RectangleShape.Origin    = new Vector2f(x2-x1, y2-y1);
            RectangleShape.FillColor = color;
            RenderWindow.Draw(RectangleShape);
        }
    }
}

I also have this as my main window
Code: [Select]
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Graphics;
using SFML.Window;

using SFMLTest.Library;

namespace SFMLTest
{
    public class Program
    {
        static RenderWindow window;

        [STAThread]
        static void Main(string[] args)
        {
            window = new RenderWindow(new VideoMode(480, 432), "MyWindow");
            window.SetActive();
            window.Closed += OnClose;

            Graphics.Init(window);

            while (window.IsOpen)
            {
                window.Clear(Color.Black);
                window.DispatchEvents();

                Graphics.Line(Color.White, 0, 0, 640, 144, 1);

                window.Display();
            }
        }

        static void OnClose(object sender, EventArgs e)
        {
            RenderWindow renderWindow = (RenderWindow)sender;
            renderWindow.Close();
        }
    }
}



however its not drawing anything

 

anything