Jump to content
  • Advertisement

Archived

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

GUI Help

This topic is 5858 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

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
Advertisement
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

  • 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!