In openGL, can I handle window resize without GLUT? - opengl

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).

Related

Is there a performance difference in using an OpenGL window like GLFW or a surrounding window like GTK or SDL?

vlc has an impressive example showing how to integrate with gtk:
https://git.videolan.org/?p=vlc.git;a=blob;f=doc/libvlc/gtk_player.c
but we are using glfw and C++. If we were to create a wrapper window using a windowing toolkit like gtk, is there any performance penalty in terms of the OpenGL operating within it?
Is it possible to open a video window within the GTKGL component, or does OpenGL interfere with video even if it is not rendering?
If you pass the window handle to libvlc, I don't see why there would be performance differences.

SDL window management with OpenGL and DirectX

I'm porting a small graphics engine from DirectX 9 to OpenGL. The engine uses SDL (now ported to 2.0) to manage input and window creation.
I want to know how to correctly handle window events for both OpenGL and DirectX. I'm interested in these for Desktop platforms (linux, OSX and windows)
Window resolution change
Full screen to windowed / windowed to fullscreen handling
Alt+tab handling -
I've tried to search through the net but information is quite not focused in one place. I imagine many others faced the same problem before.
Are there any resources to read guidelines on that kind of handling for my engine?
Is it possible to handle resolution change without losing transfered resources to the renderer system in both OpenGL and DirectX?
Window resolution change
OpenGL itself requires no special treatment for this. Unfortunately SDL goes through a full window reinitialization, including the OpenGL context on a window size change, which means, that all OpenGL state objects (that is, textures, vertex buffers, shaders and so on) are lost.
This is however a limitation of SDL.
Personally I thus prefer GLFW for creating a OpenGL window and context. You can still use SDL for other things though (like audio, networking, image loading and such).
Full screen to windowed / windowed to fullscreen handling
The is effectively a window size change as well. See above.
Alt+tab handling -
OpenGL requires no special effort for this. Just minimize the window when Alt+Tab-ing out and stop the game loop. When the window gets restored just continue the game loop.

what's the relationship between SDL and OpenGL?

Anyone can tell me what's the relationship between SDL library and OpenGL library?
OpenGL is a graphics library that doesn't provide any feature in addition to drawing. It is neither able to embed an OpenGL view inside a window of any modern OS.
That's where SDL comes right into place and provides all the required functions needed to create an OpenGL window in a cross-platform manner in which you then draw by using OpenGL library itself. SDL also has a lot of facilities that are almost always necessary when working with games or graphical applications like timers, management of keyboard and mouse and whatever.
In any case you could use any other OpenGL wrapper like GLUT library or GLFW to achieve the same thing: creating an OpenGL view inside an application.

openGL context in console

I'd like to use certain functions of openGL, but nothing related to rendering visual content. Is there way to create it without ANY dependencies (not to windows, nor some package[SDL, SFML, GLUT])? Only libraries allowed are those without external libraries, just like GLEW which I use.
What you want to do is known in general as off-screen rendering. In theory it is possible perfectly well, however the practical implementation has a lot of caveats. Most importantly on all major high performance implementations: Even if no rendering window is visible you still need the graphics system running and being active and your program run in the environment of this graphics system.
On Windows the most straightforward way to go is creating invisible window, just a window you create with CreateWindowEx but not map with ShowWindow; you don't even need a event processing loop for that. In this window you create your OpenGL context as usual, but instead of rendering to the window framebuffer, you render to a Frame Buffer Object.
On X11/GLX it's even more straightforward: X11/GLX offers PBuffers without extensions (Windows has PBuffers, too, but for creating one you need a regular OpenGL context first). So on X11 you can create a PBuffer without a proxy window. The PBuffer iteself can be rendered to as off-screen buffer; Frame Buffer Object work in a PBuffer, as well, if the implementation supports them. Using a invisible window with a Frame Buffer Object, just like with Windows, works as well. Either way, with current drivers X11 must be active and the bound console, so you can not start an additional X server in the background and have your off-screen rendering happen there, but this is just a limitation of the drivers and not of X11, GLX or OpenGL.
Only libraries allowed are those without external libraries, just like GLEW which I use.
You can link GLEW statically to your program. If you're hardcore you can do extension loading manually, but why would you want to do that?
What is the lightest cross-platform library that can staticaly link and can create context.
How do you define "lightest?"
The two cross-platform libraries that do the least other than creating OpenGL windows are FreeGLUT and GLFW.
FreeGLUT has about a 5.2MB distribution (after unzipping), while GLFW has a 2.6MB distro. Does that make it "lighter"? FreeGLUT's compiled static library, in release mode under VS2008, is around 500KB; the one for GLFW under similar compilation is 120KB. Does that make it "lighter"?

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

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)