I have seen a method in SFML called isOpen which checks if the window is open.
Is there any similar equivalent in openGL or GLUT which checks if the window is open?
OpenGL render to a framebuffer attached to an OpenGL rendering context. The rendering context may have been created from a window connecting the (default) framebuffer to the window, but this is out of scope for the OpenGL spec.
As for GLUT you can use glutSetWindow to set the window id you want to check whether or not it exist, and then do glutGetWindow. If it returns the window id previously set the window exist. If not, glutSetWindow obviously failed because the window does not exist.
Whether or not this is true seems implementation dependent, but I doubt anyone would be stupid enough to not implement error handling in such a trivial case.
Related
I was wondering if I can initialize glut in a window I made before in visual c++ , because I tried to initialize openGl using the pixel format descriptor and failed multiple times , so my question is how to initialize GLUT in a specific size in a large window
Because I want to put some buttons and text boxes near the glut viewport
By using (Free)GLUT, you have essentially given up control over the specifics of things like window creation. GLUT has no mechanism to "adopt" a window provided by the user.
So if you want to create the window yourself, you have to also have to manage it yourself, with all the OpenGL context creation stuff that entails.
I'm testing supporting multiple resolutions in an application using SDL2 with OpenGL. To create my "letterbox" functionality I set my glViewport to an appropriate value and everything works perfectly.
However, if I create my window with the SDL_WINDOW_ALLOW_HIGHDPI flag set, whenever I move my window (after receiving the SDL_WINDOWEVENT_MOVED event) SDL modifies the viewport to the full size of the window, which can be verified by calling SDL_GL_GetDrawableSize during the event.
If I do not set SDL_WINDOW_ALLOW_HIGHDPI when creating the window, the viewport is not reset. I do believe this to be a bug, but cannot find anything through the SDL bugzilla so I thought to ask if anyone has seen similar behavior.
You may need to have a retina MacBook Pro to experience this behavior.
Just do what you should be doing anyway: Always re-/set the viewport at the beginning of drawing each frame. As soon as you want to implement a HUD, use framebuffer objects or similar things you'll have to set the viewport (several times) for drawing each frame.
I can't seem to find an example of creating an OpenGL context off of an existing X11 Window. Every example I find creates a window that is already OpenGL ready by providing the necessary visual attributes (via glXChooseVisual or glXChooseFBConfig). What if I already have an existing window (referenced via Display* and Window) and want to change the Colormap and XVisualInfo for the Window for OpenGL rendering? Think ChoosePixelFormat and SetPixelFormat on Windows when creating an OpenGL context. Is this even possible in X11? Do I have to create a Window that's already ready for OpenGL?
I'm trying to create a fullscreen application using Win32 and OpenGL. I change the resolution using EnumDisplaySettings and ChangeDisplaySettings and the OpenGL functions work fine. On its WndProc I handle WM_ACTIVATEAPP and detect when the user switched focus to another window, then I minimize the application's window. When the window is maximized again, the window doesn't display properly at all. What could I include to make the application work even after minimizing?
From the question I cannot still say what you are missing and what you already have. Refer to the http://nehe.gamedev.net/. There is a section Opengl base code to setup a window in full screen and switch back to window mode. See if you can get something from there.
Occassionally I hit places where I'd want to get an OpenGL framebuffer object, but where I'm not interested about opening a window of any kind.
Is it possible to create an opengl context without attaching it to a window of any kind?
Yes! you can use the desktop window as the window passed to OpenGL- as long as you don't try to display anything on it ;)
Just Call GetDesktopWindow and pass the result as an argument when creating new OpenGL window.
http://www.opengl.org/wiki/Creating_an_OpenGL_Context
According to this Web page, WGL_ARB_create_context can be used to create a context without a window. I have not actually tried it myself. I used freeGLUT to create the context and then rendered off-screen to a framebuffer+renderbuffer. I exit the program without ever calling glutMainLoop. It is klugy, but it works for my purposes.
Yes, you can perform off-screen rendering with OpenGL, but the exact way to set it up is dependent on the operating system.
The closest you get to an OS independent way would be to use Mesa 3D, but then your off-screen rendering would not be hw accelerated.