Game preference type dialog

Posts: 14
Joined: 2005.12
Post: #1
K, I'm new to OpenGL and have only been part way through the NeHe tutorials. Couple questions that I can't seem to find answers to or need my hunches confirmed. I think some of these can be solved by using Cocoa's windows and stuff (similar to BitRacer), but I'd like to stick to all OpenGL for now.

0. If I want to have a game preferences dialog/screen and it has buttons for various things, do I need to do the button as a quad and then texture it?

1. If #1 is correct (use quads), how does one do rounded buttons? If I have just a single quad with a rounded button texture on it, won't the user be able to click the corner of the quad that's in the texture's transparent area?

2. Is there some easy way to do the mouse over/click? I'm think I would use the selection/pick stuff.

3. Is there a library or something that handles this stuff? Or maybe a demo that just draws buttons and stuff?

4. Does putting a text string in a given font/size on the screen have to be so hard?
Quote this message in a reply
Posts: 133
Joined: 2008.05
Post: #2
0. That is one way to do it, it happens to be the easiest way in an all opengl application.

1. Rounded buttons are done by using blending. You draw a quad, and use a texture with an alpha mask. For example, if you wanted a red circlular button, you'd make a 32x32 texture all red, with an alpha mask of a black circle on a white background.

2. Generally speaking, most of you're button drawing will be 2D, using ortho projection. That means you're projection matrix is not going to truly have a z coordinate, so you can just use screen coordinates for that. Remember that OpenGL uses 0,0 to define the bottom left corner, as opposed to OSX's top-left orientation.

3. There are plenty of libraries to do this. Just recently, I was using FLTK( as part of a class project. It's ugly, but it gets the job done. Has a very windowsy look.

4. Yes. Smile For simple stuff, I use aglString from apple's website. Someone else would know better about this.
Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #3
To add to what LongJumper said:

1. After you've drawn your textured and blended quad with an alpha channel, you can also do a test to see whether or not your mouse click landed on a pixel that was transparent or not. That way you can accurately ignore any mouse clicks outside of your rounded button and not just the whole rectangular quad.

4. Yeah, sorry, that's gotta be one of the more non-fun things to figure out with OpenGL. FTGL is a popular route if you do C++. I use Freetype for fancy font rendering (which is what FTGL is based on), and good ol' display listed bitmap fonts for other stuff where I might want some extra effects and don't mind the speed hit. Really though you can usually just get by with the display listed fonts for a wide variety of gaming needs. And what I mean by display listed fonts is just what that simple NeHe tutorial does. The freetype route isn't impossible but you have to spend some time reading through and understanding the documentation, plus some coding. I don't recommend it for beginners. The aglString route of LongJumper's is plenty good enough if you're doing Carbon. There is a similar example from Apple which does it with Cocoa and I can highly recommend it. In fact, if you're not planning on doing any cross-platform stuff for a while (or ever) and you can do Cocoa I would say that is THE way to go, above everything else, including FreeType. I can't remember the name of the example from Apple though. Maybe StringTexture?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Dialog boxes with SDL + OpenGL IBethune 11 11,753 Feb 4, 2009 06:33 PM
Last Post: FlamingHairball
  Tricks with dialog boxes in fullscreen mode causing permanent framerate drops. Sea Manky 2 4,514 Aug 7, 2007 06:20 AM
Last Post: Sea Manky