现代OpenGL上下文失败
好吧,我设法创建一个OpenGL上下文与wglcreatecontextattribARB
版本3.2在我的attrib结构(所以我已经初始化3.2 opengl上下文)。
它工作,但奇怪的是,当我使用glBindBuffer e,g。 我仍然得到未引用的链接器错误,不应该有新的上下文阻止这个吗?
顺便说一句,Linux不需要处理旧的和新的上下文(它直接支持它的版本核心)。 代码:
PIXELFORMATDESCRIPTOR pfd;
HGLRC tmpRC;
int iFormat;
if (!(hDC = GetDC(hWnd)))
{
CMsgBox("Unable to create a device context. Program will now close.", "Error");
return false;
}
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = attribs->colorbits;
pfd.cDepthBits = attribs->depthbits;
pfd.iLayerType = PFD_MAIN_PLANE;
if (!(iFormat = ChoosePixelFormat(hDC, &pfd)))
{
CMsgBox("Unable to find a suitable pixel format. Program will now close.", "Error");
return false;
}
if (!SetPixelFormat(hDC, iFormat, &pfd))
{
CMsgBox("Unable to initialize the pixel formats. Program will now close.", "Error");
return false;
}
if (!(tmpRC=wglCreateContext(hDC)))
{
CMsgBox("Unable to create a rendering context. Program will now close.", "Error");
return false;
}
if (!wglMakeCurrent(hDC, tmpRC))
{
CMsgBox("Unable to activate the rendering context. Program will now close.", "Error");
return false;
}
strncpy(vers, (char*)glGetString(GL_VERSION), 3);
vers[3] = ' ';
if (sscanf(vers, "%i.%i", &glv, &glsubv) != 2)
{
CMsgBox("Unable to retrieve the OpenGL version. Program will now close.", "Error");
return false;
}
hRC = NULL;
if (glv > 2) // Have OpenGL 3.+ support
{
if ((wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB")))
{
int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, glv, WGL_CONTEXT_MINOR_VERSION_ARB, glsubv,WGL_CONTEXT_FLAGS_ARB, 0,0};
hRC = wglCreateContextAttribsARB(hDC, 0, attribs);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(tmpRC);
if (!wglMakeCurrent(hDC, hRC))
{
CMsgBox("Unable to activate the rendering context. Program will now close.", "Error");
return false;
}
moderncontext = true;
}
}
if (hRC == NULL)
{
hRC = tmpRC;
moderncontext = false;
}
你仍然需要
wglGetProcAddress
获取这些指针的正确内存位置 没错,OpenGL API函数实际上是函数指针。
如果您没有时间和耐心来做到这一点,那么建议使用OpenGL加载器库,如GL3W或GLEW。 这也将为您节省首先创建您的虚拟背景,然后创建“真实”背景的负担。
另请参阅加载函数指针的OpenGL wiki页面。
链接地址: http://www.djcxy.com/p/38455.html上一篇: Modern OpenGL context failure
下一篇: How to Create Dummy / False OpenGL Context with SDL 2.0 on Windows