M-HT
Very Active Member
First I load the FBO extension with this function:
Then I use it like this:
The code is in D, but it should be understandable.
bool loadFBOExtension() {
bool fboExtensionAvailable = false;
bool fboFunctionsAvailable = false;
glBindFramebufferOES = null;
glDeleteFramebuffersOES = null;
glGenFramebuffersOES = null;
//glCheckFramebufferStatusOES = null;
glFramebufferTexture2DOES = null;
string extensions = to!string(cast(char *)glGetString(GL_EXTENSIONS));
string extleft = extensions;
while (extleft.length != 0) {
ptrdiff_t delim = indexOf(extleft, ' ');
string extension;
if (delim != -1) {
extension = extleft[0..delim];
extleft = extleft[delim+1..extleft.length];
} else {
extension = extleft;
extleft = extleft[0..0];
}
if (extension == "GL_OES_framebuffer_object") {
fboExtensionAvailable = true;
break;
}
}
if (fboExtensionAvailable) {
glBindFramebufferOES = cast(PFNGLBINDFRAMEBUFFEROESPROC) eglGetProcAddress(toStringz("glBindFramebufferOES"));
glDeleteFramebuffersOES = cast(PFNGLDELETEFRAMEBUFFERSOESPROC) eglGetProcAddress(toStringz("glDeleteFramebuffersOES"));
glGenFramebuffersOES = cast(PFNGLGENFRAMEBUFFERSOESPROC) eglGetProcAddress(toStringz("glGenFramebuffersOES"));
//glCheckFramebufferStatusOES = cast(PFNGLCHECKFRAMEBUFFERSTATUSOESPROC) eglGetProcAddress(toStringz("glCheckFramebufferStatusOES"));
glFramebufferTexture2DOES = cast(PFNGLFRAMEBUFFERTEXTURE2DOESPROC) eglGetProcAddress(toStringz("glFramebufferTexture2DOES"));
fboFunctionsAvailable = (glBindFramebufferOES != null)
&& (glDeleteFramebuffersOES != null)
&& (glGenFramebuffersOES != null)
//&& (glCheckFramebufferStatusOES != null)
&& (glFramebufferTexture2DOES != null);
}
return fboExtensionAvailable && fboFunctionsAvailable;
}
bool fboExtensionAvailable = false;
bool fboFunctionsAvailable = false;
glBindFramebufferOES = null;
glDeleteFramebuffersOES = null;
glGenFramebuffersOES = null;
//glCheckFramebufferStatusOES = null;
glFramebufferTexture2DOES = null;
string extensions = to!string(cast(char *)glGetString(GL_EXTENSIONS));
string extleft = extensions;
while (extleft.length != 0) {
ptrdiff_t delim = indexOf(extleft, ' ');
string extension;
if (delim != -1) {
extension = extleft[0..delim];
extleft = extleft[delim+1..extleft.length];
} else {
extension = extleft;
extleft = extleft[0..0];
}
if (extension == "GL_OES_framebuffer_object") {
fboExtensionAvailable = true;
break;
}
}
if (fboExtensionAvailable) {
glBindFramebufferOES = cast(PFNGLBINDFRAMEBUFFEROESPROC) eglGetProcAddress(toStringz("glBindFramebufferOES"));
glDeleteFramebuffersOES = cast(PFNGLDELETEFRAMEBUFFERSOESPROC) eglGetProcAddress(toStringz("glDeleteFramebuffersOES"));
glGenFramebuffersOES = cast(PFNGLGENFRAMEBUFFERSOESPROC) eglGetProcAddress(toStringz("glGenFramebuffersOES"));
//glCheckFramebufferStatusOES = cast(PFNGLCHECKFRAMEBUFFERSTATUSOESPROC) eglGetProcAddress(toStringz("glCheckFramebufferStatusOES"));
glFramebufferTexture2DOES = cast(PFNGLFRAMEBUFFERTEXTURE2DOESPROC) eglGetProcAddress(toStringz("glFramebufferTexture2DOES"));
fboFunctionsAvailable = (glBindFramebufferOES != null)
&& (glDeleteFramebuffersOES != null)
&& (glGenFramebuffersOES != null)
//&& (glCheckFramebufferStatusOES != null)
&& (glFramebufferTexture2DOES != null);
}
return fboExtensionAvailable && fboFunctionsAvailable;
}
Then I use it like this:
glGenFramebuffersOES(1, &luminousFramebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, luminousFramebuffer);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, luminousTexture, 0);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, luminousFramebuffer);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, luminousTexture, 0);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
The code is in D, but it should be understandable.