mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-09 20:10:25 +01:00
separate overlays by screen
This commit is contained in:
parent
74d2c71c53
commit
54ea68da6b
5 changed files with 46 additions and 8 deletions
2
Makefile
2
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
|
||||
|
|
28
src/app.cpp
28
src/app.cpp
|
@ -1,6 +1,7 @@
|
|||
#include "app.h"
|
||||
#include "panel.h"
|
||||
#include "util.h"
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <cassert>
|
||||
|
||||
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();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#define GL_GLEXT_PROTOTYPES
|
||||
#include "util.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
@ -25,6 +26,7 @@ class App
|
|||
Display *_xdisplay;
|
||||
Window _root_window;
|
||||
GLFWwindow *_gl_window;
|
||||
GLuint _gl_frame;
|
||||
|
||||
int _root_width;
|
||||
int _root_height;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "app.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#define GL_GLEXT_PROTOTYPES
|
||||
#include "util.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <string>
|
||||
|
|
Loading…
Reference in a new issue