I am trying to create a simple popup box that appears when my C++ program starts that will allow the user to enter the width, height, and length of a cube that will then be displayed in a separate window. I have been searching for a very long time, and I have yet to find a solution that will allow me to do this. Can this be done using C++, OpenGL, and GLUT? Or do I need another library to allow me to do this.
Thank you.
Jordan
Edit: I am programming a cross-platform program and cannot use Win32 to accomplish this, nor any other Window-specific function.
What are you are looking for is a graphical user interface.
There are many libraries available that interface with various input methods (for keyboard and mouse) and provide graphical output. Each one has it's own model.
There are various models, but the most common one is hierarchical.
If you are looking for a learning experience, I suggest you do some Googling on how to make your own GUI.
If you are simply looking for a convenient library that does the hard-yards for you, I strongly recommended AntTweakBar:
AntTweakBar is a small and easy-to-use C/C++ library that allows programmers to quickly add a light and intuitive graphical user interface into graphic applications based on OpenGL, DirectX 9, DirectX 10 or DirectX 11 to interactively tweak parameters on-screen....AntTweakBar works with GNU/Linux, Windows and OSX
It was designed not as a monolithic batteries-included do-all library (such as Qt, another alternative), but as a simple and lightweight tweaking interface (hence the name).
There are several examples available and it's API is quite simple, so it should be reasonably easy to pick up.
There's also GWEN. It is not a well known library, but I find it extremely versatile and easy to use.
Facts- Coded in C++- Fully Namespaced- All standard window controls- Behaves like you'd expect- Lightweight (No XML readers, no font loaders/renderers, no texture loaders - your engine should be doing all this stuff!)- Easy to integrate (comes with renderers for Windows GDI, Allegro, OpenGL, DirectX and SFML)- Totally portable & cross platform- Doesn't need RTTI- Released under a "do whatever you want" MIT license.
Opinionated note: I prefer GLFW over GLUT. It provides a nicer model, and is still in active development (unlike GLUT which has not been updated in a significantly long time). At least use freeGLUT
You need to use another external gui library to do it. If you're doing it for windows, MFC is a good option. Or check library OpenGL User Interface Library.It's cross platform.
Here some libraries
Maybe this link helps you
Your statement saying that you wish to have a popup box implies your wish to use the underlying windowing system, regardless of the OS.
If you want to be cross-platform, there are quite a few libraries you can use that either emulate or actually use the underlying windowing system, such as wxWidgets.
If using such a library is not an option, you can always use the OpenGL window to draw text and emulate your popup yourself, but that's a bit more work, imo.
Related
Is there a way to draw figures in C++ like you do in HTML combined with JavaScript?
By drawing figures I mean the <canvas></canvas> function in HTML and [canvas name].fillRect function.
I'm trying to make a 2D brick breaker in C++
C++ does not have a graphic user interface (GUI) packed in the standard library so you cannot draw using the standard functions.
However GUI toolkits like: Wxwidgets, Tk, Qt and Gtk all support it. In addition most of them support 3d graphics and images as well. In the case of Gtk the GUI can be styled with CSS style-sheets. No JavaScript unfortunately.
You can also use the inbuilt GUI that comes loaded on the operating system you are using. For example under Windows you have the Win32API and under Linux GTK, but note that the Win32API is not cross platform and the default GTK on Linux may not be bleeding edge.
Also you can't use the html or JavaScript syntax in any of these GUI. Canvases would be specifically programmed in C++/C (or the language it is aimed at).
If you want a more html like approach and if your game is going to be Windows only, XAML may also be an option. It is possible to use it with C++.
Also it may be worth noting that Qt is no longer free.
Concisely, win32. It's hard to learn, but it comes with any version (AFAIK, at least 2107 community edition) of Microsoft Visual Studio.
OpenGL is great in creating UI (specially in games) and it is highly portable. Is it unusual that an ordinary (not graphically intensive) application uses OpenGL for its UI? And if not, why? Is it about performance or ease of use?
For example, an Apple developer can use ready to use buttons and sliders, etc provided by Apple; he can also create the UI using OpenGL. The second method makes the code more flexible and portable. Why people don't do this?
Does using OpenGL makes sense if portability is our goal?
There's a lot more to UI than graphics.
As one example fonts. Rendering Chinese, Japanese, Korean, Arabic, Thai in the right directions with the write strokes etc it a TON of work. There are whole teams dedicated to that topic at Microsoft, Google, Apple, Adobe and other companies. If you go straight to GL you're going to have to solve that problem yourself.
Another example, native controls. iOS users expect certain controls to work a certain way. Android users expect something different. For a game that's usually not a problem, games usually have a very unique UI. Apps on the other hand are generally expected to stick to the conventions of their target platform. Generally users get upset when the controls don't match their native platform. Using GL for your UI means you won't get the native controls.
Similarly text editing is a very platform specific feature. Is it drag to select, right click to select, hold to select? What keys go which way, how do they work? Is it Ctrl-V or ⌘-V. All of that is platform dependent as well. You can use the native text editing controls and have the problem solved or you can use GL and have to reproduce not only all the code to edit text but try to make it work the right way on each platform in each configuration. Does your GL text editor handle Japanese keyboards? German Keyboards? Does it handle Input Method Editors for CJK and others?
So, it's more a matter of the right tool for the right job. There are whole UI platforms written on top of GL. Before Metal OSX was probably one of them (or still is?) But if you skip that and build your UI directly on GL you'll end up having to implement all those in-between pieces.
Certainly GL might be the right way to go for certain non-game apps. Paper comes to mind as an app that could be 98% GL and therefore gain portablility. On the other hand Evernote is probably on the far other side. It needs to handle every language, different fonts, input for users with disabilities, etc. All of that is built into the OS, not GL.
Yes, what you suggest is possible. Just have a look at Blender. Blender implements its own UI using OpenGL, for the exact portability reasons you gave.
However there's a lot more to user interfaces than just getting things drawn to the screen. Event management, input handling, interoperability with other applications. All that depends on functions that are not covered by OpenGL.
But there are cross platform application framework libraries, like Qt. And the whole drawing stuff makes only a small portion of what those frameworks do.
One problem you run into when using OpenGL for drawing the GUI though is, that there's a huge variation on the OpenGL profiles supported by the systems out there. It can vary from a mere OpenGL-1.1 software fallback on a old Windows XP machine, over OpenGL-1.4 on Windows Vista machine with only the default drivers installed by the Windows setup, up to OpenGL-4.5 on the same machine once that user installs the proper drivers. And the way you use OpenGL-4.5 is largely incompatible to OpenGL-1.4.
For a UI toolkit written with a OpenGL backend this means that you must implement at least three codepaths: A OpenGL-1.1 variant that uses the fixed function pipeline and client side vertex arrays. A OpenGL-3 compatibility profile. And a OpenGL-4 core profile.
This much more work than just using the OS specific methods, which you have to use anyway to create the window and get user input with.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
There are tons of GUI libraries for C/C++, but very few of them are based on the idea that opengl is a rather multiplatform graphics library. Is there any big disadvantage on using this OpenGL for building my own minimal GUI in a portable application?
Blender is doing that, and it seems that it works well for it.
EDIT: The point of my question is not about using an external library or making my own. My main concern is about the use of libraries that use opengl as backend. Agar, CEGUI or Blender's GUI for instance.
Thanks.
Here's an oddball one that bit a large physics experiment I worked on: because an OpenGL GUI bypasses some of the usual graphics abstraction layers, it may defeat remote viewing applications.
In the particular instance I'm thinking of we wanted to allow remote shift operations over VNC. Everything worked fine except for the one program (which we only needed about once per hour, but we really needed) that used an OpenGL interface. We had to delay until a remote version of the OpenGL interface could be prepared.
You're losing the native platforms capabilities for accessibility. For example on Windows most controls provide information to screen readers or other tools supporting accessibility impaired users.
Basically unless you have a real reason to do this, you shouldn't.
Re-inventing the Wheel: Yeah, you'd be doing it. But I note OP used the word "minimal" in the problem statement, so assuming it really doesn't need to scale up to all that, it may be a small enough wheel as to not matter. The product I currently work on supports OpenGL on three platforms (Win, Mac, Linux) and we built all our own widgets (text boxes, buttons, dialogs). It's a lot of work but now that we've done it we own a huge chunk of our stack and don't have to debug into third party frameworks when things don't work as expected. It's nice having complete control of the experience. There's always something you want to do that a framework doesn't support. Like everything in our business, it is a trade-off and you just have to weigh your needs against your need to finish on time.
Portability: Yes, you will still have to write platform specific code to boot-strap everything. This will be difficult if you've not done it before as it requires you to understand all the target platforms.
Windows Drivers: We've found that graphics card manufacturers have much better support for DirectX on Windows than OpenGL, since that's what is required to get MSFT certification. Often low- to mid-range cards have bugs, missing functionality, or outright crashes in their OpenGL support.
With Qt 4.5 you can select if you want to use OpenGL as window renderer.
More info:
https://www.qt.io/blog/2008/10/22/so-long-and-thanks-for-the-blit
Read the comments to know about the problems about this.
The obvious one is that you're basically building the GUI elements yourself, instead of having a nice designed like for wxWidgets or Qt.
You cant just use opengl, you need a platform specific code to set up a window for opengl.
From the freely available opengl red book:
OpenGL is designed as a streamlined,
hardware-independent interface to be
implemented on many different hardware
platforms. To achieve these qualities,
no commands for performing windowing
tasks or obtaining user input are
included in OpenGL; instead, you must
work through whatever windowing system
controls the particular hardware
you're using.
There are multiplatform solutions for this like glut, qt, wxWidgets, ...
And if you have to use them anyway, why not use built in GUI elements. They also give you the opportunity to build your own, and make use of the framework to handle mouse/keyboard events and stuff.
If you want a GUI as in windows/button etc. Don't do it yourself. There a lot of free solutions for this, wxwidgets,qt or GTK. All have OpenGL support if you want a 3d window
Just a quick question.
I'm looking for a simple strip chart (aka. graphing) control similar to the windows task manager 'Performance' view. And have found a few, but they all rely on MFC or .NET :(
Am hoping that someone here might have or know where to get a simple strip chart Win32 control that is not MFC.
Thanks.
If you have to go the roll-your-own route look at the polyline GDI call. That can draw the entire line for you in one call.
I work on a system that draws charts with custom code (no 3rd party controls, all win32 GDI). It sounds really hard, but it isn't that bad.
A little math to map the points from your coordinate space to the device context, drawing gridlines/backgrounds, and Ployline. Done! ;)
Heck you can use GDI mapping modes to make the math easy (but I wouldn't).
If you have found a good MFC control, maybe your best approach would be to convert the code yourself to pure Win32 - MFC is a thin wrapper around the Win32 API after all. Out of interest, what is the name of the MFC control you found?
Few months ago I have also experienced the same issue: trying to find an existing implementation of a performance monitoring library, which looks similar to windows task manager. However because I couldn't find any existing library that works on multi-platforms (not dependent to MFC or .NET), to I decided to create my own library :-)
Today I just released the beta version of this library, and made it available as an open source project.
Check this out here: http://code.google.com/p/qw-performance-monitoring/
Let me know if this is useful. I am still doing some testing, to make sure that every features in this library work in Mac, Linux, and Windows. Once I am done with the testing, I will release the stable release. For the current time, enjoy using this beta version :-)
I don't think there is a standard one in the Win32 common controls library. You'll either have to use someone else's widget library, or roll your own using GDI to draw the graphs. It probably isn't too difficult to roll your own - just create a bitmap control, and set the image every time your data updates to a graph that you draw in memory.
Look at this amazing open source library: http://mctrl.sourceforge.net
We have a set of applications that basically display a bunch of bitmaps and text, then allow user to press "buttons" (certain bitmaps) that cause actions to occur.
We currently have these implemented using DirectX and a bunch of code to place the bitmaps and handle the button-presses. But we'd like to have the following features:
portable to Linux
some sort of "editor" that would allow us to lay out screens without hard-coding locations of elements in code
animation
we need to be able to overlay video
not resource intensive (these terminals don't have a lot of memory or CPU)
we're currently using C++, so management would prefer that, but other languages would be considered
We'd prefer a free, open-source solution, but would be willing to buy something if it is not too expensive. (We have a couple dozen developers, and tens of thousands of terminals deployed.)
We don't like the common GUI toolkits or widgets. We want something that has more of the look of a game than of a dialog box.
Any suggestions for off-the-shelf stuff we could use?
Maybe the way to go is something like Clutter or Allegro. If you check in this article at ArsTechnica what they are using Clutter for, you might get an idea how to use it. I don't know for sure if it works on Windows, but I'm pretty sure it does, considering it only depends on libraries that are supported under Windows.
You could try wxWidgets (it has wxBitmapButton) or try to implement your own solution using SDL for all of the graphics.
"We don't like the common GUI toolkits or widgets. We want something that has more of the look of a game than of a dialog box."
You realize that Trolltech's QT has a style sheet language for widgets? Take a look at their white paper, specifically page 60
http://trolltech.com/pdf/qt43-whitepaper-us.pdf
Going over your other requirements:
portable to Linux
Yes. Also supports Windows, Mac, and embedded environments.
some sort of "editor" that would allow us to lay out screens without hard-coding locations of elements in code
Qt's Designer is a very nice tool. I use it all the time.
animation
Qt supports this.
we need to be able to overlay video
Qt supports this.
not resource intensive (these terminals don't have a lot of memory or CPU)
This might be the fly in the ointment. You could check out Qt's embedded option. I've never used that myself.
we're currently using C++, so management would prefer that, but other languages would be considered
Qt is for C++ and works with all major compilers.
We'd prefer a free, open-source solution, but would be willing to buy something if it is not too expensive. (We have a couple dozen developers, and tens of thousands of terminals deployed.)
Qt has both open-source and closed source options.