Results 1 to 4 of 4

Thread: Scrollbar

  1. #1
    Member Contributor
    Join Date
    Feb 2005
    Posts
    83

    Scrollbar

    I've made a scrollbar to scroll some picture, build with statements like glBegin(GL_LINE), etc. So it's not a texture image. If I scroll the bar, it's reaction time is too slow, so I want to speed up the scrollingfunction. Can I put the picture, during run time in a texture? If yes, how?

    I hope anybody can help me.

  2. #2
    Member Contributor
    Join Date
    Jun 2003
    Location
    Blacksburg, VA 24060, USA
    Posts
    59

    Re: Scrollbar

    I'll suggest u to use some openGL based GUI toolkit like GLUI (google for 'GLUI') for the scrollbar.

    The toolkit will take care of managing the scrollbar, what u will need to do is just get a value from the scrollbar and change your camera accordingly.

    - Chetan

  3. #3
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Scrollbar

    Make sure you have an image with packed 8 bit data per component per pixel like rgbrgbrgbrgb etc. etc for each pixel, and make calls like the following ONLY ONCE AT THE START but make sure it's AFTER you have your OpenGL context active:

    glBindTexture(GL_TEXTURE_2D, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, your_image_pointer);

    Then when you need to use the texture call:

    glBindTexture(GL_TEXTURE_2D, 1);
    glEnable(GL_TEXTURE_2D);

    To draw a quad with the texture on it use the following code, just alter the glVertex calls to suit your needs, you obviously know what these do now.

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex2f(0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex2f(1.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex2f(1.0f, 1.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex2f(0.0f, 1.0f);
    glEnd();

    Then when you're done call

    glDisable(GL_TEXTURE_2D);

    If you want to use other images simply use glBindTexture(GL_TEXTURE_2D, 2); with a different integer NOTE I'VE CHANGED THE ONE TO A TWO, that tells OpenGL this is a different texture, the second argument is a unique handle identifying the texture, you can use any numbers you like unless you want to play nicely with other software libraries you might link to. You can initialize lots of textures once at the start and use them later with the bind calls, this will ensure your code is nice & fast when you move the slider.

    If you only have one texture you don't need the bind calls, however you will need to use them later if you add images and want to stay as fast as possible.

    This is very basic and so the code looks surprisingly simple, once you get this working you can improve it with features like texture filtering etc.

    This is all untested so excuse any typos. One thing you may want to do depending on your image is change the formats and use ABGR to speed up load time marginally depending on your image source, but just try to get something working first, then you can get fancy later.

  4. #4
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Scrollbar

    P.S. Bind reserves 0 so don't use that integer, although I think if you don't bind at the start it'll use zero for your first load. I wouldn't rely on this though. If you bother with bind calls use a non zero unsigned int to identify each texture you load.

Similar Threads

  1. Scrollbar for opengl view
    By hockeyman in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-28-2012, 05:51 AM
  2. scrollbar with opengl
    By rohit in forum OpenGL: Windows
    Replies: 2
    Last Post: 05-03-2009, 11:13 PM
  3. OpenGL flickering due to scrollbar ?
    By rockeye in forum OpenGL: Windows
    Replies: 6
    Last Post: 04-03-2008, 01:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean