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

Author Topic: SFML C# with OpenGL.net  (Read 3623 times)

0 Members and 1 Guest are viewing this topic.

BinarySpike

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML C# with OpenGL.net
« on: August 16, 2017, 09:26:59 am »
I'm trying to integrate SFML C# with OpenGL.net.  Unfortunately, whenever I call any Gl calls, the "window.clear" simply ceases to work.  I just want proof that they are working together properly before I move on to my next stage.

If I set it to clear red with SFML, it works fine until I add a "Gl" call.

Here is my current test code broken by "Gl.Initialize()":
class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(640, 480), "SFML window with OpenGL");
            window.SetVerticalSyncEnabled(true);

            // Setup event handlers
            window.Closed += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized += new EventHandler<SizeEventArgs>(OnResized);

            Gl.Initialize();

            // Start the game loop
            while (window.IsOpen)
            {
                // Process events
                window.DispatchEvents();

                window.Clear(Color.Red);
                window.Display();
            }
        }

        /// <summary>
        /// Function called when the window is closed
        /// </summary>
        static void OnClosed(object sender, EventArgs e)
        {
            Window window = (Window)sender;
            window.Close();
        }

        /// <summary>
        /// Function called when a key is pressed
        /// </summary>
        static void OnKeyPressed(object sender, KeyEventArgs e)
        {
            Window window = (Window)sender;
            if (e.Code == Keyboard.Key.Escape)
                window.Close();
        }

        /// <summary>
        /// Function called when the window is resized
        /// </summary>
        static void OnResized(object sender, SizeEventArgs e)
        {
            Gl.Viewport(0, 0, (int)e.Width, (int)e.Height);
        }
    }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML C# with OpenGL.net
« Reply #1 on: August 16, 2017, 10:16:58 am »
Do you really need to use the graphics module of SFML together with OpenGL? If not, then use a Window (not a RenderWindow), this way you are sure to avoid conflicts.
Laurent Gomila - SFML developer

 

anything