PDA

View Full Version : Offscreen rendering / X11 / FBOs



endlosschleife
11-03-2010, 03:32 AM
Hi all,

I don't get this to work, and I would like to know if this actually even possible. I would like to render offscreen on a Linux server and send the pixel data to a client. I have read about FBOs, and that they are independent of any windowing system, so I thought this would be the right approach to get this to work.

The code roughly looks like this:

The initialization:

// create FBO (offscreen framebuffer)
glGenFramebuffersEXT(1, &fb);
// bind offscreen buffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

glGenRenderbuffersEXT(1, &depthbuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 512, 512);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL _RENDERBUFFER_EXT, depthbuffer);
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYT E, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_T EXTURE_2D, tex, 0);

Some rendering...

Getting the pixel data:

unsigned char data[786432];

// read from texture
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

This will not produce the expected pixel data when I run this on a SSH console. I actually need to run this in a X console and open a X window first (using glut for that) and then I get the expected pixel data.

Any ideas if it is even possible to render offscreen using FBOs (or any other method) on a server where you actually don't have a windowing system available?

Thank you.

Mark

eile
11-03-2010, 04:17 AM
To make your GL context current, you need a X11 display connection and a drawable. Afaik there is no way around that with GLX. I do use a small unmapped window for FBO rendering.

There might be other OpenGL implementations on Linux which provide another 'glue' than GLX to allow for offscreen rendering without a X-Server. AGL for example does not require a drawable to make a GL context current.

Dark Photon
11-03-2010, 04:26 AM
To make your GL context current, you need a X11 display connection and a drawable. Afaik there is no way around that with GLX. I do use a small unmapped window for FBO rendering.
I think you're right about the drawable, but drawable need not be a window. It can be a pixmap or a pbuffer. See GLX_DRAWABLE_TYPE here:

http://www.opengl.org/sdk/docs/man/xhtml/glXGetFBConfigAttrib.xml

eile
11-04-2010, 01:05 AM
I think you're right about the drawable, but drawable need not be a window. It can be a pixmap or a pbuffer.

It can definitely be a PBuffer. Afair, pixmaps are not hardware-accelerated.

Using a window just seems the most robust path, since this is supported everywhere. I had some troubles with PBuffers on OS X which only has GLX 1.2, where PBuffers are not part of the core spec.