[Solved] Noesis GUI and OpenTK rendering issues
Posted: 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:
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:
Code: Select all
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;
}
}
}