cancel
Showing results for 
Search instead for 
Did you mean: 

struggling with rendering on Oculus [sdk 0.7 / 0.8]

godjilla
Level 2
Hi. I'm an Oculus development beginner.

I use OpenGL to deal with Oculus and I could easily get HMD sensor variables but I had difficulties with rendering images on HMD.
What I tried were.
- Create a framebuffer and render images on a texture which is bound with the framebuffer. And blit it.
[when I display on viewport of PC (framebuffer 0) it worked but on Oculus it didn't).
- change 'tex->OGL.TexID with' id of texture where images are rendered.
-etc..

I failed every tries.. and now I'm in panic.

Of course I searched for example source codes but I couldn't find any codes that I needed.
(my OS is Windows10, and I needed sdk 0.7 or 0.8 codes)

Can i get any help?


Below is the source code I'm using.

- Source.cpp
#include "GlobalVariable.h"

void InitApp(){

//Generate a framebuffer
glEnable(GL_FRAMEBUFFER_SRGB);
FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName);
//Bind generated framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

//Generate a texture
glGenTextures(1, &RenderedTexture);
//Bind generated texture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, RenderedTexture);
//Set texparameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//Bind generated FRAMEBUFFER & TEXTURE
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, RenderedTexture, 0);
}

void hmdInit(){
result = ovr_Initialize(nullptr);
if (OVR_FAILURE(result)){
//return;
}
result = ovr_Create(&hmd, &luid);
if (OVR_FAILURE(result)){
ovr_Shutdown();
//return;
}
desc = ovr_GetHmdDesc(hmd);
resolution = desc.Resolution;

}
void hmdTexInit(){
recommenedTex0Size = ovr_GetFovTextureSize(hmd, ovrEye_Left, desc.DefaultEyeFov[0], 1.0f);
recommenedTex1Size = ovr_GetFovTextureSize(hmd, ovrEye_Right, desc.DefaultEyeFov[1], 1.0f);

EyeWidth = recommenedTex0Size.w;
EyeHeight = recommenedTex0Size.h;

}

void hmdSensorInit(){
//ovrResult ovr_ConfigureTracking(ovrHmd hmd, unsigned int requestedTrackingCaps, unsigned int requiredTrackingCaps);
//ovr_ConfigureTracking(session, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position,0);
//ts = ovr_GetTrackingState(session, ovr_GetTimeInSeconds());
if (ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked))
{

}
}
void hmdRenderInit(){
// Configure Stereo settings.

bufferSize.w = recommenedTex0Size.w + recommenedTex1Size.w;
bufferSize.h = recommenedTex0Size.h;


glEnable(GL_FRAMEBUFFER_SRGB);
glGenFramebuffers(1, &ovrFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, ovrFramebuffer);

pTextureSet0 = 0;
pTextureSet1 = 0;
if (ovr_CreateSwapTextureSetGL(hmd, GL_SRGB8_ALPHA8, bufferSize.w, bufferSize.h, &pTextureSet0) == ovrSuccess){
// Sample texture access:
tex0 = (ovrGLTexture*)&pTextureSet0->Textures[0];
glGenTextures(1, &(tex0->OGL.TexId));
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex0->OGL.TexId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

tex0->OGL.TexId = RenderedTexture;
//Bind generated FRAMEBUFFER & TEXTURE

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ovrFramebuffer, 0);
}
if (ovr_CreateSwapTextureSetGL(hmd, GL_SRGB8_ALPHA8, bufferSize.w, bufferSize.h, &pTextureSet1) == ovrSuccess){
tex1 = (ovrGLTexture*)&pTextureSet1->Textures[1];
glGenTextures(1, &(tex1->OGL.TexId));
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex1->OGL.TexId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

//tex1->OGL.TexId = RenderedTexture;
//Bind generated FRAMEBUFFER & TEXTURE
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, ovrFramebuffer, 0);
}


glGenTextures(1, &depthBuffID);
glBindTexture(GL_TEXTURE_2D, depthBuffID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
internalFormat = GL_DEPTH_COMPONENT24;
type = GL_UNSIGNED_INT;
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, bufferSize.w, bufferSize.h, 0, GL_DEPTH_COMPONENT, type, NULL);


// Initialize VR structures, filling out description.
desc = ovr_GetHmdDesc(hmd);
eyeRenderDesc[0] = ovr_GetRenderDesc(hmd, ovrEye_Left, desc.DefaultEyeFov[0]);
eyeRenderDesc[1] = ovr_GetRenderDesc(hmd, ovrEye_Right, desc.DefaultEyeFov[1]);
hmdToEyeViewOffset[0] = eyeRenderDesc[0].HmdToEyeViewOffset;
hmdToEyeViewOffset[1] = eyeRenderDesc[1].HmdToEyeViewOffset;

// Initialize our single full screen Fov layer.
layer.Header.Type = ovrLayerType_EyeFov;
layer.Header.Flags = 0;
layer.ColorTexture[0] = pTextureSet0;
layer.ColorTexture[1] = pTextureSet1;
layer.Fov[0] = eyeRenderDesc[0].Fov;
layer.Fov[1] = eyeRenderDesc[1].Fov;

layer.Viewport[0].Pos.x = 0;
layer.Viewport[0].Pos.y = 0;
layer.Viewport[0].Size.w = bufferSize.w / 2;
layer.Viewport[0].Size.h = bufferSize.h;

layer.Viewport[1].Pos.x = bufferSize.w / 2;
layer.Viewport[1].Pos.y = 0;
layer.Viewport[1].Size.w = bufferSize.w / 2;
layer.Viewport[1].Size.h = bufferSize.h;

viewOffset[0] = eyeRenderDesc[0].HmdToEyeViewOffset;
viewOffset[1] = eyeRenderDesc[1].HmdToEyeViewOffset;

viewScaleDesc.HmdSpaceToWorldScaleInMeters = 1.0f;
viewScaleDesc.HmdToEyeViewOffset[0] = viewOffset[0];
viewScaleDesc.HmdToEyeViewOffset[1] = viewOffset[1];

layers = &layer.Header;
// ld.RenderPose is updated later per frame.

// Enable the oculus capabilities:
layer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft;


tex0->OGL.TexId = RenderedTexture;
tex0->OGL.Header.API = ovrRenderAPI_OpenGL;
tex0->OGL.Header.TextureSize = bufferSize;
tex0->Texture.Header.TextureSize = bufferSize;
tex0->Texture.Header.API = ovrRenderAPI_OpenGL;
tex1->OGL.TexId = RenderedTexture;
}


void Render(){
//Render on generated Framebuffer & Texture
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

glBindTexture(GL_TEXTURE_2D, RenderedTexture);
glClearColor(1, 1, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();


glBegin(GL_TRIANGLES);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-0.6f, -0.4f, 0.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(0.6f, -0.4f, 0.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(0.f, 0.6f, 0.f);
glEnd();


}
void TextureMapping(){

// release state
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0, 0, 0.5f, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBindTexture(GL_TEXTURE_2D, RenderedTexture);
glLoadIdentity();
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, EyeWidth, EyeHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glColor4f(1.f, 1.f, 1.f, 1.f);
glBegin(GL_QUADS);

glNormal3f(0, 0, 1.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-0.6f, -0.6f, 1.f);

glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.6f, -0.6f, 1.f);

glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.6f, 0.6f, 1.f);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.6f, 0.6f, 1.f);

glEnd();



}
void hmdRender(){

pTextureSet0->CurrentIndex = (pTextureSet0->CurrentIndex + 1) % pTextureSet0->TextureCount;
//Render on generated Framebuffer & Texture
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferName);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ovrFramebuffer);
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0->OGL.TexId, 0);
// Set its depth layer as our depth buffer
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex1->OGL.TexId, 0);
// Clear the frame buffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthBuffID, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

// Bind the left or right ZED image
glBindTexture(GL_TEXTURE_2D, tex0->OGL.TexId);

//glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, EyeWidth, EyeHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);


//displayMidpointSeconds = ovr_GetPredictedDisplayTime(hmd, 0);
hmdState = ovr_GetTrackingState(hmd, displayMidpointSeconds);
result = ovr_SubmitFrame(hmd, 0, nullptr, &layers, 1);

// specify source, destination drawing (sub)rectangles.


}
void ErrorCallback(int error, const char* description) {
std::cout << description << std::endl;
}
void main(){

hmdInit();
hmdSensorInit();
hmdTexInit();
GLFWwindow* window = NULL;

glfwSetErrorCallback(ErrorCallback);

if (!glfwInit())
exit(EXIT_FAILURE);

//hmdInit();
//hmdRenderInit();
window = glfwCreateWindow(EyeWidth, EyeHeight, "Tutorial 00: Test", NULL, NULL);
if (!window) {

glfwTerminate();
exit(EXIT_FAILURE);
}


glfwMakeContextCurrent(window);

glfwSwapInterval(0);
//glfwSetWindowSizeCallback(window, WindowSizeChangeCallback);

glewInit();
hmdRenderInit();
InitApp();
while (!glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);


Render();
TextureMapping();

hmdRender();



glfwPollEvents();


}


glfwDestroyWindow(window);


glfwTerminate();

return ;
}


-GlobalVariable.h
//header, library, etc
#define GLFW_DLL
#define GLFW_INCLUDE_GLU

#include "glew-1.13.0-win32\glew-1.13.0\include\GL\glew.h"
#include "glfw-3.1.2.bin.WIN32\glfw-3.1.2.bin.WIN32\include\GLFW\glfw3.h"
#include "OculusSDK\LibOVR\Include\OVR_CAPI_GL.h"

#include <gl/GL.h>
#include <gl/GLU.h>
#include <iostream>
#include <fstream>


#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "glfw3dll.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "LibOVR.lib")

//Variables
GLuint FramebufferName;
GLuint RenderedTexture;

GLuint ovrFramebuffer;

//OVR
ovrResult result;
ovrHmd hmd;
ovrGraphicsLuid luid;
ovrHmdDesc desc;
ovrSizei resolution;
ovrTrackingState ts;

double ftiming;
//eyes
int EyeWidth = 100;
int EyeHeight = 100;
ovrSizei recommenedTex0Size;
ovrSizei recommenedTex1Size;
ovrEyeRenderDesc eyeRenderDesc[2];
ovrVector3f hmdToEyeViewOffset[2];
ovrVector3f viewOffset[2];
ovrViewScaleDesc viewScaleDesc;

//ovr Texture
ovrSizei bufferSize;
ovrSwapTextureSet * pTextureSet0;
ovrSwapTextureSet * pTextureSet1;
ovrGLTexture* tex0;
ovrGLTexture* tex1;
ovrLayerEyeFov layer;
ovrLayerHeader* layers;

double displayMidpointSeconds;
ovrTrackingState hmdState;


GLuint depthBuffID;
GLenum internalFormat;
GLenum type;
9 REPLIES 9

joan
Level 4
Have you looked at OculusRoomTinyGL sample in the SDK? It's a good starting point.

You are not supposed to create a texture on your side and try to force it into Oculus texture set. You must use the texture created by the runtime and draw onto it.

There is a recent thread about this aspect here.

kojack
Volunteer Moderator
Volunteer Moderator
Yep, you can't modify the texture names in the texture set. The texture set it gives you is never used internally, it has it's own copy and kkeps using the original values, it's only there for you to read the texture id it made for you.
Author: Oculus Monitor,  Auto Oculus Touch,  Forum Dark Mode, Phantom Touch Remover,  X-Plane Fixer
Hardware: Threadripper 1950x, MSI Gaming Trio 2080TI, Asrock X399 Taich
Headsets: Wrap 1200VR, DK1, DK2, CV1, Rift-S, GearVR, Go, Quest, Quest 2, Reverb G2

Mars3D
Level 2
Here's my OpenGL Oculus class for 0.8 that might help

Oculus.cpp
#include "Oculus.h"

extern PFNGLLOADTRANSPOSEMATRIXFPROC glLoadTransposeMatrixf;

// Create oculus object (GL window must have been already created)
COculus::COculus()
{
glLoadTransposeMatrixf = (PFNGLLOADTRANSPOSEMATRIXFPROC)wglGetProcAddress("glLoadTransposeMatrixf");

}

bool COculus::Initialise()
{
ovrResult error;

error = ovr_Initialize(nullptr);
if (!OVR_SUCCESS(error)) {
return false;
}

ovrGraphicsLuid luid;
error = ovr_Create(&hmd, &luid);
if (!OVR_SUCCESS(error)) {
return false;
}

HmdDesc = ovr_GetHmdDesc(hmd);

error = ovr_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
if (!OVR_SUCCESS(error)) {
return false;
}

return true;
}

// Delete object
COculus::~COculus()
{
ovr_Destroy(hmd);
ovr_Shutdown();
}


bool COculus::CreateBuffers(int winX, int winY,float PixelScale)
{
ovrResult error;

//resolution = HmdDesc.Resolution;
resolution.w = winX;
resolution.h = winY;


// Make eye render buffers
for (int eye = 0; eye < 2; ++eye)
{
idealTextureSize[eye] = ovr_GetFovTextureSize(hmd, ovrEyeType(eye), HmdDesc.DefaultEyeFov[eye], PixelScale);
error = ovr_CreateSwapTextureSetGL(hmd, GL_SRGB8_ALPHA8, idealTextureSize[eye].w, idealTextureSize[eye].h, &TextureSet[eye]);
if (!OVR_SUCCESS(error)) {
return false;
}

for (int i = 0; i < TextureSet[eye]->TextureCount; ++i)
{
ovrGLTexture* tex = (ovrGLTexture*)&TextureSet[eye]->Textures[i];

glBindTexture(GL_TEXTURE_2D, tex->OGL.TexId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}

glGenFramebuffers(1, &fbID[eye]);

glGenTextures(1, &dbID[eye]);
glBindTexture(GL_TEXTURE_2D, dbID[eye]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

GLenum internalFormat = GL_DEPTH_COMPONENT24;
GLenum type = GL_UNSIGNED_INT;

glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, idealTextureSize[eye].w, idealTextureSize[eye].h, 0, GL_DEPTH_COMPONENT, type, NULL);

}

// Create mirror texture and an FBO used to copy mirror texture to back buffer
error = ovr_CreateMirrorTextureGL(hmd, GL_SRGB8_ALPHA8, resolution.w, resolution.h, reinterpret_cast<ovrTexture**>(&mirrorTexture));
if (!OVR_SUCCESS(error)) {
return false;
}


// Configure the mirror read buffer
glGenFramebuffers(1, &mirrorFBO);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mirrorFBO);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mirrorTexture->OGL.TexId, 0);
glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

EyeRenderDesc[0] = ovr_GetRenderDesc(hmd, ovrEye_Left, HmdDesc.DefaultEyeFov[0]);
EyeRenderDesc[1] = ovr_GetRenderDesc(hmd, ovrEye_Right, HmdDesc.DefaultEyeFov[1]);

return true;

}

void COculus::BeginFrame()
{
// Get eye poses, feeding in correct IPD offset
ViewOffset[0] = EyeRenderDesc[0].HmdToEyeViewOffset;
ViewOffset[1] = EyeRenderDesc[1].HmdToEyeViewOffset;

// Keeping sensorSampleTime as close to ovr_GetTrackingState as possible - fed into the layer
sensorSampleTime = ovr_GetTimeInSeconds();

ovrTrackingState hmdState = ovr_GetTrackingState(hmd, ovr_GetPredictedDisplayTime(hmd, 0), ovrTrue);

ovr_CalcEyePoses(hmdState.HeadPose.ThePose, ViewOffset, EyeRenderPose);
}




void COculus::BindFrameBuffer(int eye)
{
TextureSet[eye]->CurrentIndex = (TextureSet[eye]->CurrentIndex + 1) % TextureSet[eye]->TextureCount;

auto tex = reinterpret_cast<ovrGLTexture*>(&TextureSet[eye]->Textures[TextureSet[eye]->CurrentIndex]);
glBindFramebuffer(GL_FRAMEBUFFER, fbID[eye]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex->OGL.TexId, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, dbID[eye], 0);
}

void COculus::SetView(int eye, float nearPlane, float farPlane)
{
glViewport(0, 0, idealTextureSize[eye].w, idealTextureSize[eye].h);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_FRAMEBUFFER_SRGB);

ovrMatrix4f proj = ovrMatrix4f_Projection(HmdDesc.DefaultEyeFov[eye], nearPlane, farPlane, ovrProjection_RightHanded);

glMatrixMode(GL_PROJECTION);
glLoadTransposeMatrixf(proj.M[0]);
}

void COculus::UnbindFrameBuffer(int eye)
{
glBindFramebuffer(GL_FRAMEBUFFER, fbID[eye]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
}

void COculus::EndFrame(float scale)
{
// Set up positional data.
ovrViewScaleDesc viewScaleDesc;
viewScaleDesc.HmdSpaceToWorldScaleInMeters = scale;
viewScaleDesc.HmdToEyeViewOffset[0] = ViewOffset[0];
viewScaleDesc.HmdToEyeViewOffset[1] = ViewOffset[1];

ovrLayerEyeFov ld;
ld.Header.Type = ovrLayerType_EyeFov;
ld.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft; // Because OpenGL.

for (int eye = 0; eye < 2; ++eye)
{
ld.ColorTexture[eye] = TextureSet[eye];
ld.Viewport[eye].Pos.x = 0;
ld.Viewport[eye].Pos.y = 0;
ld.Viewport[eye].Size = idealTextureSize[eye];
ld.Fov[eye] = HmdDesc.DefaultEyeFov[eye];
ld.RenderPose[eye] = EyeRenderPose[eye];
ld.SensorSampleTime = sensorSampleTime;
}

ovrLayerHeader* layers = &ld.Header;
ovrResult result = ovr_SubmitFrame(hmd, 0, &viewScaleDesc, &layers, 1);

// Blit mirror texture to back buffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, mirrorFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

GLint w = mirrorTexture->OGL.Header.TextureSize.w;
GLint h = mirrorTexture->OGL.Header.TextureSize.h;

glBlitFramebuffer(0, h, w, 0, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);


}


void COculus::GetHeadTracking(double Q[4])
{
// Query the HMD for the current tracking state.
ovrTrackingState ts = ovr_GetTrackingState(hmd, ovr_GetPredictedDisplayTime(hmd, 0), ovrTrue);
if (ts.StatusFlags & (ovrStatus_OrientationTracked))
{
Posef pose = ts.HeadPose.ThePose;

Q[0]=pose.Rotation.w;
Q[1]=pose.Rotation.x;
Q[2]=pose.Rotation.y;
Q[3]=pose.Rotation.z;
}
}

void COculus::GetEulerAngles(float* yaw,float* pitch,float* roll)
{
// Query the HMD for the current tracking state.
ovrTrackingState ts = ovr_GetTrackingState(hmd, ovr_GetPredictedDisplayTime(hmd, 0), ovrTrue);
if (ts.StatusFlags & (ovrStatus_OrientationTracked))
{
Posef pose = ts.HeadPose.ThePose;

pose.Rotation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(yaw, pitch, roll);

}
}

void COculus::GetOffset(int eye,float* OffetX, float* OffetY, float* OffetZ)
{
*OffetX = EyeRenderDesc[eye].HmdToEyeViewOffset.x;
*OffetY = EyeRenderDesc[eye].HmdToEyeViewOffset.y;
*OffetZ = EyeRenderDesc[eye].HmdToEyeViewOffset.z;

}

void COculus::Recenter()
{
ovr_RecenterPose(hmd);
}


Oculus.h

#ifndef OCULUS_H
#define OCULUS_H

#define OVR_OS_WIN32

#include <GL/gl.h>

#include <OVR.h>
#include <OVR_CAPI_GL.h>

using namespace OVR;

class COculus
{

public:

COculus();
~COculus();

bool Initialise();
bool CreateBuffers(int winX, int winY, float PixelScale);

void BeginFrame();

void SetView(int eye, float near, float far);
void BindFrameBuffer(int eye);
void UnbindFrameBuffer(int eye);

void EndFrame(float scale);

void GetEulerAngles(float* yaw, float* pitch, float* roll);
void GetHeadTracking(double Q[4]);
void GetOffset(int eye, float* OffetX, float* OffetY, float* OffetZ);

void Recenter();

private:
ovrHmd hmd;
ovrHmdDesc HmdDesc;
ovrSwapTextureSet* TextureSet[2];
ovrVector3f ViewOffset[2];
ovrPosef EyeRenderPose[2];
double sensorSampleTime;
ovrSizei idealTextureSize[2];
ovrGLTexture* mirrorTexture;
ovrSizei resolution;
ovrEyeRenderDesc EyeRenderDesc[2];
GLuint fbID[2];
GLuint dbID[2];
GLuint mirrorFBO;

};

#endif


Pseudo code example of usage:

Initialise
CreateBuffers

for each frame
{
BeginFrame
for each eye
{
SetView
BindFrameBuffer
GetOffset
Render Your Scene using the offset
UnbindFrameBuffer
}
EndFrame
}

godjilla
Level 2
Thank you guys for advices.
I'll tell you with my progresses after i give tries on my work on Monday (in Korea)
Really thanks a lot.

godjilla
Level 2
"Mars3D" wrote:

Initialise
CreateBuffers

for each frame
{
BeginFrame
for each eye
{
SetView
BindFrameBuffer
GetOffset
Render Your Scene using the offset
UnbindFrameBuffer
}
EndFrame
}



Thanks a lot but I don't get it that how to use offset to render my scene.
What I did was trying to render a triangle.
void RenderScene(){

glColor4f(1.f, 1.f, 1.f, 1.f);
glBegin(GL_TRIANGLES);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-0.6f, -0.4f, 0.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(0.6f, -0.4f, 0.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(0.f, 0.6f, 0.f);
glEnd();
}

I just put the above code between the "BindFramebuffer" and "UnbindFramebuffer"
And I just got black void lonely scene.

Would you tell me with more detail?

godjilla
Level 2
"kojack" wrote:
Yep, you can't modify the texture names in the texture set. The texture set it gives you is never used internally, it has it's own copy and kkeps using the original values, it's only there for you to read the texture id it made for you.


Do you mean that texture ids are 'read only' ?
If so, How do I render on textures of Oculus??

godjilla
Level 2
"joan" wrote:
Have you looked at OculusRoomTinyGL sample in the SDK? It's a good starting point.

You are not supposed to create a texture on your side and try to force it into Oculus texture set. You must use the texture created by the runtime and draw onto it.

There is a recent thread about this aspect here.



'Texture created by the runtime' must be textures from 'ovr_CreateSwapTextureSetGL' .
I tried to draw a triangle on the texture but it doesn't appear.

Mars3D
Level 2
"godjilla" wrote:

I just put the above code between the "BindFramebuffer" and "UnbindFramebuffer"
And I just got black void lonely scene.

Would you tell me with more detail?

The offsets are what you need to translate your modelview matrix by.

This should work,


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-OffSetX, 0.0f, -6.0f);
glDisable(GL_TEXTURE_2D);

glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f(0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
glEnd();

godjilla
Level 2
"Mars3D" wrote:
"godjilla" wrote:

I just put the above code between the "BindFramebuffer" and "UnbindFramebuffer"
And I just got black void lonely scene.

Would you tell me with more detail?

The offsets are what you need to translate your modelview matrix by.

This should work,


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-OffSetX, 0.0f, -6.0f);
glDisable(GL_TEXTURE_2D);

glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f(0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
glEnd();




I love you dude.
Take my kiss ❤️