Jump to content
  • Advertisement


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


SImple GUI

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

Hi all, Ive got a program im working on almost done and at the moment its a console app. I want to make a really simple GUI for it. I have made a psp image for this. What I need it: - Just one screen with my psp image on - Be able to use the mouse, click the buttons on the image and have them run my commands (instead of space bar) - Have the buttons change when pressed Thats it I think. I can get the one screen by using one side of a square and putting it right next to the screen but not sure this is the best way. I heard its best to Ortho mode but have no idea how to use it even after looking a a couple of tutorials. The mouse is the other thing, is there anyway of doing seeing where it is pixel by pixel (not sure if this would work corrected though or be accurate). I am surprised that no one had made a simple tutorial to do this being as it must be a question is asked quite alot. Maybe there is one that I dont know about! Well if anyone can help let me know please Thanks

Share this post

Link to post
Share on other sites
Drawing GUIs is usually done by drawing textured rectangular polygons (quads) to the screen (as you said). glOrtho sets the projection matrix to a 2d projection. The projection matrix basically contains the perspective transformation, but since a GUI has no perspective (generally) glOrtho "removes" it.

You could use it like this;

glOrtho(0.0f, 4.0f, 0.0f, 3.0f, 0.0f, 1.0f);

// draw rectangular textured quads here
glTexCoord2f(tc1, tc2);
glVertex2f(x, y);
// etc...

The x coordinate goes from 0 (left) to 4 (right), the y coordinate goes from 0 (bottom) to top (3).

I included a glOrtho description for reference:

The glOrtho function multiplies the current matrix by an orthographic matrix.

void glOrtho(

GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble near,
GLdouble far


left, right

The coordinates for the left and right vertical clipping planes.

bottom, top

The coordinates for the bottom and top horizontal clipping planes.

near, far

The distances to the nearer and farther depth clipping planes. These distances are negative if the plane is to be behind the viewer.

I hope this helps

EDIT: I missed the mouse part

You need to get a hold of the mouse coordinates. There are various ways to do so and many are platform dependent. I'll assume Windows.

In the windows messaging loop, the giant switch statements, add this (make sure there are two global ints in your program called xPos and yPos):

// the mouse has moved; windows is telling you where to.
// this is in screen coordinates (pixels of window), counted from the upper left
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor

// the user clicked at (xPos, yPos)
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
// check which button got clicked

Just determine whether the user clicked on a botton or not... you should be able to continue from here. I suggest looking up the windows documentation on the above windows messages.

[ Galactic Conquest | Bananas | My dead site | www.sgi.com | Goegel ]

[edited by - Kurioes on April 20, 2004 5:19:26 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!