2013-10-19 11 views
0

좋아요, 내 속성 구조체에 버전 3.2와 함께 wglcreatecontextattribARB 인 OpenGL 컨텍스트를 만들 수있었습니다. (그래서 저는 3.2 OpenGL 컨텍스트를 초기화했습니다).현대 OpenGL 컨텍스트 오류

작동하지만 이상한 점은 glBindBuffer e, g를 사용할 때입니다. 아직 참조되지 않은 링커 오류가 발생합니다. 더 새로운 컨텍스트가이를 방지하지 않아야합니까?

나는 윈도우에있다. 리눅스는 오래되고 새로운 컨텍스트 (그것의 버전의 핵심을 직접적으로 지원한다)를 다룰 필요가 없다. 코드 :

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] = '\0'; 
    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; 
    } 
+0

이 질문은 stackoverflow에 속한 것 같아요. – Shekhar

답변

4

당신은 여전히 ​​apropriate 이름과 기능 서명

  1. 에 선언 함수 포인터가 필요합니다.
  2. wglGetProcAddress
  3. # 해당 함수 포인터에 실제 OpenGL API 이름을 정의하여 해당 포인터의 올바른 메모리 위치를 가져옵니다.

그렇습니다. OpenGL API 함수는 실제로 함수 포인터입니다.

GL3W 또는 GLEW와 같은 OpenGL 로더 라이브러리를 사용하는 것이 시간과 인내가 없으면 권장됩니다. 이렇게하면 더미 컨텍스트를 만든 다음 "실제"컨텍스트를 만드는 부담을 덜어줍니다.

OpenGL wiki page on loading function pointers도 참조하십시오.

+0

그런 다음 새로운 컨텍스트를 만드는 데 전체 USE는 무엇입니까? 이전 컨텍스트 (함수 포인터 및 확장 같은 선언으로 새 API를 액세스)와 동일한 작업을 수행해야하는 경우 새로운 컨텍스트를 전혀 쓸모 없게 만들지 않습니까? – user209347

+0

@ user209347 짧은 답변 : 아니오, 쓸모가 없습니다. 간단한 동기 부여를 위해 [wgl_create_context] (https://www.opengl.org/registry/specs/ARB/wgl_create_context.txt)의 "개요"섹션을 읽으십시오. – user2802841

+0

관련 글 wglGetProcAddress – luiscubal