what's the relationship between SDL and OpenGL? - 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.

Related

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

OpenVR. Rendering in OpenGL without SDL

Is this possible in nature? What role of SDL library in OpenVR API? Does it needed for OpenGL context or only for mirroring the stereo image to SDL window?
It is possible. If you don't use SDL, you'll have to create your rendering context and window by yourself. The whole code would be too long for this answer, but on Windows you could use functions like CreateWindowEx and wglCreateContext. OpenVR doesn't require anything different from a normal context setup, but you need to use a somewhat modern version of OpenGL (4.1 at least works for me).

Query about opengl, glut, glew

Is there not a simple sdk for opengl why there are glut or glew and what are the written using? Which one should I use? There are so many frameworks out there that it is so confusing? Why there isn't just one sdk for opengl?
why there are glut or glew and what are the written using?
GLUT, GLFW and similar frameworks exist, because the system level interfaces to create a window and a OpenGL context are extremely versatile in what they can do, but it also takes a lot of code, just to create a window and them some more to create the OpenGL context. …and then some lots more of code to also do things like UI event management and so on.
These system level APIs are that verbose, because on a system level, you don't want to pin down what you can and can not do with these APIs.
So the three calls
glutInitDisplayMode(…);
glutCreateWindow(…);
glutMainLoop();
encapsulate about 1.5k lines of code dealing with just the system. But then with GLUT you don't get nice buttons, menu bars and the likes. For that you'd use a different framework, like Qt, which has even more code, but uses the same system level APIs as GLUT does. Same goes for GLFW and so on.
GLEW we have, because OpenGL can be extended and the system level interface for extending it is again down for minimalism and flexibility.
Why there isn't just one sdk for opengl?
Because in the end OpenGL is a system level API and the "SDK" comes ready-to-use with your regular system default compiler.
If you want to, you can create OpenGL programs without GLEW, GLUT and so on. But it is tedious.

Hook SDL, SFML or GLFW into existing OpenGL application

I am working with an existing OpenGL library which needs to be augmented with other UI functions (better keyboard input, mouse handling, etc). I was hoping to use SDL, SFML or GLFW with the existing OpenGL API to facilitate this. Using any of these frameworks, is it possible to hook UI functions from any of these frameworks into an existing window, rather than a window directly created from these frameworks?
-The existing OpenGL window is already created by the library I'm forced to use.
-I'm aware of the SDL_WINDOW_FOREIGN bit set but am not sure how this is supposed to work.
-Is there a better strategy for simply detecting mouse/keyboard input?
The SDL 2.0 function SDL_CreateWindowFrom() can set up SDL for input and rendering from a given native window.
https://wiki.libsdl.org/SDL_CreateWindowFrom

Do Libraries like GLUT & GLFW have the same functionality as SDL?

I was watching this video about OpenGL 3 - https://www.youtube.com/watch?v=XMgfddy7S7Q
And while talking about libraries to work with OpenGL (at 3:00) he mentions GLFW, freeGLUT and GLUT to use to create the window.
But can they handle input and sound as well like SDL?
And if so should I be using SDL? Or is GLFW more tuned for making games specifically in OpenGL?
No, GLUT and GLFW are frameworks that manage OpenGL context creation and windowing (which includes input) mostly. GLUT has a few components that are actually designed to draw things, but by in large it is there to setup GL only.
SDL, on the other hand, includes sound which neither GLFW nor GLUT do but also includes utilities to load resources such as image files. It is a much more end-to-end solution, whereas GLFW and GLUT are only designed to facilitate rendering/windowing. To do the same thing using GLFW, you would need to throw in some libraries such as SOIL (or work directly with libpng, libjpeg, etc.) and also find an audio library.
You do not need any of these things to make a game in truth. I interact directly with OpenGL (WGL/GLX/CGL) on Windows, Linux and OS X in my work but the extra time necessary to debug and maintain each of these platforms at such a direct level can be a real nuisance. If writing extra code specific to each platform you run on is unappealing then you should definitely consider GLFW, etc.