[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [offtopic] screen capture using opengl



On Mon, 30 Mar 2009 10:59:42 -0500
"Boyd Stephen Smith Jr." <bss@iguanasuicide.net> wrote:

> In <[🔎] 20090330125126.2802148e@vivalunalitshi.luna.local>, Micha Feigin wrote:
> >I'm trying to figure out how to capture the screen using opengl. I tried
> >glReadPixels but if I understand correctly it is reading from the current
> >opengl context (the visible part of the current opengl window) and not the
> > full screen. Is there a way to make the current opengl context the full
> > screen instead of an opengl window, or is there another way to do this?
> 
> I've only got a passing familiarity with OpenGL, but I'll guess...
> 
> If you are doing a screen capture via OpenGL, you'll probably want to create 
> your own context (with direct GLX calls), rather than using the one provided 
> by your widgets API (Qt/Gtk).  You will probably need to base it off of the 
> root window.

Thanks, for some reason that gave me the right search words for google, found a
currently working solution using glx under linux (will still need to find a
matching version for windows). If anyone is interested or can tell me if what
I'm doing is the most efficient way for this, or much more importantly, how do
I trasnlate this code to copy the data into a PBO (pixel buffer object if I'm
not mistaken) then here is the code (without the error checking for clarity)

    Display *dpy = XOpenDisplay(NULL);
    Window root = DefaultRootWindow(dpy);
    GLint att[] = {GLX_RGBA, None};
    XVisualInfo *vis = glXChooseVisual(dpy, 0, att);
    GLXContext glc = glXCreateContext(dpy, vis, NULL, true);
    glXMakeCurrent(dpy, root, glc);

    glReadBuffer(GL_FRONT);

    unsigned char *data = new unsigned char[WIDTH*HEIGHT*3];
    glReadPixels (0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, data);


Reply to: