2014-12-29 3 views
1

http://nehe.gamedev.net/tutorial/creating_an_opengl_window_(win32)/13001/ OpenGL 튜토리얼을 따르고 있으며 그 코드를 사용하고 있습니다. 이제 여러 클래스를 사용하여 구성하려고합니다. 이 클래스를 만들면서 Device Context, HWND를 릴리스 할 수 없게되었고 Windows 클래스의 등록을 취소 할 수 없었습니다.Device Context, HWND를 해제 할 수없고 Windows 클래스 (OpenGL)를 등록 취소 할 수 없습니다. -

GLvoid KillGLWindow(GLvoid){ 
if (fullscreen){ 
    ChangeDisplaySettings(NULL, 0); 
    ShowCursor(true); 
} 
if (hRC){ 
    if (!wglMakeCurrent(NULL, NULL)){ 
     MessageBox(NULL, "Release of DC and RC failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
    } 
    if (!wglDeleteContext(hRC)){ 
     MessageBox(NULL, "Release of RC failed", "Shutdown error", MB_OK | MB_ICONEXCLAMATION); 
    } 
    hRC = NULL; 
} 
if (hDC && !ReleaseDC(hWnd, hDC)){ 
    MessageBox(NULL, "Release of DC failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
    hDC = NULL; 
} 
if (hWnd && !DestroyWindow(hWnd)){ 
    MessageBox(NULL, "Release of hWnd failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
    hWnd = NULL; 
} 
if (!UnregisterClass("OpenGL", hInstance)){ 
    MessageBox(NULL, "Could not unregister window class", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
    hInstance = NULL; 
} 
} 

(문에서도 해고 경우 마지막 세)

나는 이러한 오류의 원인이 그 주위를 움직이고 된 코드는 키 검출입니다 : 아래의 코드는 해제 여부를 할 수 있는지 확인하는 데 사용되는 코드입니다 WinMain 함수의 코드. 이것이 내가 바꾼 유일한 코드입니다.

else{ 
     if (active){ 

      if (testKey.isEsc()){ 
       done = true; 
      } 
      if (testKey.isA()){ 
       KillGLWindow(); 
      } 
      else{ 
       DrawGLScene(); 
       SwapBuffers(hDC); 
      } 
     } 
      if (testKey.isF1()){ 
       //Keys::keys[VK_F1] = false; 
       KillGLWindow(); 
       fullscreen = !fullscreen; 
       if (!CreateGLWindow("XcoxGL", 640, 480, 16, fullscreen)){ 
        return 0; 
       } 
      } 

내가 변경 한 부분은 testKey.THING 부분입니다.

bool Keys::keys[256] = { false }; 

bool Keys::isA(){ 
    if (&keys[0x41]){ 
     return true; 
    } 
    else{ 
     return false; 
    } 
} 

bool Keys::isF1(){ 
    if (&keys[VK_F1]){ 
     return true; 
    } 
    else{ 
     return false; 
    } 
} 

bool Keys::isEsc(){ 
    if (&keys[VK_ESCAPE]){ 
     return true; 
    } 
    else{ 
     return false; 
    } 
} 

그리고 마지막으로, Keys.h는 다음과 같습니다 :

#pragma once 
class Keys{ 
public: 
    static bool keys[256]; 
    bool isA(); 

    bool isF1(); 

    bool isEsc(); 
}; 

I를 testKey은

Keys testKey 

Keys.cpp이처럼 보이는 선으로 메인 클래스에서 시작된다 원하는 경우 전체 코드를 게시 할 수 있지만 DC 및 HWND를 만드는 방법은 위에 게시 된 자습서에 나와 설명되어 있습니다.

누군가 내 키 코드로 인해 DC와 HWND가 출시되지 못하는 것을 알고 있습니까?

답변

0
아마 KillGLWindow이 한 번 이상이라고

, 그 정말 적절하지,이 시도 :

GLvoid KillGLWindow(GLvoid){ 
if (fullscreen){ 
    ChangeDisplaySettings(NULL, 0); 
    ShowCursor(true); 
} 
if (hRC){ 
    if (!wglMakeCurrent(NULL, NULL)){ 
     MessageBox(NULL, "Release of DC and RC failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
    } 
    if (!wglDeleteContext(hRC)){ 
     MessageBox(NULL, "Release of RC failed", "Shutdown error", MB_OK | MB_ICONEXCLAMATION); 
    } 
} 
hRC = NULL; 
if (hDC && !ReleaseDC(hWnd, hDC)){ 
    MessageBox(NULL, "Release of DC failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
} 
hDC = NULL; 
if (hWnd && !DestroyWindow(hWnd)){ 
    MessageBox(NULL, "Release of hWnd failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
} 
hWnd = NULL; 
if (hInstance && !UnregisterClass("OpenGL", hInstance)){ 
    MessageBox(NULL, "Could not unregister window class", "Shutdown error", MB_OK | MB_ICONINFORMATION); 
} 
hInstance = NULL; 
} 
관련 문제