How can I determine if the OpenGL window is the active window? - c++

How can I determine if the OpenGL window is the active window?

You can not do it from the opengl, because only the window manager knows which window is active. The best you can do, is you activate it yourself (for example, in glut it is done with glutSetWindow)

OpenGL only deals with drawing stuff. Terms like "Window" "Active" or "Focused" are completely outside the scope of OpenGL. You need to consult your windowing system's functions for this (Win32, X11, or functions provided by a cross-plattform toolkit)

Related

render a qt overlay window over opengl child window

I am looking for some information about rendering child windows in specific about how OpenGL interop with GDI. The problem that I have is that I have basically is that I have two windows, first, the main windows are created in qt, and inside of qt, a child window is hosted that leverages an OpenGL renderer.
Now what I wanted to do is to host an overlay on top of my OpenGL window, so I use that to overlay the OpenGL window. The problem that I am having is that when I render with OpenGL, the OpenGL generated graphics seem to obscure the graphics area including and effectively undo the graphics composited by qt.
In the image below the blue area is the qt overlay, in that picture I'm using GDI (BeginPaint/EndPaint) so and the windows seem to interact fine. That is, window order seems correct, the client region is correct. The moment I start to render with Opengl the blue area gets replaced with whatever OpenGL renders.
What I did I basically created to create the overlay I created a second frameless, topmost QMainWindow, and once the platform HWND was initialized I reparent it. Basically I change the new windows parent to be the same parent of my OpenGL window.
What I believed this would do is that the every window, gets drawn separately and the desktop composition manager would make the final composition and basically avoiding the infamous airspace problem as documented by Microsoft in their WPF framework.
What I would like to know is what could cause these issues? At this point, I lack understanding why once i render with OpenGL the pixels by qt overlay are obscured, even though windows hierarchy should say make them composited. What could I do to accomplish what I want?
Mixing OpenGL and GDI drawing on a shared drawable (that also includes sibling / childwindows without the CS_OWNDC windowclass style flag) never was supported. That's not something about Qt, but simply how OpenGL and GDI interact.
But the more important issue is: Why the hell aren't you using the OpenGL support built right into Qt in the first place? Ever since Qt-5 – if available – uses OpenGL to draw everything (all the UI elements). Qt-5 makes it trivial to mix Qt stuff and OpenGL drawing.

In openGL, can I handle window resize without GLUT?

I am working on an openGL project. The application should handle window resize events and correctly adjust the aspect ratio accordingly. I've seen many solutions for window resize handling, but they all require GLUT. Is there a way that I can implement the window resize handling without using GLUT?
OpenGL does not know anything about windows, it just knows about a default framebuffer - sometimes called an window-system provided framebuffer or whatever. The default framebuffer can be a window, some output surface or even hardware overlay, or some off-screen resource (like pbuffers or some implementation and/or platform-specific stuff). The connection between an actual windows and a GL context is done via platform-specific GL binding APIs like egl (originated for mobile/embedded GLES, but nowadays also applicable for desktop GL), wgl (on Windows), glX on Unix X11 window system, and so on.
But managing the window is a topic completely outside of the realm of OpenGL.
Is there a way that I can implement the window resize handling without using GLUT?
Yes, GLUT is just a (very outdated!) cross-plattform wrapper around those platform-specifc APIs mentioned before. You can always directly implement all that stuff using the native APIs of your platform. Or you can use some other wrapper API or windowing toolkit with OpenGL support (like GLFW, SDL, Qt, gtk, wxWindows, whatever).

How are opengl menus that go outside of the window implemented?

I was looking at how sometimes when you right click, the menu goes outside of the window.
Is this implemented with a separate window? If so, how can I get this functionality. I am trying to use GLFW, but I understand if it isn't possible.
Currently I am on windows, but I like keeping my options open, which is why GLFW would be preferable.
I noticed that GLUT has such a feature. If you are confused to what I am looking at then look at that.
Thanks for any help!!
Overlapping menus (in MS Windows) have to be implemented as a new top-level window, you would have a new OpenGL rendering context and draw the menu in that space - yes, it's a fair bit of work all for the edge-case of a menu overspilling the parent window,
However this isn't often a problem in OpenGL programming because if you're working on a full-screen game then the menu will always be displayed within the main window, and even if it isn't a full-screen a game your users really won't notice them as games tend to use different UI concepts like radial-menus which wouldn't overspill the parent window.
Or if you're working on a non-game title, chances are it isn't full-screen and is going to be an OpenGL rendering area within a larger application that is rendered using a native UI toolkit (e.g. 3ds Max, AutoCAD, etc), in which case no problem: just use native menus.
You can, of course, use native menus in an OpenGL application anyway, provided you do the necessary plumbing for native window messages.

Overlaying edit box control over OpenGL pane

I have a large OpenGL canvas in a Visual C++ MFC application. An edit box control sits over the OpenGL canvas. However, whenever the OpenGL canvas is redrawn, it obliterates the part of the edit box which sits above it, ignoring the specified window Z-order. How can I prevent this?
You don't.
Having other windows interact with an OpenGL window is not a good idea. They don't interact well; it's best to keep child windows clear of OpenGL windows.

A way to return control to Windows when window is not the focus OpenGL - C++

I was wondering if there was an OpenGL command to return control to Windows when the window the rendering is happening in is no longer the focus. As it stands, the mouse is constantly moved to the center of the screen even when it is not the focus.
Any way around this?
Thanks!
OpenGL is a rendering API; it does not have commands that deal with the underlying windowing system. WGL, GLX, and Apples AGL do that sort of thing. And even those APIs don't deal with mouse movement.
If the mouse is being forced to the center of the screen by your application, then it is probably due to some other code that you are using. Many of the common tools for creating OpenGL windows (FreeGLUT, GLFW, Qt, wxWidgets, etc) have commands for capturing the mouse and affecting its position. You will need to check your code and the documentation of whatever software you're using to interface with your window to see where the problem lies.
For windows, make sure you're setting mouse position if windows is active.
if(getactivewindow() == this->hwnd)
setmousepos()
This is probably the issue.