PDA

View Full Version : Alternative to glFramebufferTexture for OpenGL version 3.1



tmason
05-11-2014, 06:05 AM
Hello,

I am trying to create an OpenGL 3.1 application for the Oculus Rift and one item it seems to require is a frame buffer texture but the function glFramebufferTexture is available for versions 3.2 and higher.

Is there a function that mimics this via a hack or something for OpenGL 3.1?

Thank you for your time.

Agent D
05-11-2014, 06:18 AM
glFramebufferTexture2D for your case??

Framebuffer objects are part of core OpenGL(R) since version 3.0 (or previous via an extension).

It is true that the glFramebufferTexture function is only available in 3.2, but the specialized glFramebufferTextureND are available in 3.1.

I don't see where your problem is. The simplest way would be to set up an FBO (http://www.opengl.org/wiki/Framebuffer_Object) with a 2D texture color buffer attachment. One for the left eye and one for the right
eye. The resulting textures are rendered on two quads with a distortion applied for the Rift and that should be it.

tmason
05-11-2014, 06:30 AM
glFramebufferTexture2D for your case??

Framebuffer objects are part of core OpenGL(R) since version 3.0 (or previous via an extension).

It is true that the glFramebufferTexture function is only available in 3.2, but the specialized glFramebufferTextureND are available in 3.1.

I don't see where your problem is. The simplest way would be to set up an FBO (http://www.opengl.org/wiki/Framebuffer_Object) with a 2D texture color buffer attachment. One for the left eye and one for the right
eye. The resulting textures are rendered on two quads with a distortion applied for the Rift and that should be it.


Thank you. I was just trying to use the built in Oculus Rift SDK which takes the ID of the function.

Example below:



[...]

GLuint l_FBOId;
glGenFramebuffers(1, &l_FBOId);
glBindFramebuffer(GL_FRAMEBUFFER, l_FBOId);

// The texture we're going to render to...
GLuint l_TextureId;
glGenTextures(1, &l_TextureId);
// "Bind" the newly created texture : all future texture functions will modify this texture...
glBindTexture(GL_TEXTURE_2D, l_TextureId);
// Give an empty image to OpenGL (the last "0")
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, l_TextureSize.w, l_TextureSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
// Linear filtering...
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// Create Depth Buffer...
GLuint l_DepthBufferId;
glGenRenderbuffers(1, &l_DepthBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, l_DepthBufferId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, l_TextureSize.w, l_TextureSize.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, l_DepthBufferId);

[...]

/*

Oculus Rift API

*/

ovrGLTexture l_EyeTexture[2];
l_EyeTexture[0].OGL.Header.API = ovrRenderAPI_OpenGL;
l_EyeTexture[0].OGL.Header.TextureSize.w = l_TextureSize.w;
l_EyeTexture[0].OGL.Header.TextureSize.h = l_TextureSize.h;
l_EyeTexture[0].OGL.Header.RenderViewport = l_Eyes[0].RenderViewport;
l_EyeTexture[0].OGL.TexId = l_TextureId;

[...]

tmason
05-13-2014, 05:19 AM
glFramebufferTexture2D for your case??

Framebuffer objects are part of core OpenGL(R) since version 3.0 (or previous via an extension).

It is true that the glFramebufferTexture function is only available in 3.2, but the specialized glFramebufferTextureND are available in 3.1.

I don't see where your problem is. The simplest way would be to set up an FBO (http://www.opengl.org/wiki/Framebuffer_Object) with a 2D texture color buffer attachment. One for the left eye and one for the right
eye. The resulting textures are rendered on two quads with a distortion applied for the Rift and that should be it.

glFramebufferTexture2D works. Thank you.