I’m working on an OpenGL library that will allow a user to create a primary OpenGL window and then create child windows inside that window for use in games and such, but I am not sure whatt he best method to go about this is. I wanted some advice on the topic because I may want to port this project from Win32/Win64 to Linux/X eventually and would prefer to stay away from subclassing Windows forms. If I have to subclass the Windows forms and simply check for which OS the library is compiling on, so be it, but I would prefer not to go down this road.
I was thinking about creating a class (all of this is being done in C++) for child windows that would specify location, width, height, text, image, etc and just pass mouse-clicks to the library and let it decide what button the clicks are within and handling them, but this may not be the fastest way. However, this method would also bring forth another problem or possible solution depending on how you look at it. There would be no messages passed through Windows/Linux when a button is pressed since the library is handling it. This would allow the library to send private messages to the main module and such, and allow the main module to process them.
So, ideas or suggestions?
An (unmaintained) OpenGL GUI library that seem to work in the way you described :
I implemented own MVC (Model-View-Controller) framework for OpenGL GUI application. I use only Windows APIs, without MFC nor .NET.
[EDIT] And, it currently supports 9 frequently used controls: Button, RadioButton, CheckBox, TextBox, EditBox, ListBox, TrackBar, ComboBox and TreeView. [/EDIT]
Take a look:
I don’t want to use somebody else’s library either. I am doing this both to learn and to create my own personal library because if I make something useful with it in the future and decide to sell it, I need it to be my code. That may never happen, but it could and I want to be prepared.
I will look over the information provided in the second link when I get home because it does look informative and may help me. Still, anybody with information on doing this without external libraries, please share it.
For any useful UI system the rendering code will be very minimal. The power comes from the event system, layout engine, and customizability.
Sure, you’ll use OpenGL to transform from screen coordinates to widget coordinates and draw pretty buttons but that’s it. Broaden your search criteria to include how to create a UI system. You should be able to find many examples of how various systems defined their class hierarchies, rendering contexts, and metadata associated with those various classes.
There is definitely no “best way” to accomplish this.