4

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??
phraust
  • 113
  • 1
  • 9
  • 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 https://www.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." – enhzflep Feb 14 '14 at 02:11
  • 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? – phraust Feb 14 '14 at 02:23
  • As @enhzflep 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. – Prabindh Feb 14 '14 at 03:38
  • @phraust - 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: http://stackoverflow.com/questions/11315053/how-to-read-windows-specific-extensions ? – enhzflep Feb 14 '14 at 04:55
  • 2
    Do other (non wgl and wgl extensions) work? Do you have a gl context current? – starmole Feb 14 '14 at 05:26

1 Answers1

14

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.

Mr. Smith
  • 4,394
  • 5
  • 34
  • 74
  • 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)... – Dmitry Nov 12 '17 at 00:40