wglCreatePbufferARB()

I want to create a pixel buffer with wglCreatePbufferARB() and the following attributes:

WGL_DEPTH_TEXTURE_FORMAT_NV,
WGL_TEXTURE_DEPTH_COMPONENT_NV,
WGL_TEXTURE_TARGET_ARB,
WGL_TEXTURE_2D_ARB,

I know my machine supports this because I tried the nVidia demo ‘Simple shadow mapping’. But wglCreatePbufferARB() always returns NULL in my project so my question is if there is ANYTHING I have to enable/disable in order to successfully create a pixel buffer with the above attributes?

Thanks in advance,
Gero Gerber

Could you post the piece of code that tries to do this?

Of course…

// Create pbuffer (pixel-buffer) for each light
HDC hdc = wglGetCurrentDC();
HGLRC hRC = wglGetCurrentContext();

// attribute arrays
int aiPFormats[256] = { 0 };
unsigned int uiNumPFormats = 0;
int aiAttributes[512] = { 0 };
float afAttributes[512] = { 0.0f };
int iNumAttributes = 0;
float fNumAttributes = 0.0f;
int iWidth = 1024;
int iHeight = 1024;

aiAttributes[iNumAttributes++] = WGL_DRAW_TO_PBUFFER_ARB;
aiAttributes[iNumAttributes++] = GL_TRUE;

aiAttributes[iNumAttributes++] = WGL_BIND_TO_TEXTURE_DEPTH_NV;
aiAttributes[iNumAttributes] = GL_TRUE;

wglChoosePixelFormatARB(hdc, aiAttributes, afAttributes, 512, aiPFormats, &uiNumPFormats);

ZeroMemory(aiAttributes, 512 * sizeof(int));
iNumAttributes = 0;

aiAttributes[iNumAttributes++] = WGL_DEPTH_TEXTURE_FORMAT_NV;
aiAttributes[iNumAttributes++] = WGL_TEXTURE_DEPTH_COMPONENT_NV;

aiAttributes[iNumAttributes++] = WGL_TEXTURE_TARGET_ARB;
aiAttributes[iNumAttributes] = WGL_TEXTURE_2D_ARB;

HPBUFFERARB hPBuffer = wglCreatePbufferARB(hdc, aiPFormats[0], iWidth, iHeight, aiAttributes);

// hPBuffer is NULL :frowning:

You may need to provide more information like bit depth for color buffer and so on. I tried many different things to get this function working. My problem was that I was using somethings incorrectly… took me a while to debug it.

I can send you my code if you want and you can update it.

V-man

You didn’t call wglGetProcAddress in your code to get the OpenGL extensions. Could that be the problem?

he has initialised its functions, else it would not return 0 but crash…

I create the pixel buffer in the exact same way as the demo does. But if I clear aiAttributes[] to zero between wglChoosePixelFormatARB() and wglCreatePbufferARB() it returns a valid handle. But I need the depth texture attributes to be set for my project. I’m totally clueless on how to solve this thing :frowning:

For those of you who are interested. My problem is solved with the help from nVidia. I had to call wglGetExtensionsStringARB() before pbuffer creation. I didn’t know that this function does more than returning the supported extensions :frowning:

That sounds very odd
Of course you should call this function to see if WGL_ARB_pbuffer extension is supported in a shipping application, but it should work otherwise too. They must have done some sort of hack in the drivers I suppose.

Mmh, you are right. And this is nowhere documented.
If I don’t specify WGL_DEPTH_TEXTURE_FORMAT_NV and don’t call wglGetExtensionsStringARB() I also get a pbuffer. Seems that only this flag needs the call to wglGetExtensionsStringARB(). I don’t under stand it,… BUT IT WORKS :wink:

hm odd… drivers look little crappy so far then… at least your problem is solved. my one isn’t (the crash on wgl_arb_render_texture) but i call the getextensionstring yet
have fun…