FoolRunning
Topic Author
Posts: 3
Joined: 10 Sep 2017, 21:31

[Solved] Noesis GUI and OpenTK rendering issues

15 Sep 2017, 03:15

I'm trying to get the C# OpenGL sample to work using OpenTK. I've managed to get the GUI rendering (was actually very easy), but it's acting strangely.
For example, the dropdowns from the ComboBox controls aren't visible (but I can still click on them as if they are there) and the check marks don't show up in the CheckBox controls (but the TextBox control does change states). However, some things like moving the handle of the Slider controls and typing in the TextBox control work just fine (except the mouse-over effects don't show up).

I've checked for OpenGL errors (there are none) and I've seen that someone else has gotten Noesis GUI working using OpenTK, so I'm assuming that I setup my GL context wrong or have some weird OpenGL state that's affecting things (although I think the only state I'm setting is the same states set in the OpenGL sample). I've spent several hours trying to track down what's going on and have gotten nowhere.

EDIT: Forgot to mention that the C# OpenGL sample runs just fine on my machine (so I know it's not a hardware problem).

Anyone have any ideas?

Here's my code:
    internal sealed class MainWindow : GameWindow
    {
        private View view;
        private Renderer renderer;

        public MainWindow() : base(1280, 720, new GraphicsMode(32, 24, 8, 1, ColorFormat.Empty, 3), "Test", 
            GameWindowFlags.Default, DisplayDevice.Default, 3, 1, GraphicsContextFlags.Default)
        {
            VSync = VSyncMode.On;
            //WindowState = WindowState.Fullscreen;
        }

        #region Overrides of GameWindow
        protected override void OnLoad(EventArgs e)
        {
            GUI.Init();
            GUI.SetResourceProvider("Data");

            GUI.SetTheme((ResourceDictionary)GUI.LoadXaml("NoesisStyle.xaml"));
            //GUI.SetTheme((ResourceDictionary)GUI.LoadXaml("SimpleStyle.xaml"));
            Grid content = (Grid)GUI.LoadXaml("TextBox.xaml");
            
            view = GUI.CreateView(content);
            renderer = view.Renderer;
            renderer.InitGL(new VGOptions());
            
            view.Update(0.001); // Ensures view is updated before first render call (avoids crash)
        }

        protected override void OnUnload(EventArgs e)
        {
            renderer.Shutdown();
            GUI.Shutdown();
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            view.SetSize(Width, Height);
        }

        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            view.Update(e.Time);
        }

        protected override void OnRenderFrame(FrameEventArgs e)
        {
            renderer.UpdateRenderTree();

            if (renderer.NeedsOffscreen())
                renderer.RenderOffscreen();

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.ClearDepth(1.0f);
            GL.DepthMask(true);
            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.StencilTest);
            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.ScissorTest);

            GL.UseProgram(0);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Viewport(0, 0, Width, Height);
            GL.ColorMask(true, true, true, true);

            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.LoadIdentity();
            GL.Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

            renderer.Render();

            SwapBuffers();
        }

        protected override void OnMouseMove(MouseMoveEventArgs e)
        {
            view.MouseMove(e.X, e.Y);
        }

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            view.MouseDown(e.X, e.Y, TranslateButton(e.Button));
        }

        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            view.MouseUp(e.X, e.Y, TranslateButton(e.Button));
        }

        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            view.KeyDown(TranslateKey(e.Key));
        }

        protected override void OnKeyUp(KeyboardKeyEventArgs e)
        {
            view.KeyUp(TranslateKey(e.Key));
            if (e.Key == Key.Escape)
                Exit();
        }

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            view.Char(e.KeyChar);
        }
        #endregion

        private static Noesis.Key TranslateKey(Key key)
        {
            switch (key)
            {
                case Key.F1: return Noesis.Key.F1;
                case Key.F2: return Noesis.Key.F2;
                case Key.F3: return Noesis.Key.F3;
                case Key.F4: return Noesis.Key.F4;
                case Key.F5: return Noesis.Key.F5;
                case Key.F6: return Noesis.Key.F6;
                case Key.F7: return Noesis.Key.F7;
                case Key.F8: return Noesis.Key.F8;
                case Key.F9: return Noesis.Key.F9;
                case Key.F10: return Noesis.Key.F10;
                case Key.F11: return Noesis.Key.F11;
                case Key.F12: return Noesis.Key.F12;
                case Key.PageUp: return Noesis.Key.Prior;
                case Key.PageDown: return Noesis.Key.Next;
                case Key.Home: return Noesis.Key.Home;
                case Key.End: return Noesis.Key.End;
                case Key.Insert: return Noesis.Key.Insert;
                case Key.Left: return Noesis.Key.Left;
                case Key.Right: return Noesis.Key.Right;
                case Key.Up: return Noesis.Key.Up;
                case Key.Down: return Noesis.Key.Down;
                case Key.Enter: return Noesis.Key.Return;
                case Key.Tab: return Noesis.Key.Tab;
                case Key.BackSpace: return Noesis.Key.Back;
                case Key.Space: return Noesis.Key.Space;
                case Key.Delete: return Noesis.Key.Delete;
            }
 
            return Noesis.Key.None;
        }

        private static Noesis.MouseButton TranslateButton(MouseButton button)
        {
            switch (button)
            {
                case MouseButton.Left: return Noesis.MouseButton.Left;
                case MouseButton.Right: return Noesis.MouseButton.Right;
                case MouseButton.Middle: return Noesis.MouseButton.Middle;
                default: return Noesis.MouseButton.XButton1;
            }
        }
    }
Last edited by FoolRunning on 18 Sep 2017, 15:16, edited 1 time in total.
 
FoolRunning
Topic Author
Posts: 3
Joined: 10 Sep 2017, 21:31

Re: Noesis GUI and OpenTK rendering issues

16 Sep 2017, 19:45

Well, after about three days of pulling my hair out, I finally figured out what is wrong. :?

To anyone who has a similar problem when using Noesis GUI and ends up here:
Noesis.View.Update is expecting an ever-increasing time (i.e. the total time that the program has been running - in seconds) and not what I was assuming (the time in seconds since the last update - which is what OpenTK gives in it's Time property). If I had paid more attention to the samples floating around, I would have noticed that. :oops:

So basically the problem I was seeing is that all animations were not playing because the view thought that no time was passing between updates. All the things that were missing in the UI were animated in some way.
 
User avatar
jsantos
Site Admin
Posts: 3919
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Solved] Noesis GUI and OpenTK rendering issues

18 Sep 2017, 18:35

Thanks for coming back here with feedback! At first I though that the source of your problem could be improper rendering of offscreens (remember that after calling RenderOffscreen you need to restore the default render target and viewport) but now I see it is a different thing.

This problem with the time is so frequent that I think we should at least check that the value is always being incremented from frame to frame and signal an error when it doesn't happen.
 
FoolRunning
Topic Author
Posts: 3
Joined: 10 Sep 2017, 21:31

Re: [Solved] Noesis GUI and OpenTK rendering issues

18 Sep 2017, 19:36

This problem with the time is so frequent that I think we should at least check that the value is always being incremented from frame to frame and signal an error when it doesn't happen.
I would definitely vote for this as it would have saved me a bunch of time. ;)

I also want to thank you all for this really nice library. Of all the GUI libraries I've been evaluating, it's definitely the easiest to setup and use. You also have some great documentation and the licensing is very reasonable for an indie/solo developer. :D
 
User avatar
jsantos
Site Admin
Posts: 3919
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Solved] Noesis GUI and OpenTK rendering issues

18 Sep 2017, 20:33

Thanks for the kind words! Integration and samples are going to be even better in next versions.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 16 guests