Open ErskaConti opened 2 years ago
Hi, I'm not familiar with Conky, but if it has a Lua API and if it can interwork with OpenGL, it may be that it can already be used in conjunction with MoonGL.
Note that MoonGL (like OpenGL itself) does not provide means to create GLcontexts. One has to create a GLcontext using either the native OS API or libraries such as GLFW, GLUT, SDL, FLTK or the like, then make the context 'current', and use the OpenGL API to draw in it (or MoonGL to do it from Lua code). If Conky can create a GLcontext and make it current, then you should be able to use MoonGL on it, right away.
I'm unsure if Conky creates an actual GLcontext, or if Xlib does while creating the Conky-Window, and my searching for transferring/connecting Xlib-drawable to an GLcontext yielded no results.
I did throw your examples into the lua-file Conky loads and runs and it worked (created an additional window through moonGLFW). The only part lacking is using the already created window.
As for what Conky is, it's used to draw text onto the desktop (wallpaper it's a window) meant for System Monitoring... it includes lua as an optional avenue for more complex graphics through: load (which doFile()s a lua file) and has hooks for startup(), draw_pre() draw_post() and shutdown()... my idea would be to use OpenGL to skew graphs&text 'into' the background which isn't supported through 2D-rendering like Cairo provides.
As I wrote earlier, OpenGL (and thus MoonGL) operates in whatever GLcontext/window is current when you issue the GL calls. So if there is a current context it should draw there, otherwise it should raise an error or worse, a segment violation. Thus you should be able to check if Conky actually creates a GLcontext by executing gl.init() right after creating the Conky window, without creating additional windows with MoonGLFW or other libraries. If this fails (as I suspect) there is no GLcontext.
By the way, with a quick source I found these notes about Cairo and OpenGL: https://www.cairographics.org/OpenGL/ Maybe you can find in them some useful hints for what you are trying to do.
conky: llua_do_call: function conky_draw_post execution failed: /home/erska/.conky/Renderer/addThis.lua:33: glewInit error: Missing GL version
that's called after conky_window has been created, before conky draws it's text, also happens after.
so I would say no GLcontext, right?
notes about Cairo and OpenGL: https://www.cairographics.org/OpenGL/
These are about using Cairo in OpenGL, which isn't really a problem... my problem is kind of the reverse but not really (I want to replace cairo with opengl, tho drawing OpenGL onto a cairo surface would work (edit: as a solution acceptable to me), but does not seem to be included in these examples)
I also tried to add cairo and create those to check if cairo would apply a GLcontext for drawing; no luck.
conky: llua_do_call: function conky_draw_post execution failed: /home/erska/.conky/Renderer/addThis.lua:33: glewInit error: Missing GL version
that's called after conky_window has been created, before conky draws it's text, also happens after.
so I would say no GLcontext, right?
I'm afraid so.
As with Conky, I have almost no knowledge about Cairo so I'm afraid I cannot be of much help here. However, I don't think it's possible to draw OpenGL directly onto surfaces other than glcontexts. With a glcontext in place you can however render to texture, and read back the rendered texture, so if there is a way to draw a texture on a Cairo surface you may try this path.
thanks, damn I hoped you would simply go 'yea just create a glcontext for the window using this: ...'
Conky has an option to run Lua-scripts, and it provides the variable
conky_window
which containsdrawable
- Window's drawable (Xlib Drawable), requires Lua extras enabled at compile time.visual
- Window's visual (Xlib Visual), requires Lua extras enabled at compile time.display
- Window's display (Xlib Display), requires Lua extras enabled at compile time.which seem to be used for cairo through
Now I'm not at all experienced with this stuff, but I imagine it would be possible to create a GLcontext in a similar way, using the same variables provided...