Archived

This topic is now archived and is closed to further replies.

Ed Johnson

GUI Help

Recommended Posts

ok i''m trying to impliment a gui (graphical user interface) to my game.... i got a pic with transparency that i want to be in the bottom-right corner of the screen. BUT, i just want it to stay there, and not move around (use masking right?) could anyone help?

Share this post


Link to post
Share on other sites
Here's how I do it:

      
void CScreen::enable2D()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho (0.0, sizex, 0.0, sizey, 0.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_ENABLE_BIT);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
}


void CScreen::disable2D()
{
glDepthMask(GL_TRUE);

glPopAttrib();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}



enable2D sets up a 2D projection, allowing you to draw to the screen, specifying vertices by actual screen coordinates. It disables lighting and depth testing too.

disable2D reverts to the old settings.

sizex and sizey are the screen resolution.
____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on May 4, 2002 8:18:44 PM]

Share this post


Link to post
Share on other sites
There are basically two ways you can do this. There''re probably more, but whatever. First, you can load an image as a texture (dimensions have to be powers of two like any texture), and draw it as a quad on the screen. This is how the NeHe tutorial (I believe it''s number 20) works. Second, you can load any size image into an image buffer, and use glDrawPixels() to draw it onto the screen. I like this method better personally, because button image dimensions aren''t always powers of two and they''re ugly when you stretch or shrink them. However, I occasionally get garbled up pixels from this function for some reason. A variation on both methods is to use masking, which is detailed in the NeHe tutorial.

Share this post


Link to post
Share on other sites
Personally I use a textOut function which alpha blends characters to the screen to do the text. For windows, I just draw black alpha-blended quads drawn over the background, and I draw any buttons using GL_LINES. I wouldn't use glDrawPixels, as it can be very slow on a lot of cards.

If you want more varied buttons, you could just have a button tileset texture and form the buttons by drawing quads. This would allow you to draw a button of any size you liked, without stretching the texture.

For example, your button::draw method could draw a button by drawing the tile of the left side of the button, then drawing the middle section tile, stretched to the desired size, then drawing the right section.

If the button had some sort of background skin you wanted to preserve you could use GL_REPEAT on the middle section, but you'd have to make sure the repeating image lined up.

Not sure what sort of components you want though, as you havent been very specific.

____________________________________________________________
www.elf-stone.com


[edited by - benjamin bunny on May 5, 2002 2:44:05 PM]

Share this post


Link to post
Share on other sites
benjamin bunny: in ur code up there, where do u put the draws? or where do u specify in ur GLDRAW that u want it projected and not 3d?

Share this post


Link to post
Share on other sites
Put it wherever you like. It doesn''t have to be in a screen class like I''ve done, I just find it intuitive that way. Just make sure you call enable2D before you draw your 2D stuff, and disable2D when you''re finished. As I said, do your 2D stuff after all the 3D drawing is done.

____________________________________________________________
www.elf-stone.com

Share this post


Link to post
Share on other sites
if you haven''t defined a class called CScreen then defining a function:

CScreen::someFunction()....

will cause an error. the CScreen:: means function of class CScreen. typically you define functions that way if you''re splitting your classes into .h and .cpp files.

you could either definte a class CScreen with those member functions or just drop the CScreen:: part and they''ll become normal non-class functions.

anyway, sniff out some basic C++ tutorials for more info. there''s also a really good article on splitting files between .h and .cpp files somewhere in the Articles & Resources section. trol around there for a while too.

-me

Share this post


Link to post
Share on other sites