How does OpenGL return a picture to X server?

I am following one of the OpenGL 3.3 tutorials. But outside of the tutorial, I have a goal to write a library that could replace Mesa in the created program.
The tutorial uses GLFW and GLEW to “simplify context creation”. Simplify… to who?
From here https://www.theseus.fi/bitstream/handle/10024/140206/Laaksonen_Jarno.pdf?sequence=1&isAllowed=y -
“It takes care of unneeded things like window control and setting up a functioning program depending on the operating system and allows the programmers to concentrate on what to render instead of how to render.”
I do not understand how the rendered picture goes from video card to framebuffer, and then, to the screen. But that’s important. However I already have a program that writes to the framebuffer without OpenGL, and it seems that I don’t need to know how it gets to the screen. I still need to know how OpenGL returns data, though.
If I would create the context by myself, I would eventually knew the functions that are responsible for its creation, and could to implement them. But the context creation is black-boxed by GLFW and GLEW. Even worse, I will have to implement all the functions these libraries require.
So, what do I have to do now?

[QUOTE=bckpkol;1291575]I am following one of the OpenGL 3.3 tutorials. But outside of the tutorial, I have a goal to write a library that could replace Mesa in the created program.
The tutorial uses GLFW and GLEW to “simplify context creation”. Simplify… to who?
[/QUOTE]
To the application programmer. Context-creation is platform-specific, so if you want to support multiple platforms you’d need to write separate code for each platform. Also, if you want to make use of certain features of later OpenGL versions you need to use context-creation functions which don’t exist in earlier versions. But if you want the program to still work with earlier versions, you can’t use the later functions until you’ve determined that they’re supported, and you can’t check the OpenGL version without creating a context. So you need to create a context, perform a version check, then (if you have a sufficiently recent version) create another context with the more recent functions.

[QUOTE=bckpkol;1291575]From here https://www.theseus.fi/bitstream/handle/10024/140206/Laaksonen_Jarno.pdf?sequence=1&isAllowed=y -
“It takes care of unneeded things like window control and setting up a functioning program depending on the operating system and allows the programmers to concentrate on what to render instead of how to render.”
I do not understand how the rendered picture goes from video card to framebuffer, and then, to the screen. But that’s important. However I already have a program that writes to the framebuffer without OpenGL, and it seems that I don’t need to know how it gets to the screen. I still need to know how OpenGL returns data, though.
[/QUOTE]
OpenGL doesn’t “return” data. The framebuffer is a region of video memory. The OpenGL library (typically) issues commands to the GPU, which writes to the framebuffer, and which also controls scan-out (reading the framebuffer and generating a video signal from it).

I say “typically” because the original versions of Mesa provided a client-side implementation of OpenGL which simply wrote to a framebuffer in system memory then copied its contents to the screen with (I believe) XPutImage. Later versions of Mesa added support for 3D-capable video hardware, and Mesa eventually became the basis for OpenGL support in the X server.

Both of those libraries are open-source, so you can just examine their source code if you want to know how to handle context creation (alternatively, you could look at the source code for GLUT, SDL, SFML, GTK, Qt or wxWidgets, which also have context-creation code).

Incidentally: you probably don’t need GLEW on X11, as libGL exports all of the functions from a given version of the API. GLEW is primarily for Windows, where opengl32.dll only exports the OpenGL 1.1 API; anything added later is only accessible via a function pointer obtained from the video driver via wglGetProcAddress(). The equivalent X11 function, glXGetProcAddress(), just uses dlsym() to retrieve the pointer from libGL; the main reason for using glXGetProcAddress() is to use functions without making them hard (load-time) dependencies.