Forum Discussion
ckoeber
12 years agoHonored Guest
Materials with OpenGL and Oculus Rift SDK with F.Buffers .
Hello,
So I have this weird issue with rendering to OpenGL and the Oculus Rift's SDK.
I can render fine without the Rift but with the Rift I get a blank black screen.
Now before, without materials, I load everything in just fine.
It's when I started loading in materials that I experienced this problem.
So is it something simple I am missing?
Thank you for your time.
I load materials in like this:
I bind Materials like this:
This is how I create the framebuffer and textures for the Oculus Rift:
So I have this weird issue with rendering to OpenGL and the Oculus Rift's SDK.
I can render fine without the Rift but with the Rift I get a blank black screen.
Now before, without materials, I load everything in just fine.
It's when I started loading in materials that I experienced this problem.
So is it something simple I am missing?
Thank you for your time.
I load materials in like this:
bool HighSpeedMaterialCache::loadTexture2D()
{
if (MaterialFile != "") {
FIBITMAP *loadedImage = NULL;
FREE_IMAGE_FORMAT CurrentFormat = FIF_UNKNOWN;
CurrentFormat = FreeImage_GetFileType(MaterialFile.c_str(), 0);
if (CurrentFormat == FIF_UNKNOWN) {
FREE_IMAGE_FORMAT CurrentFormat = FreeImage_GetFIFFromFilename(MaterialFile.c_str());
}
if (CurrentFormat == FIF_UNKNOWN) {
return false;
}
if (FreeImage_FIFSupportsReading(CurrentFormat)) {
loadedImage = FreeImage_Load(CurrentFormat, MaterialFile.c_str());
}
if (!loadedImage) {
return false;
}
BYTE* bytesDataPointer = FreeImage_GetBits(loadedImage);
WidthOfTexture = FreeImage_GetWidth(loadedImage);
HeightOfTexture = FreeImage_GetHeight(loadedImage);
BytesPerPixel = FreeImage_GetBPP(loadedImage);
if (WidthOfTexture == 0 || HeightOfTexture == 0 || BytesPerPixel == 0) {
return false;
}
glGenTextures(1, &TextureObject_ID); // section being edited by CKoeber to pull in material files
glBindTexture(GL_TEXTURE_2D, TextureObject_ID);
setFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP);
GLsizei iFormat = BytesPerPixel == 24 ? GL_BGR : BytesPerPixel == 8 ? GL_LUMINANCE : 0;
GLsizei iInternalFormat = BytesPerPixel == 24 ? GL_RGB : GL_DEPTH_COMPONENT;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
WidthOfTexture, HeightOfTexture, 0, iFormat,
GL_UNSIGNED_BYTE, bytesDataPointer);
glGenerateMipmap(GL_TEXTURE_2D);
FreeImage_Unload(loadedImage);
glGenSamplers(1, &TextureSamplerObject_ID);
HasMipsBeenGenerated = true;
return true;
} else {
return false;
}
}
I bind Materials like this:
glUniform1fv(CurrentOpenGLController->GetObjectHasMaterialFileID(), 1, &ObjectHasMaterial);
glActiveTexture(GL_TEXTURE0 + Materials[0].TextureUnit_ID);
glBindTexture(GL_TEXTURE_2D, Materials[0].TextureObject_ID);
glBindSampler(Materials[0].TextureUnit_ID, Materials[0].TextureSamplerObject_ID);
This is how I create the framebuffer and textures for the Oculus Rift:
MainRiftDevice = CurrentRiftDevice;
MainRiftDeviceDesc = CurrentRiftDeviceDesc;
IsRiftAvailable = true;
l_TextureSizeLeft = ovrHmd_GetFovTextureSize((*MainRiftDevice), ovrEye_Left, MainRiftDeviceDesc->DefaultEyeFov[ovrEye_Left], 1.0f);
l_TextureSizeRight = ovrHmd_GetFovTextureSize((*MainRiftDevice), ovrEye_Right, MainRiftDeviceDesc->DefaultEyeFov[ovrEye_Right], 1.0f);
l_TextureSize.w = l_TextureSizeLeft.w + l_TextureSizeRight.w;
l_TextureSize.h = (l_TextureSizeLeft.h>l_TextureSizeRight.h ? l_TextureSizeLeft.h : l_TextureSizeRight.h);
/*
Create Our FrameBuffer
*/
glGetIntegerv(GL_MAX_SAMPLES, &NumOfSamples);
glGenTextures(1, &g_MultiSampleTexture_ID);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, g_MultiSampleTexture_ID);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, NumOfSamples, GL_RGBA, l_TextureSize.w, l_TextureSize.h, false);
glGenFramebuffers(1, &g_MultiSampleFrameBufferObject_ID);
glBindFramebuffer(GL_FRAMEBUFFER, g_MultiSampleFrameBufferObject_ID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, g_MultiSampleTexture_ID, 0);
glGenRenderbuffers(1, &g_MultiSampleColorRenderBufferObject_ID);
glBindRenderbuffer(GL_RENDERBUFFER, g_MultiSampleColorRenderBufferObject_ID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, NumOfSamples, GL_RGBA, l_TextureSize.w, l_TextureSize.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, g_MultiSampleColorRenderBufferObject_ID);
glGenRenderbuffers(1, &g_MultiSampleDepthBufferObject_ID);
glBindRenderbuffer(GL_RENDERBUFFER, g_MultiSampleDepthBufferObject_ID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, NumOfSamples, GL_DEPTH24_STENCIL8, l_TextureSize.w, l_TextureSize.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_MultiSampleDepthBufferObject_ID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, g_MultiSampleDepthBufferObject_ID);
g_DrawBufferStatusCheck_ENUM = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
if (g_DrawBufferStatusCheck_ENUM != GL_FRAMEBUFFER_COMPLETE) {
switch (g_DrawBufferStatusCheck_ENUM)
{
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
break;
default:
break;
}
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return false;
}
/*
Create Oculus Rift's Framebuffer.
*/
glGenFramebuffers(1, &g_OculusRiftFrameBufferObject_ID);
glBindFramebuffer(GL_FRAMEBUFFER, g_OculusRiftFrameBufferObject_ID);
glGenTextures(1, &g_OculusRiftTexture_ID);
glBindTexture(GL_TEXTURE_2D, g_OculusRiftTexture_ID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, l_TextureSize.w, l_TextureSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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);
glGenRenderbuffers(1, &g_OculusRiftDepthBufferObject_ID);
glBindRenderbuffer(GL_RENDERBUFFER, g_OculusRiftDepthBufferObject_ID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, l_TextureSize.w, l_TextureSize.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_OculusRiftDepthBufferObject_ID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_OculusRiftTexture_ID, 0);
GLenum l_GLDrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, l_GLDrawBuffers); // "1" is the size of DrawBuffers
g_DrawBufferStatusCheck_ENUM = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
if (g_DrawBufferStatusCheck_ENUM != GL_FRAMEBUFFER_COMPLETE) {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return false;
} else {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
MainEyeFov[ovrEye_Left] = (*MainRiftDeviceDesc).DefaultEyeFov[ovrEye_Left];
MainEyeFov[ovrEye_Right] = (*MainRiftDeviceDesc).DefaultEyeFov[ovrEye_Right];
l_Cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
l_Cfg.OGL.Header.Multisample = 0;
l_Cfg.OGL.Header.RTSize.w = (*MainRiftDeviceDesc).Resolution.w;
l_Cfg.OGL.Header.RTSize.h = (*MainRiftDeviceDesc).Resolution.h;
l_Cfg.OGL.Window = glfwGetWin32Window(MainApplicationWindow);
int l_RenderCaps = 0;
int l_DistortionCaps = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp;
if (ovrHmd_ConfigureRendering((*MainRiftDevice), &l_Cfg.Config, l_DistortionCaps,
MainEyeFov, MainEyeRenderDesc) == false) {
return false;
}
l_EyeTexture[ovrEye_Left].OGL.Header.API = ovrRenderAPI_OpenGL;
l_EyeTexture[ovrEye_Left].OGL.Header.TextureSize.w = l_TextureSize.w;
l_EyeTexture[ovrEye_Left].OGL.Header.TextureSize.h = l_TextureSize.h;
l_EyeTexture[ovrEye_Left].OGL.Header.RenderViewport.Pos.x = 0;
l_EyeTexture[ovrEye_Left].OGL.Header.RenderViewport.Pos.y = 0;
l_EyeTexture[ovrEye_Left].OGL.Header.RenderViewport.Size.w = l_TextureSize.w / 2;
l_EyeTexture[ovrEye_Left].OGL.Header.RenderViewport.Size.h = l_TextureSize.h;
l_EyeTexture[ovrEye_Left].OGL.TexId = g_OculusRiftTexture_ID;
// Right eye uses the same texture, but a different rendering viewport...
l_EyeTexture[ovrEye_Right] = l_EyeTexture[ovrEye_Left];
l_EyeTexture[ovrEye_Right].OGL.Header.RenderViewport.Pos.x = (l_TextureSize.w + 1) / 2;
return true;
}
}
1 Reply
- vrdavebOculus StaffHave you checked the GL error state? It's possible the new material code is causing an error that doesn't break anything but the Rift distortion code. I would recommend running your app with gDEBugger or apitrace and telling them to break/report on any error. You can also call glGetError() after each GL call.
One thing that jumps out is the internal format of your texture. Should glTexImage2D(..) be referencing iInternalFormat instead of GL_RGB in the following code?"ckoeber" wrote:
glGenTextures(1, &TextureObject_ID); // section being edited by CKoeber to pull in material files
glBindTexture(GL_TEXTURE_2D, TextureObject_ID);
setFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP);
GLsizei iFormat = BytesPerPixel == 24 ? GL_BGR : BytesPerPixel == 8 ? GL_LUMINANCE : 0;
GLsizei iInternalFormat = BytesPerPixel == 24 ? GL_RGB : GL_DEPTH_COMPONENT;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
WidthOfTexture, HeightOfTexture, 0, iFormat,
GL_UNSIGNED_BYTE, bytesDataPointer);
glGenerateMipmap(GL_TEXTURE_2D);
FreeImage_Unload(loadedImage);
glGenSamplers(1, &TextureSamplerObject_ID);
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device