how to create a sliding bar in opengl?

This is a discussion on how to create a sliding bar in opengl? within the Game Programming forums, part of the General Programming Boards category; anyone got any sample code on how to create a sliding bar in opengl? i try looking on the net, ...

  1. #1
    Registered User zell's Avatar
    Join Date
    Jan 2005
    Posts
    37

    how to create a sliding bar in opengl?

    anyone got any sample code on how to create a sliding bar in opengl?

    i try looking on the net, couldn't find one.

    thanks alot in advance
    learning c programming for operating systems...
    learning openGL for graphics design...

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    what exactly do you mean by "sliding bar".

  3. #3
    Registered User zell's Avatar
    Join Date
    Jan 2005
    Posts
    37
    u know those u adjust to the left and right to achieve different values
    something like a scroll bar on the right of the IE browser
    learning c programming for operating systems...
    learning openGL for graphics design...

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    well depending on a couple factors a very general outline is like this:

    1. create a textured polygon that is your slide background
    2. create a textured polygon that is the slide
    3. put them where you want them
    4. set the precision or whatever you call it the number of possible value positions the slider can have
    5. calculate the pixel to precision ratio
    6. set the slide at its default position based on the default value
    7. when clicked have the slide follow the mouse horizontally or vertcially to the limits of the slide, and snap it to position wherever it is when the mouse button is let up. or if the slide is not clicked but the slide background is, either have the slide jump to that position or move towards it.
    8. calculate the value based on the new position of the slide

    also remember to calculate room at ends of the background to account for the slide, so it doesn't go over the edge...
    you could create a third polygon that represents the "groove" to make it easier to keep the slide in bounds.
    Last edited by no-one; 02-11-2005 at 04:34 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    OpenGL is not a widget set, its a graphics library. If you want widgets such as scroll bars you'll need to use a widget library (GUI) or build the components from scratch as no-one describes.

  6. #6
    Registered User zell's Avatar
    Join Date
    Jan 2005
    Posts
    37
    thanks
    did a pretty simple one, but enough for my case





    Quote Originally Posted by no-one
    well depending on a couple factors a very general outline is like this:

    1. create a textured polygon that is your slide background
    2. create a textured polygon that is the slide
    3. put them where you want them
    4. set the precision or whatever you call it the number of possible value positions the slider can have
    5. calculate the pixel to precision ratio
    6. set the slide at its default position based on the default value
    7. when clicked have the slide follow the mouse horizontally or vertcially to the limits of the slide, and snap it to position wherever it is when the mouse button is let up. or if the slide is not clicked but the slide background is, either have the slide jump to that position or move towards it.
    8. calculate the value based on the new position of the slide

    also remember to calculate room at ends of the background to account for the slide, so it doesn't go over the edge...
    you could create a third polygon that represents the "groove" to make it easier to keep the slide in bounds.
    learning c programming for operating systems...
    learning openGL for graphics design...

  7. #7
    Registered User zell's Avatar
    Join Date
    Jan 2005
    Posts
    37
    now i come to another problem
    i want to create a another window for the sliding bar itself

    how do i do it?
    learning c programming for operating systems...
    learning openGL for graphics design...

  8. #8
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    you mean another Window's type window? and have them communicate? that, lies outside of my realm of expertise.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    In OpenGL you wouldn't have to make each object a window as you do in true Windows programming. Most of the same thing can be 'simulated' by clever use of textured quadrilaterals. Note that you can also use alpha blending to achieve some affects that Window's GUIs still can't do very well.

    You could create your own window's class. Create a default type of WndProc() for your window and make it virtual.

    If the user does not re-define WndProc() relative to the window he creates by deriving from the base Window class, then all messages will go to your WndProc().

    But sending messages to the WndProc() is quite simple as well as is tracking the mouse, keyboard, etc.

    You can use the same exact setup that Windows uses or you can create your own. But you don't have to use the RegisterClass() methodology with this setup....I think that would be too much.

    Code:
    #include <queue.h>
    
    struct MSG
    {
      DWORD msg;
      Vector2 MousePos;
    };
    
    class CWindow
    {
       protected:
       
        public:
          CWindow(void) {}
          queue<MSG> MessageQueue;
    
          virtual int WndProc(MSG pMsg,WORD lParam,WORD wParam);
    
          //Text functions
          //Caret functions
          //Window access functions
          //Window drawing functions
          //Message functions
          //etc, etc.
    };
    
    
    //Static objects
    class CStatic:public CWindow
    {
    }
    
    class CBitmap:public CStatic
    {
    }
    
    class CText:public CStatic
    {
    }
    
    
    //Button objects
    class CButton:public CWindow
    {
    }
    
    class CRadioButton:public CButton
    {
    }
    
    class CCheckBox:public CButton
    {
    }
    
    //Edit controls
    class CEdit:public CWindow
    {
    }
    
    //Listboxes
    class CListBox:public CWindow
    {
    }
    
    class CListBoxCtrl:public CListBox
    {
    }
    
    //the sky is the limit
    With this type of setup you can do a pretty rudimentary Windows type GUI with little trouble.

    The most important class in the framework is CWindow. Almost all window functionality ever needed should be in this class.

    If you do choose to use the RegisterClass setup then you can be assured that every window in the system will have a message queue because you have given it one. When an event happens and you need to send a message you post the message to the queue or you can directly call the window's WndProc with the message. Messages are passed along from the parent window object to its children and/or to its controls. You can create dialog boxes and all kinds of stuff if you really sit down and think it through.

    Also if you understand a bit about Win32 programming then you should be able to emulate this in a graphical environment like OpenGL. The benefit to this is that most of us are quite familiar with Win32 programming and so using your GUI system would be a snap.

    If you want to know the truth I look for Windows to be ported to using 3D graphics and textured quads in the future. 3D cards are much faster and the interface looks much jazzier. Plus you don't have to worry about DC's (except with printers, etc) and it would be a lot easier to use graphics in the API. Maybe I'm wrong, but I think Microsoft should move the entire GUI into Direct3D and dump the 2D stuff.
    Last edited by VirtualAce; 02-15-2005 at 12:11 AM.

  10. #10
    Trolley boy JackGL's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    15
    Quote Originally Posted by Bubba
    Maybe I'm wrong, but I think Microsoft should move the entire GUI into Direct3D and dump the 2D stuff.
    They are .

    I don't know if they're going to expand the API to make use of the extra sexiness, or what's happening at a programmer level, but early screenshots of the new GUI do look very swish.

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    The only major problem I can foresee is with text rendering. It would be nearly impossible to resize a True Type Font texture without losing clarity...if the GUI does indeed used textured quads to render the text. On the other hand if they use filtering that could also smooth out the jaggies induced into the image by resizing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Status bar
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2005, 10:45 AM
  2. Cannot create MDI Client Win
    By JaWiB in forum Windows Programming
    Replies: 1
    Last Post: 10-31-2005, 09:05 PM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  5. program won't create status bar
    By Unregistered in forum Windows Programming
    Replies: 7
    Last Post: 08-30-2001, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21