cancel
Showing results for 
Search instead for 
Did you mean: 

WebCam Stream on the Oculus

Anonymous
Not applicable
Hello,

currently I'm trying to show a stream from 2 webcams on the oculus. Unfortunately I have no idea how to render the images. Actually it is the first time I'm working with such topics. I will show now what I have done so far.

First of all the main part. Most of the code is combined from different demos an d examples. Does it work that way?
#define GLEW_STATIC
#include <GL/glew.h>
#include <OVR.h>
#include <OVR_CAPI.h>
#include <OVR_CAPI_GL.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <GLFW/glfw3.h>
#include <GLFW\glfw3native.h>

#if defined(_WIN32)
#include <Windows.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#endif


using namespace std;

ovrHmd HMD; // The handle of the headset
ovrEyeRenderDesc EyeRenderDesc[2]; // Description of the VR.
ovrRecti EyeRenderViewport[2]; // Useful to remember when varying resolution


int main()
{
// Initialize LibOVR and the Rift
ovr_Initialize();
HMD = ovrHmd_Create(0);
if (!HMD)
{
std::cout << "Oculus Rift not detected. Creating virtual HMD" << endl;
HMD = ovrHmd_CreateDebug(ovrHmdType::ovrHmd_DK1);
}
if (HMD->ProductName[0] == '\0')
std::cout << "Oculus Rift not detected." << endl;


//--------Setup Window-----------------
//initialisiere glfw
glfwInit();

//konfiguriere glfw (immer gleich)
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

//die größe des Fensters ist nicht änderbar
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);


//erzeuge ein Fenster
GLFWmonitor* l_Monitor;
int l_Count;
GLFWmonitor** l_Monitors = glfwGetMonitors(&l_Count);
switch (l_Count)
{
case 0:
printf("No monitors found, exiting...\n");
exit(EXIT_FAILURE);
break;
case 1:
printf("Two monitors expected, found only one, using primary...\n");
l_Monitor = glfwGetPrimaryMonitor();
break;
case 2:
printf("Two monitors found, using second monitor...\n");
l_Monitor = l_Monitors[1];
break;
default:
printf("More than two monitors found, using second monitor...\n");
l_Monitor = l_Monitors[1];
}

GLFWwindow* window = glfwCreateWindow(HMD->Resolution.w, HMD->Resolution.h, "OpenGL", l_Monitor, nullptr); // windowed

// Check if window creation was succesfull...
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}

//make openGL context
glfwMakeContextCurrent(window);

//nötig. erlaubt die anpassung an unterschiedliche Systeme
glewExperimental = GL_TRUE;
glewInit();


//only in direct mode relevant
//ovrHmd_AttachToWindow(HMD, glfwGetWin32Window(window) , NULL, NULL);
ovrHmd_SetEnabledCaps(HMD, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);


//-------------------------------------------
//initialize Tracking
ovrHmd_ConfigureTracking(HMD, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection |
ovrTrackingCap_Position, 0);


//-------------------------------------------

const int backBufferMultisample = 1;
// Configure OpenGL.
ovrGLConfig cfg;
//memset(&cfg, 0, sizeof(cfg)); //clear Memory
cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
cfg.OGL.Header.Multisample = backBufferMultisample;
cfg.OGL.Header.BackBufferSize = OVR::Sizei(HMD->Resolution.w, HMD->Resolution.h);
cfg.OGL.Window = glfwGetWin32Window(window);
cfg.OGL.DC = GetDC(cfg.OGL.Window);
ovrBool isSuccessful = ovrHmd_ConfigureRendering(HMD, &cfg.Config, ovrDistortionCap_Chromatic |
ovrDistortionCap_TimeWarp |
ovrDistortionCap_Overdrive,
HMD->DefaultEyeFov, EyeRenderDesc);


if (!isSuccessful)
{
std::cout << "Impossible to configure rendering (" << isSuccessful<<")"<< std::endl;
return isSuccessful;
}

//-------------------------------------------
//Main loop
while (true)
{
// Here I've no idea what to do.


}

//Destroy stuff
ovrHmd_Destroy(HMD);
ovr_Shutdown();
return 0;
}



At the moment I am capturing from the webcams with openCV. I've also managed to get an openGL texture from the captured images (I've left the error handling):

cv::VideoCapture capture0(0); //Capture using any camera connected to your system
cv::VideoCapture capture1(1); //Capture using any camera connected to your system

cv::Mat frame;
capture0.read(frame); //Create image frames from capture
cv::Mat frame1;
capture1.read(frame1); //Create image frames from capture


GLuint texture;
glGenTextures(1,&texture);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, frame.size().width, frame.size().height, 0, GL_RGB, GL_UNSIGNED_BYTE, frame.data);


And now I've no idea what to do with the texture.

I know that this things won't work perfectly, but I would be reallly happy if there is any image on the rift. Can anyone help?

Please leave a comment if you dont' understand what i want or if you need more information.
1 REPLY 1
Still need help?

Did this answer your question? If it didn’t, use our search to find other topics or create your own and other members of the community will help out.

If you need an agent to help with your Meta device, please contact our store support team here.

Having trouble with a Facebook or Instagram account? The best place to go for help with those accounts is the Facebook Help Center or the Instagram Help Center. This community can't help with those accounts.

Check out some popular posts here:

Getting Help from the Meta Quest Community

Tips and Tricks: Charging your Meta Quest Headset

Tips and Tricks: Help with Pairing your Meta Quest

Trouble With Facebook/Instagram Accounts?