wglGetProcAddress returns NULL

拈花ヽ惹草 提交于 2020-01-01 03:46:14

问题


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??

回答1:


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.



来源:https://stackoverflow.com/questions/21769427/wglgetprocaddress-returns-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!