offscreen rendering context

Is it possible to create an offscreen rendering context ? :confused:
I know Mesa can do it, but I don’t want to use that lib …


look into pbuffers.

check this out:

ok I tried to make a pbuffer with ARB extension
but I have always the same pb :
I don’t have any rendering context for ogl because all my stuff is in a DLL

but before calling functions like glGetString(GL_EXTENSIONS), I need a valid opengl context and a valid device context

I tried this code :

HDC hGLDC = ::CreateCompatibleDC(NULL);
HGLRC hGLRC = wglCreateContext(hGLDC);

const unsigned char* tmp = glGetString(GL_EXTENSIONS);

but hGLRC == NULL … do you have any solution for me ?

well, you’re getting a memory DC by passing NULL.

I think what you need to do is create a dumby window (one that is never displayed) and inside that window set your PFD (pixel format descriptor), get a DC from that window and finally get your hGLRC.

It’s a hack, but it should get you a GL rendering context.

good luck.

damn ?!
Is it the only solution ??

Does anyone have an example of creating a dummy window ?

I tried that but it fails :

HWND hWnd;
WNDCLASS wndclass;

memset(&wndclass, 0, sizeof(WNDCLASS)); = CS_OWNDC;
wndclass.lpfnWndProc = WinProc;
wndclass.hInstance = NULL;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wndclass.lpszClassName = "test";


HDC dummyHDC = ::GetDC(hWnd );

   PFD_TYPE_RGBA, 0,0,0,0,0,0,0,0,0,0,0,0,0, 
   16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0

int pixelFormat = ChoosePixelFormat(dummyHDC, &pfd);
SetPixelFormat(dummyHDC, pixelFormat, &pfd);

HGLRC dummyHGLRC = wglCreateContext(dummyHDC);

wglMakeCurrent(dummyHDC, dummyHGLRC);

const unsigned char* tmp = glGetString(GL_EXTENSIONS);
std::string ext = (char*)tmp;
int k = ext.find("WGL_ARB_pbuffer");

k == -1 at this time…
It doesn’t find my extension

Can you run it in a debugger and see what you’re getting back as your extension string?

what is this returning?
const unsigned char* tmp = glGetString(GL_EXTENSIONS);

also, your PFD isn’t set up to render to pBuffers.

you need to set up your PFD with the following enumeration:

I did a quick search and this seems to walk thru setting up a pbuffer and PFD…
check it out:

setting all this up is teadious (and more importantly, terribly uninteresting) so I’d much rather point you to a link then try and type it myself here.

good luck.

He is only asking for how to create a dummy window so you do not need the WGL_DRAW_TO_PBUFFER_ARB flag set. After all until you start GL you have no idea whether or not it supports pbuffers.

You should also set the WS_CLIPCHILDREN and WS_CLIPSIBLINGS for window style when you create the window. Though I doubt ommitting this will cause you any problems at this stage.

You can also check the return value of glGetString(GL_RENDERER) and glGetString(GL_VENDOR) which will give you a fair idea of whether you got the hardware driver or not.

I notice you are neglecting to set up any colour bits. I have no idea what this will do but it would certainly be better to ask for some I expect. Bare in mind that the pixel format you create your dummy context with doesn’t have to match the one you need for you pbuffer (there are however reasons why you may want it to).

You can also ask for the actual pixel format it chose to be described, since what you get back may not be what you asked for, something like this:

DescribePixelFormat(hDC, nPixelFormat, sizeof(pfd), &pfd))

You can also check for a hardware accelerated pixel format like this:

if(pfd.dwFlags & PFD_GENERIC_FORMAT)
then no hardware accel


Ok thanx I will try it

Ok, I managed to make my pbuffer features
but there is comething that I don’t understand …

To create a pbuffer, I must :

  • create a hidden window
  • get the hidden window device context
  • create a valid opengl context
  • then I can create pbuffer
  • render my scene
  • I get buffer with glReadPixels

but if my computer doesn’t support pbuffer extension, I do :

  • create a hidden window
  • get the hidden window device context
  • create a valid opengl context
  • render my scene
  • I get buffer with glReadPixels

It is almost the same procedure !
So what are the advantages of using pbuffer ?

  • P-buffers are not connected to the window’s size. They can be bigger than the screen.
  • P-buffers never fail the pixel ownership test due to overlapping windows or areas moved off the desktop.

If you use EXTENSION you must call this first:

if specified hardware extension:


Hey Relic…

Why I can’t use TgluQuadricObj in OpenGL Extension?