Creating OpenGL context without window

15,769

The old method for purely windowless OpenGL is using a PBuffer. On Windows this requires the creation of a intermediate OpenGL context using a regular window to obtain the required extension function pointers. On X11/GLX it works without further ado.

The modern way to implement off-screen rendering is using a regular, but hidden window with the usual OpenGL context and a FBO as render target.

The bleeding edge, and yet not very well supported method (except on certain embedded devices) is using EGL for drawable creation.

Share:
15,769
Rookie
Author by

Rookie

english is not my native language, bear with me.

Updated on June 16, 2022

Comments

  • Rookie
    Rookie about 2 years

    I'm trying to figure out what is the simplest way to create a windowless OpenGL program for offscreen rendering.

    Currently I use this, and it works fine so far: (error checks removed here for clarity)

    BOOL create_opengl_context(){
        GLuint PixelFormat;
        static PIXELFORMATDESCRIPTOR pfd;
        hDC = GetDC(NULL);
        PixelFormat = ChoosePixelFormat(hDC, &pfd);
        SetPixelFormat(hDC, PixelFormat, &pfd);
        hRC = wglCreateContext(hDC);
        wglMakeCurrent(hDC, hRC);
    }
    

    Is this safe to use? What is the "standard" way to create a windowless OpenGL program?

    Edit: I'm using FBO for the offscreen rendering.

  • Rookie
    Rookie almost 12 years
    Im using FBO. Currently the context creation takes 3/4 of the time my program runs... is it anywhow possible to reduce this context creation time?
  • rodrigo
    rodrigo almost 12 years
    @Rookie: If you are running the same program many times, maybe you can change it to a client/server model, in which the client does the computations but the server does the actual render. That way the context is created only once in the server initialization.
  • Rookie
    Rookie almost 12 years
    @rodrigo, i cant let client do any computations or i would run into other compatibility problems. i dont understand how that makes the context creation only once though... im not sure how can i make it "keep alive" the program but still be possible to run multiple processes from that program at once...?