GUI Help

Started by
11 comments, last by Ed Johnson 21 years, 11 months ago
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?
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]

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

where do i write the gui info? ect the boxes and all that stuff



bump
Write it on the screen. I recommend using a marker pen for this.

____________________________________________________________
www.elf-stone.com

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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.
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]

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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?
At the end of my main drawing function, after all the 3D stuff has been drawn, I do this:


screen->enable2D();
...draw 2D stuff
screen->disable2D();


____________________________________________________________
www.elf-stone.com

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

ok ill try... hopefully it will work :-/
is there any specific place to put the ortho projection thing?


bump

This topic is closed to new replies.

Advertisement