Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wglGetProcAddress returns NULL

Tags:

c++

opengl

wgl

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??
like image 875
phraust Avatar asked Dec 09 '22 09:12

phraust


1 Answers

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.

like image 148
Mr. Smith Avatar answered Dec 11 '22 00:12

Mr. Smith