OpenVR. Rendering in OpenGL without SDL - opengl

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

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.

Alternative to GLUT

GLUT is a very old framework for OpenGL, and there seems to be a lot of negative attitude towards it. I hear SDL is an alternative, though to my understanding it does not handle the 3d component of OpenGL. What is a good option (which preferably has good documentation so it is easily learnable) that can do what GLUT does and provide more functionality, eg. to make a complete 3d game? I prefer not to use pre-made game engines, I'd much rather build my own code from scratch.
orginal GLUT is very old and I would not recommend it. But the new version of it: http://freeglut.sourceforge.net/ is quite interesting framework. Is is as simple as GLUT but adds more features: mouse scroll, new geometry objects, etc, etc.
last version of this library is from January 2012
here is a useful link with several frameworks for opengl: http://www.opengl.org/resources/libraries/windowtoolkits/
If you want to make w "whole" project I suggest combining more libraries:
http://www.opengl.org/wiki/Related_toolkits_and_APIs#Context.2FWindow_Toolkits
http://glsdk.sourceforge.net/docs/html/index.html
SOIL for texture loading
If you are to use modern OpenGL GLFW is the best option out there to manage context, window creation, user input. The lib is very active with constant new releases.
Just wanted to add that my consideration to move from GLUT and from FREEGLUT was the lack of ability to define color, stencil, depth bits and MSAA samples for created context. GLFW allows you doing this.
SDL can create windows with OpenGL context (see the SDL_WINDOW_OPENGL window flag), so you can use the OpenGL functions. So can SFML, and probably Allegro too.
I personally recommend SFML, especially version 2 (which is in development), as I find it very easy to set-up and start using, both generally and for OpenGL.

WGL: possible to find offscreen context and render to window?

There is an interesting browser framework called Awesomium, which is basically a wrapper around the Chromium browser engine.
I'm interested in using it to redistribute WebGL-based games for the desktop. However Awesomium only supports rendering using a pixel buffer sent to the CPU, even though the WebGL context itself is based on a real hardware-accelerated OpenGL context. This is inefficient for real-time high-performance games and can kill the framerate on low-end machines.
Awesomium may eventually fix this, but it got me thinking: is it possible to search a process for an offscreen OpenGL context and render it directly to a window? This would avoid the inefficient rendering method, keeping rendering entirely on the GPU. I'm using a native C++ app on Windows, so presumably this will involve WGL specifics. Also since Chromium is a multithreaded browser engine it may involve finding an OpenGL context on a different thread or event a different process. Is it possible?
is it possible to search a process for an offscreen OpenGL context and render it directly to a window?
No, it it not possible. If the opengl context is created for the OS buffer, then it is not possible to redirect it to other buffer and other opengl context.
Maybe you can use shared opengl resources (if both opengl contexts are created using such option).

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"?