01-11-2015 03:29 AM
#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;
}
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);
01-14-2015 01:27 AM