Jump to content
  • Advertisement
Sign in to follow this  
DriveByBaptism

OpenGL Scrolling box

This topic is 2599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

At the moment I am using GLFW to make use of OpenGL (not sure how much of a difference that will make) and I need to make some scrollable windows that appear in certain game screens. For example, I have a buy screen in my game the needs to display items for sale. Rather than clutter up the screen with all the items I want to make a window where only a set amount of items are on display, and you need to scroll down to the see them all.

Much like the browser window your using to view this post.

I've looked about but can't seem to find anything. Could someone point me in the right direction for this. I'm fairly new to the world of OpenGL.

Share this post


Link to post
Share on other sites
Advertisement
It doesn't look like GLFW has any built in font support so you'll either have to write your own or find another library to use.

Searching came up with CEGUI as one option

I decided to make my own Gui; I haven't done any scrolling menus yet but they should be pretty simple to implement into my Box/Menu classes.

I prefer to have fixed width bitmap font so this was not hard to do at all. Just load the character map and write your drawing functions (character, line, boxes).

I haven't tried doing truetype font I imagine it would be a bit more difficult if that's the sort of thing you need.

The other complication is handling input. I have a pretty easy to use 'Input' stack of Input Maps so I can push/pop bindings quite easily for each Menu or Item.

Mostly OpenGL doesn't have to do but the drawing of the Gui

Share this post


Link to post
Share on other sites
I have just completed a scroll-list object in my GUI. The way I do it; first draw your list box as you want it to look without the items for sale. For example if you want a background that doesn't scroll and a border around it - you draw that first. For the items that are to be displayed and clipped inside the list box I use glScissor. The function restricts the rendering to a rectangular area. Pseudo code:

[source lang="cpp"]
// Draw non scrolling stuff
....

// Draw scrolling stuff
glScissor(scissorX, scissorY, scissorWidth, scissorHeight);

glEnable(GL_SCISSOR_TEST);

glPushMatrix();
glTranslated(scrollx,scrolly);
//draw items in shop
glBegin(...);
glEnd();
glPopMatrix();

glDisable(GL_SCISSOR_TEST);
[/source]
That is how I would do it. The same thing can probably be accomplished another way. Maybe using a stencil test or something.

glScissor reference link.

Good luck!

Share this post


Link to post
Share on other sites
For the items that are to be displayed and clipped inside the list box I use glScissor.


The alternative would be to set the projection and viewport accordingly. It's probably not a bad idea to do one of those things for all GUI elements before rendering its children (in case of long text lines etc.).

You might notice that many games are lazy and just have up/down buttons, but no button to drag. It's a good bit of extra logic to calculate the size and position, but really worth it if you expect to have way more items than you can fit in the box. Or think really hard about whether one click should scroll one item or one screen (or one screen minus one item, since that is less disorienting) and how soon/fast repeating will happen if the mouse buttons remains pressed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!