Can framebuffer object used without egl initialization?

I’m a newcomer to the opengl programming. I want to use opengles 2.0 to do some post-processing of images. I find that the FBO seems to be a good choice. My question is how can I use the FBO and should I use the EGL API to create a display,context,surface before that? I found that I cannot use glGetIntegerv or glGenFramebuffer until a window/pbuffer surfface is created. Is there any better ways to do the same thing?

My code is like this, when egl initialization presents the code can run, but when removed it seems any function begin with gl* will fail.

#include “./gl2.h”
#include “./gl2ext.h”
#include “./gl2extimg.h”
int main(int argc, char *argv)
{
// Fragment and vertex shaders code
const char
pszVertShader =
"attribute vec4 a_position;
"
"void main()
"
"{
"
" gl_Position = a_position;
"
"}
";

const char* pszFragShader =
"precision mediump float;
"
"void main()
"
"{
"
" gl_FragColor = vec4(0.5, 0.3, 0.1,1.0);
"
"}
";
GLuint uiFragShader, uiVertShader; // Used to hold the fragment and vertex shader handles
GLuint uiProgramObject; // Used to hold the program handle (made out of the two previous shaders
// Create the fragment shader object
uiFragShader = glCreateShader(GL_FRAGMENT_SHADER);

Even I am looking for an answer for the exactly same problem. I think you need to create EGLContext as it is necessary for maintaining the OpenGL ES state (hope I am not wrong here), but I am not sure if creating pBuffer surface is required as you are planning to render onto a FBO object. However, if you don’t create pBuffer surface, then I am not sure what needs to be passed as argument to eglMakeCurrent!

Please let me know if you found what you were looking far!

Thanks,

ASFIK , you can not make any gl call before creating eglContext . Create a eglContext first and then you can proceed with FBOs no need to initialize shaders’ stuff.

Thank you for you reply. I know glContext is necessary,but what about surface. Logically speaking I think it not necessary, but in fact FBO will not work if you do not create a surface.

Hi,

i use the context without showing any surface on the screen. Im using iOS so i don’t know if this is available on your platform, but maybe it helps you. It’s necessary to create a rectangle where the OpenGL ES context can render the images. But i don’t use it from the main screen. I think you only search for a rendering solution without showing the image on the screen?

My solution for this:

I’ve created a OpenGLESManager which holds the context.
The initialization looks like the following code sniped:


    if((_instance = [super initWithFrame:CGRectMake(0.0f, 0.0f, 2000, 2860)]))
    {
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
        
        if(!context || ![EAGLContext setCurrentContext:context])
        {
            [self release];
            return nil;
        }
        
        [self createFramebuffer];
    }

After this i can use the opengl methods and rendering stuff. But i don’t need to show it on the screen.

For the context maybe it helps you to understand. The OpenGL ES Api is developed like a client server structure. And with the creating of the context you can set some messages or stats to the server. (<- This is from a OpenGL ES book and it helps me to understand the stuff of the OpenGL ES)

Spec currently requires an egl surface/context be made current in your thread, even if you just want to render to an FBO.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.