Skip to main content
GameDev.net gamedev.net
🔒 Locked

user interfaces

Started by cragwolf Jan 20, 2005 at 6:51 PM 11 replies 2k views
Original Post
cragwolf
cragwolf
I would like to create a 2D user interface for my 3D opengl scene. At this stage, I'm thinking a panel on the right hand edge of the screen, say 200 pixels wide, and a panel along the bottom of the screen, say 150 pixels high. I think I'll use glOrtho projection for these panels, but I'm not sure how to draw them on screen. Two possible ideas: 1) Draw two quads, each representing a panel. OK, but I want the panels to look good, so they'll need to have a nice texture. But square textures and rectangular quads (one of whose dimensions might change depending on which resolution the user chooses) don't go together so nicely, especially when you want a nice border around the panel. 2) Use glDrawPixels. I'll have better control of what goes on the screen (guess I won't need glOrtho in this case) but what about the speed of this function? Any comments? Any other ideas about how to do a simple 2D user interface in OpenGL?
jake_Ghost
jake_Ghost
well its not to hard if you dont have to many animated backgrounds and special effects. The easist way to do it would to just the quads. Its not hard to draw good looking buttons with photoshop CS, or elements, then simulate a button being pressed. Or doing mouseover and stuff like that. You could make a professional looking interface with little amount of hasel. Ive only been using openGL for about 4 months and i have a interface similar to most blizzard interfaces. I have an animated background with animated buttons, sounds, and some flare effects. I hope this has helped!

Jake
_John_Galt_
_John_Galt_
I guess u want to draw a transparent panel .. on the right top right. . u wud want to draw it in SCREEN COORDINATES .. as opposed to 3D world Coordinates .. what u cud do is ..
0) Draw ur 3D scene as u r doin it now
0.1) Enable Blending for transparency
1)push the VIEWPORT_BIT and all mATRICES
2)define a new viewport at the location u want (top , right)
3)Set it up 4 2D drawing .. gluOrtho2D
4)put the quad .. textured quad whatever
5)pop the viewport bit and the MAtrices

let me know if this works

You can use the same method for the TWP panels at the bottom and the right
Solias
Solias
You can also pack several of your rectangular images into one square texture, then just use the texture coords to put the right part of the texture on each quad. This may help you cut down on wasted space in your texture.
X-0ut
X-0ut
My GUI

Ok it doesnt look like much, snes style kinda.
It does the job well though, simply cteated in ortho with a textureless quad & lines.
Jovan
Jovan
How would i go about detecting if a person has clicked their mouse on a button? (using X and Y coordinates, non GLUT/GUI question)
Samith
Samith
Quote:
Original post by X-0ut
[nice image]
Ok it doesnt look like much, snes style kinda.
It does the job well though, simply cteated in ortho with a textureless quad & lines.


I like interfaces like that the best. Textureless line/quad windows are always my favorite.

If you do need to have textures though, I would suggest packing different parts of the texture into a square texture file, then just using correct texture coordinates to draw borders and stuff.
X-0ut
X-0ut
Jovan: firstly you would need to map the mouse coordinates to the gui coordinates.
The test is then a simple point in box test.
_John_Galt_
_John_Galt_
was my suggestion on the creating diff viewports wrong .. please let me know .. someone
X-0ut
X-0ut
Sure you could do it that way.
I prefer to just go ortho and scale the coordinates in the 0-1 range, rather than working with different resolutions though.
But hey, whatever works.
_John_Galt_
_John_Galt_
i cud nt understand what u mean by goin ortho .. .do u mean using glOrtho ?? but if that is the case then the scene will occupy the whole screen rite ?? mind telling me a but more >> please
X-0ut
X-0ut
I mean using an orthographic projection, how you get there is unimportant be it glOrtho, glu, your own matrices -whatever.
Anyway, you draw your scene first in the required projection, then alter for the gui (just so you know you can alter the projection as many times as you like in a frame).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.