Search code examples
c#3dopentk

How to implement a vertical scroll bar for openTK gameWindow


I am developing a 2d windows application using openTK and c#. i am using gamewindow class.

class myWindow : GameWindow
{
}

is there any way to implement a vertical scroll bar for this window?? Thank You


Solution

  • Make your-very-own Scrollbar widget. Draw it in 2D using OpenGL:

    DrawVerticalScrollBar(scrollbar_x, scrollbar_y, 
       scrollbar_width, scrollbar_height, 
       vertical_scroll, min_value, max_value); //pseudocode
    

    Then later draw the contents of the "scroll-bar" view:

    GL.Enable(EnableCap.ScissorTest);
    GL.Scissor(view_start_x, view_start_y, view_end_x, view_end_y);
    
    // Assume matrix mode is modelview
    GL.PushMatrix();
    GL.Translate(0, -vertical_scroll, 0);
          // Draw the graphics affected by scrollbar
    GL.PopMatrix();
    
    GL.Disable(EnableCap.ScissorTest);
    
    // Draw rest of the 2d graphics
    

    If you don't want to clip contents of the view, you can remove the ScissorTest and GL.Scissor