How do i start my own OpenGL GUI?

Started by
6 comments, last by Janju 21 years, 8 months ago
How would i design a gui? How does this message queue thing work? What classes will i need? I an working on an startegy game, and i need imput on how to do my gui right!
Advertisement
heres a quick sample. no guarantee on it working, or being good. just ideas. I hope this helps.


class Button{
public:
//give it variables
float left,right,top,bottom;//relative to window
char *name;
//and a callback function
int (*fn)(void);
}

class Window{
public:
//give it variables
float left,right,top,bottom;
char *title;
int nButtons;//number of buttons
Button *buttons;//pointer to buttons in this window
//and functions like:
void Load(char* file);
void Draw();
}
Rodger
Still need more info on that message queue thing...

@robirt
Ok that helps a bit, but what's a call back function?

[edited by - Jonus on August 13, 2002 8:20:52 AM]
I have also been working on some GUI-Elements like Buttons and Scrollbars which are implemented with OpenGL. I can tell you how I have designed that things. First I have introduced a common Baseclass which i named GraphicObject. This class contains all attributes and methods every Graphical Object have. Then there are some specific basical Graphical-Objects Classes which are inherited from the GraphicObject-Class, like a simple Line or a Rectangle and so on. Then I introduce a Composite-Class which contains of many different GraphicObjects(Here I use the Composite-Pattern for Details see E.Gamma,... "Design-Patterns"). A button or another GUI-Element is a Composite of different GraphicObjects like lines, rectangles and so on. So I created a Button-Class which inherits the Composite-Class.
For the Message-queue thing I use the Chain of Responsibility-Pattern (also see E.Gamma, ... "Design-Patterns" for more Details). That means that every GUI-Element has a method like HandleEvent() which get the Input like Windows callback Function and inside this you can Handle every Event. Do this for every GUI-Element and even the Window-itself(The Window is a composite of other GUI-Elements). For setting-up the Messagequeue call in your Windows-Main Function the HandleEvent()-Functions of your Window(s) which delegates the Event to their Child-Objects.
This is one Idea how you can implement your GUI in OpenGL. It is not an easy things and maybe there exists easier Designs. Look at www.OpenGL.org there exists alrady some GUI-Interfaces for OpenGL perhaps to use such an Library would be easier as implementing your own GUI.
Good luck

Peter Gmeiner
Peter Gmeiner
a callback function is a function you set up to be called by another function, to answer both questions, the messages sent to you by your OS are usually handled by a callback function. In windows, when youre setting up your window class, you specify a function that will be called everytime you need to deal with a message you get from, and code that function accordingly. For a rundown on the whole thing, go to www.winprog.org and/or www.gametutorials.com
You might want to check out the concepts covered in the Developing a GUI with C++ and DirectX series here on Gamedev (DirectX is only for the graphics part, you can easily replace it with OpenGL).

EDIT: (You'll likely want to skip part 1)

[edited by - michalson on August 13, 2002 9:29:56 AM]
www.cfxweb.net/~projectfy/gui.php

hope that can help you,

Bruno
Thanks guys!

@PGmeiner
I will take a close look at the design patterns your taleked about!

The case study at the beginning of the book is very intressting too.

@digitec devil
I still don''t understand what a ''callback'' function is, but i guess i will make it without it.

They''re function pointers in c and virtul in c++, thats all i understand until now.

@Michalson
I will check it out, ... cool that i can program a bit dx ... and yes i skiped part 1 .

Bruno
I will take a look at his source, but i don''t think thats his stuff is what i am looking for.

This topic is closed to new replies.

Advertisement