wglGetProcAddress returns NULL
Asked Answered
I

1

6

I was trying to use WGL_ARB_pbuffer for offscreen rendering with OpenGL,

but I was failed during initialization. Here is my code.
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
if(!wglGetExtensionsStringARB) return;
const GLubyte* extensions = (const GLubyte*) wglGetExtensionsStringARB(wglGetCurrentDC());

So actually this ends at 2nd line because wglGetExtensionsStringARB got NULL.

I have no idea why wglGetProcAddress doesn't work. I included "wglext.h" and also I defined as below at the header.
PFNWGLGETEXTENSIONSSTRINGARBPROC    pwglGetExtensionsStringARB = 0;
#define wglGetExtensionsStringARB   pwglGetExtensionsStringARB

Why can't I use wglGetProcAddress as I intended??
Indifferentism answered 14/2, 2014 at 1:56 Comment(5)
Are you sure the function is supported by your driver/card combination? The ARB indicates it to be a function that's not necessarily supported on all hardware. Quoting from opengl.org/registry/specs/ARB/wgl_extensions_string.txt - "Applications should call wglGetProcAddress to see whether or not wglGetExtensionsStringARB is supported. If it is supported then it can be used to determine which WGL extensions are supported by the device."Ehudd
That's why I wrote "if(!wglGetExtensionsStringARB) return;" so there it returns and I still don't know why wglGetExtensionsStringARB got null. If I have to chekc my driver, how can I?Indifferentism
As @Ehudd mentioned, the NULL indicates your driver/GL implementation does not support this extension. Incase you have a software implementation that has this support, you can use it, or you need to upgrade your driver/HW. Unless you plan to implement this extension yourself, little you can do as checking the driver.Charade
@Indifferentism - If the wglGetProcAddress call returns NULL, its not supported - this is how you check for card/driver support. You apparently dont have it. :( Have you tried wglGetExtensionString, as is mentioned in an answer here: #11315553 ?Ehudd
Do other (non wgl and wgl extensions) work? Do you have a gl context current?Nipping
K
17

wglGetProcAddress requires an OpenGL rendering context; you need to call your wglCreateContext and wglMakeCurrent prior to calling wglGetProcAddress. If you have not already setup an OpenGL context, wglGetProcAddress will always return NULL. If you're not sure if you have an OpenGL context yet (for example, if you're using a 3rd party framework/library), call wglGetCurrentContext and check to make sure it's not returning NULL.

Knox answered 14/2, 2014 at 5:48 Comment(1)
OHHH so that's why glewInit is called after glutCreateWindow. Still doesn't explain why glLoadMatrixf/glGetFloatv(GL_MODELVIEW_MATRIX,Out) also need it(dont crash but do nothing if context not set)...Brothers

© 2022 - 2024 — McMap. All rights reserved.