PDA

View Full Version : offscreen rendering context



overseb
09-24-2004, 06:18 AM
Is it possible to create an offscreen rendering context ? :confused:
I know Mesa can do it http://www.mesa3d.org/, but I don't want to use that lib ...

thx

Aeluned
09-24-2004, 07:18 AM
look into pbuffers.

check this out: http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_pbuffer.txt

overseb
09-30-2004, 06:43 AM
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 ?
thx

Aeluned
09-30-2004, 06:55 AM
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.

overseb
09-30-2004, 10:13 PM
damn ?!
Is it the only solution ??

overseb
10-01-2004, 03:37 AM
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));
wndclass.style = 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";
RegisterClass(&wndclass);

hWnd = CreateWindow("test", "test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL);

HDC dummyHDC = ::GetDC(hWnd );

static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), 1,
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
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

Aeluned
10-01-2004, 05:55 AM
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:
WGL_DRAW_TO_PBUFFER_ARB;

I did a quick search and this seems to walk thru setting up a pbuffer and PFD...
check it out:
http://reality.siliconstudio.co.jp/~terada/OpenGL/Samples/pbuffer1.cxx

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.

MattS
10-01-2004, 07:54 AM
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

Matt

overseb
10-04-2004, 10:22 PM
Ok thanx I will try it

overseb
10-12-2004, 12:56 AM
Hi
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 ?

Relic
10-12-2004, 01:06 AM
- 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.

Dol AI with 3D Bone system
10-12-2004, 08:50 PM
If you use EXTENSION you must call this first:
wglGetProcAddress(glGetString(GL_EXTENSION));

if specified hardware extension:
wglGetProcAddress(glGetString(GL_RENDERER));

Testing...

Dol AI with 3D Bone system
10-12-2004, 08:53 PM
Hey Relic...

Why I can't use TgluQuadricObj in OpenGL Extension?