Is the use of OpenGL restricted to creating graphics intensive softwares? - opengl

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.

Related

How to Skin an Win32 Application

Win32 look nasty, how to make it look better by custom skins?
I mean something like Adobe products, iTunes, Autodesk 3dsmax and Softimage XSI, Windows media player, Blender, Comodo firewall, Winamp, Babylon client, and few download managers etc.;
there are many similar applications out there but I can't find any proper tutorial or guideline, it looks like secret recipe!
only -two- tutorials available online:
old and useless: http://www.codeproject.com/Articles/20497/Draw-Skin-Window-Using-Pure-Win32-API
only cover opaque background (and this is what I avoid, I need more about GUI components):
http://www.flipcode.com/archives/Win32_Window_Skinning.shtml
Is there any book or proper guideline to learn how to build skins for Win32api?
Edit: I accept David Rodríguez comment, down there ↓↓
I have done this before using C++ Builder. The approach I took was to create a form, set it to be borderless and color the entire form the same color. Then I set the form transparency to this color. I then add images to the form which create the desired skin.
I'm sure this can all be done through standard win APIs, but I can't describe (or advise) doing it solely through API calls.
The operating system handles "skinning" for you automatically.
In "classic" mode (or Windows 2000 and earlier versions), this gets you a, well classic-looking interface. The windows are drawn just like they always were since Windows 95. Presumably, this is what you are referring to when you say that "Win32 look nasty". However, you need to realize that many people like this look and specifically choose to enable it on their machines. [WARNING: Personal opinion coming up!] I'm one of those people, and judging from the screenshots that get posted here from developers' machines, I'm definitely not the only one.
Windows XP actually introducing the "skinning" or theming engine, which lives in a set of Windows DLLs. By explicitly linking to version 6 of ComCtl32.dll, your application would automatically get these visual effects. Some people said this version of Windows looked "Fisher-Price", while others were perfectly happy with the term "gaudy". The option was retained to allow the user to switch to the "classic" theme (as described above), if desired.
Windows Vista completely overhauled Windows's theming engine and introduced a new UI known as "Aero". This provides flashy-looking windows and controls, complete with transparency effects—that is, as long as your graphics card supports it. Again, by explicitly linking to version 6 of ComCtl32.dll, your application would automatically get all of these styles applied.
It's worth noting that through all of this, Microsoft has provided users with the ability to customize the colors (and fonts and other things) used in the user interface. For example, Aero defaults to blue. If you don't like blue, you can change it. I change my UI colors periodically for fun and to re-energize myself. If you can't read or don't like the font, you change it, too.
Thus, if you choose to do something different with your application, defining your own custom color palette and ignoring the options chosen by the user through the provided customization interface, your app is going to look broken and stick out like a sore thumb on the user's desktop. When designing a UI, the last thing you want to do is to be or look different.
In short, upgrade your computer to Windows Vista or later and enable the Aero interface if you want flashy. Don't override the user or try to custom draw all of your controls. You'll just end up with an application that is hard to use, doesn't work as expected, is a pain in the rear to maintain, and just generally looks worse than if you'd simply left it alone.

Is there some way to express OpenGL instructions in a language-independent way?

The title pretty much says it. I was thinking about making a simple video editor, and I was unsure about the "logistics" of various effects and filters and such. Let's say I want to make it possible for an external program to apply some effect to the image. Does it have to be an executed program necessarily, or can it simply be a set of OpenGL instructions that the video editor can parse, and essentially "pass along" to OpenGL. Technically, that would be a program, but it seems more elegant and standardized than making a full fledged secondary program just to apply an effect. Maybe there's a better way?
Edit: Thanks for the answers guys. Here's a follow up though: How do other video editors implement this? The reason I ask is because the answers seem to be rather negative on the above point, so I was wondering how it is done by professional applications.
Does it have to be an executed program necessarily, or can it simply be a set of OpenGL instructions that the video editor can parse, and essentially "pass along" to OpenGL.
There are several ways to approach the problem ("make video editor with ability to create custom effects").
Make your editor support plugins, and provide api for making new video effect plugins. Macromedia Director worked this way. New effect will have to be implemented as a plugin library (dll/.so, depending on your platform).
Embed scripting language with OpenGL bindings into your application for making video effects, provide basic functions for interacting with internal state of your application. This will allow faster development of effects, but performance will suffer greatly for certain operations. "Blender" (3d editor) works this way, Maya provides similar framework (I think). Basically, this is #1 but implemented as scripting language.
Make your editor load GLSL shaders. This will allow you to make some effects fairly quickly, but other than that it is not good idea - while GLSL has decent amount of "power" (functions/maths), GLSL alone won't allow you to make anything you want, because it won't be able to interact with your application at all (pure GLSL can't create textures, framebuffers, and so on, which will limit your ability to make something more interesting). Most likely you'll be only able to make some kind of filter, nothing more. #1 and #2 will give "power" to end user.
Implement node-based effect editor. I.e. there are several types of nodes user can drag around that represent certain operations, they have inputs/outputs and user can connect them. Blender 3D and UDK(Unreal Development Kit) have such feature. I think .kkreiger (site is down, google it) used similar technique to make 96kb 1st person shooter. This can be quite powerful, but programmers are very likely to hate dragging graphical entities around with mouse, unless you also provide the way to make such node graph via scripting language (AviSynth had something similar but not quite like that). This can be as powerful as #1 or #2, but will cost you extra development time.
Aside from that, there is no "language-independent" way to make effect. Either you have to use existing language to make effect plugin interact with your application, OR you have to make your own "language" to describe effect. The only language-independent way to deal with this is to hire a programmer and tell him what kind of effect you want. But then again, that requires natural language.
Let's say I want to make it possible for an external program to apply some effect to the image. Does it have to be an executed program necessarily, or can it simply be a set of OpenGL instructions that the video editor can parse, and essentially "pass along" to OpenGL.
Either thing works. However in the OpenGL standard itself there's no such thing like "OpenGL instructions" or "opcodes". But at least in X11 based systems with indirect GLX this is possible, because GLX actually defines opcodes. And it is possible for multiple X clients to operate on the same context if it is indirect. Unfortunately you won't have that option most of the time, as you probably want a direct context, because you may want OpenGL3 (for which not all operations have opcodes defines, which makes indirect impossible for OpenGL-3), or because you're not using GLX.
So the next option is, that you provide the other process with some kind of command/interpreter prompt for OpenGL. If you're lazy I suggest you just embedd a Python interpreter in your program, together with the Python OpenGL bindings. Those operate on whatever context that's currently active, allowing the other program to actually send some Python script to do its stuff.
And last but not least you could provide OpenGL through some RPC interface.
Or you provide some plugin system, where you load some DLL, which does the deed.
Sure, but it would be basically the equivalent of you creating your own language. You can accept OpenGL "instructions" from the user via some text interface (or if you want to somehow put something together as a GUI), then parse those "instructions", and the underlying implementation would execute those instructions in whatever language your application is written in.
The short answer is no. What you are looking for is a HCI guy's dream DSL which would describe presentation regardless of the underlying technology.
Probably not quite what you wanted, you might want to look at GLSL. GLSL is a C-like language that is compiled by the graphic card driver into native "graphic assembly language".

Popup Text Input Box in C++ with OpenGL

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.

What is the best approach to use openGL in the web?

I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class. The teacher liked the program and he requested me to somehow put it online so that instead of downloading the .exe I can just run it on the web browser. Kinda like java applets run on the browser.
The question is:
How if possible, can I display a C++/OpenGL program in a web browser?
I am thinking of moving to JOGL which is a java interpretation of OpenGL but I rather stay in C++ since I am more familiar with it.
Also is there any other better and easier 3D web base API that I can consider?
There is a lot activity recently with WebGL. It is a binding for Javascript to native OpenGL ES 2.0 implementations, designed as an extension of the canvas HTML5 element.
It is supported by the nightly builds of Firefox, Safari, Chrome and Opera.
Have a look at these tutorials, based on the well known NeHe OpenGL tutorials.
Several projects based on WebGL are emerging, most notably Scenegraphs APIs.
From Indie teams: SceneJS, GLGE, SpiderGL.
From Google: the team behind O3D plugin is trying to implement a pure WebGL backend (source) for the project, so that no plugin will be necessary.
From W3C/Web3D: There is an ongoing discussion to include X3D as part of any HTML5 DOM tree, much like SVG in HTML4. The X3DOM project was born last year to support this idea. Now it is using WebGL as its render backend, and is version 1.0 since March 2010.
I'm almost sure that WebGL is the way to go in the near future. Mozilla/Google/Apple/Opera are promoting it, and if the technology works and there is sufficient customer/developer demand, maybe Microsoft will implement it on IE (let's hope that there will be no "WebDX"!).
AFAIK, there's only 3 options:
Java. it includes the whole OpenGL stack.
Google's Native Client (NaCL), essentially it's a plugin that let's you run executable x86 code. Just compile it and call it from HTML. Highly experimental, and nobody will have it already installed. Not sure if it gives you access to OpenGL libraries.
Canvas:3D. Another very experimental project. This is an accelerated 3D API accessible from JavaScript. AFAICT, it's only on experimental builds of Firefox.
I'd go for Java, if at all.
OTOH, if it's mostly vectorial works (without lots of textures and illumination/shadows), you might make it work on SVG simply by projecting your vectors from 3D to 2D. In that case, you can achieve cross-browser compatibility using SVGWeb, it's a simple JavaScript library that allows you to transparently use either the browser's native SVG support or a Flash-based SVG renderer.
Do you really have the time to rewrite it? I thought students were meant to be too busy for non-essential assignment work.
But if you really want to do it, perhaps a preview of it running as a flash movie is the easiest way. Then it's just a matter of doing that and you could provide a download link to the real application if people are interested.
Outside of Java, in-browser OpenGL is really in its infancy. Google's launched a really cool API and plugin for it though. It's called O3D:
http://code.google.com/apis/o3d/
Article about the overall initiative:
http://www.macworld.com/article/142079/2009/08/webgl.html
It's not OpenGL, but the Web3D Consortium's X3D specification may be of interest.
Another solution is to use Emscripten (a source-to-source compiler).
Emscripten supports C/C++ and OpenGL and will translate the source into html/JavaScript.
To use Emscripten you will need to use SDL as a platform abstraction layer (for getting an OpenGL context as well as loading images).
Emscripten is currently being used in Unreal Engine and will also be used in the Unity 5 engine.
Read more about the project here:
https://github.com/kripken/emscripten
Two approaches:
Switch to Java. However, your application will suffer from a loss of performance as a trade off for portability. But since Java is everywhere, this approach ensures that your code can be executed in most browsers.
Use ActiveX, which allows you to run native binary code for Microsoft Windows. This is not recommended in production because activeX is well known as a potential security hole, but since your lecturer is the one viewing it, security doesn't seem to be a big deal. This is applicable for Microsoft platform (Windows+IE) only.

Simple Frameworks for Displaying Bitmaps and Handling Button Presses

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.