diff --git a/Makefile b/Makefile index 09207d5..e42894c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ build: - CPATH=. g++ -Wall -lX11 -lglfw -lGL openvr/libopenvr_api.so src/*.cpp -o overlay + CPATH=. g++ -Wall -lX11 -lXrandr -lglfw -lGL openvr/libopenvr_api.so src/*.cpp -o overlay run: build ./overlay diff --git a/src/app.cpp b/src/app.cpp index 144252a..cb56b7e 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,6 +1,7 @@ #include "app.h" #include "panel.h" #include "util.h" +#include #include App::App() @@ -11,7 +12,21 @@ App::App() InitX11(); InitGLFW(); - _panels.push_back(Panel(this, 0, 0, 0, _root_width, _root_height)); + glGenTextures(1, &_gl_frame); + glBindTexture(GL_TEXTURE_2D, _gl_frame); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + int monitor_count; + XRRMonitorInfo *monitor_info = XRRGetMonitors(_xdisplay, _root_window, 1, &monitor_count); + printf("found %d monitors:\n", monitor_count); + + for (int i = 0; i < monitor_count; i++) + { + XRRMonitorInfo mon = monitor_info[i]; + printf("screen %d: pos(%d, %d) wh(%d, %d)\n", i, mon.x, mon.y, mon.width, mon.height); + + _panels.push_back(Panel(this, i, mon.x, mon.y, mon.width, mon.height)); + } } App::~App() @@ -65,6 +80,17 @@ void App::InitGLFW() void App::Update() { + auto frame = XGetImage( + _xdisplay, + _root_window, + 0, 0, + _root_width, _root_height, + AllPlanes, + ZPixmap); + glBindTexture(GL_TEXTURE_2D, _gl_frame); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _root_width, _root_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, frame->data); + XDestroyImage(frame); + for (auto &panel : _panels) { panel.Update(); diff --git a/src/app.h b/src/app.h index 10cd469..373a499 100644 --- a/src/app.h +++ b/src/app.h @@ -1,3 +1,4 @@ +#define GL_GLEXT_PROTOTYPES #include "util.h" #include #include @@ -25,6 +26,7 @@ class App Display *_xdisplay; Window _root_window; GLFWwindow *_gl_window; + GLuint _gl_frame; int _root_width; int _root_height; diff --git a/src/panel.cpp b/src/panel.cpp index 8e93e51..cfe0e27 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -2,7 +2,6 @@ #include "app.h" #include "util.h" -#include #include #include @@ -19,6 +18,11 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) _active_hand = -1; glGenTextures(1, &_gl_texture); glBindTexture(GL_TEXTURE_2D, _gl_texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGB, + _width, _height, 0, + GL_BGRA, GL_UNSIGNED_BYTE, 0); _texture.eColorSpace = vr::ColorSpace_Auto; _texture.eType = vr::TextureType_OpenGL; @@ -29,7 +33,7 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id); assert(overlay_create_err == 0); _app->vr_overlay->ShowOverlay(_id); - _app->vr_overlay->SetOverlayWidthInMeters(_id, 2.5f); + // _app->vr_overlay->SetOverlayWidthInMeters(_id, 2.5f); uint8_t col[4] = {20, 50, 50, 255}; _app->vr_overlay->SetOverlayRaw(_id, &col, 1, 1, 4); printf("Created overlay instance %d\n", _index); @@ -37,7 +41,9 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) // (flipping uv on y axis because opengl and xorg are opposite) vr::VRTextureBounds_t bounds{0, 1, 1, 0}; _app->vr_overlay->SetOverlayTextureBounds(_id, &bounds); - _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &DEFAULT_POSE); + vr::HmdMatrix34_t start_pose = DEFAULT_POSE; + start_pose.m[0][3] += index * 1.5f; + _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &start_pose); } } @@ -76,9 +82,12 @@ void Panel::Update() void Panel::Render() { - auto frame = XGetImage(_app->_xdisplay, _app->_root_window, _x, _y, _width, _height, AllPlanes, ZPixmap); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _width, _height, 0, GL_BGRA, GL_UNSIGNED_BYTE, frame->data); - XDestroyImage(frame); + glCopyImageSubData( + _app->_gl_frame, GL_TEXTURE_2D, 0, + _x, _y, 0, + _gl_texture, GL_TEXTURE_2D, 0, + 0, 0, 0, + _width, _height, 1); auto set_texture_err = _app->vr_overlay->SetOverlayTexture(_id, &_texture); assert(set_texture_err == 0); diff --git a/src/panel.h b/src/panel.h index 65c3e4f..7f80c00 100644 --- a/src/panel.h +++ b/src/panel.h @@ -1,3 +1,4 @@ +#define GL_GLEXT_PROTOTYPES #include "util.h" #include #include