2014. 4. 19. 14:48
[OpenGL]
◆ 윈도우즈 OPENGL - 랜더링 컨텍스트
OpenGL 렌더링 컨텍스트: OpenGL 설정과 명령을 기억함
OpenGL 명령은 작업할 목적지 창을 알아야 한 스레드 당 하나의 렌더링 컨텍스트만을 활성화 할 수 있음
- 따라서 OpenGL 명령 이전 렌더링 창을 지정해야 함
[step 1] HGLRC hRC; // OpenGL 랜더링 컨텍스트 핸들러 변수 선언
[step 2] HDC hDC; // 개별적인 윈도우즈 장치 컨텍스트 선언
[step 3] 픽셀 포맷 지정 // 표현할 창의 속성 정의
[step 4] hRC = wglCreateContext(hDC); // OpenGL 랜더링 컨텍스트 핸들러 생성(개별적인 윈도우즈 장치 컨텍스트)
[step 5] wglMakeCurrent(hDC, hRC); // OpenGL 렌더링 컨텍스를 활성화하고 창의 장치컨텍스트와 연결
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | HGLRC m_hRC; //Rendering Context HDC m_hDC; // Device Context m_hDC = ::GetDC(m_hWnd); // Get the Device context int nPixelFormat; // Pixel format index static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),// Size of this structure 1, // Version of this structure PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap) PFD_SUPPORT_OPENGL | // Support OpenGL calls in window PFD_DOUBLEBUFFER, // Double buffered mode PFD_TYPE_RGBA, // RGBA Color mode 24, // Want 24bit color 0,0,0,0, 0,0,0,0, 0,0,0,0,0, // Not used to select mode 32, // Size of depth buffer 0,0, PFD_MAIN_PLANE, // Draw in main plane 0,0,0,0}; // Not used to select mode // Choose a pixel format that best matches that described in pfd nPixelFormat = ChoosePixelFormat(m_hDC, &pfd); // Set the pixel format for the device context VERIFY(SetPixelFormat(m_hDC, nPixelFormat, &pfd)); // Create the rendering context m_hRC = wglCreateContext(m_hDC); // Make the rendering context current, perform initialization, then // deselect it VERIFY(wglMakeCurrent(m_hDC,m_hRC)); |
윈도우즈 프로그램은 다수의 창을 포함함. 즉, 각각 창들이 자신의 장치 컨텍스트를 가지고 이는 개별적은 픽셀 포맷을 가질 수 있음
- 윈도우즈 GDI 함수(장치 컨텍스트): GDI를 위한 드로잉 모드와 명령을 기억함 즉, OPenGL 랜더링 컨텍스트와 유사함
결론: OpenGL 랜더링 컨텍스트를 통해서 화면을 제어하는데 윈도우즈 프로그램에서 이를 활용하기 위해서는 윈도우즈 장비 컨텍스트를 OpenGL 랜더링 컨텍스트와 연결 해줘야 제어가 가능함.
'OpenGL' 카테고리의 다른 글
OpenGL: Basic knowledge for 3D programing (0) | 2014.04.19 |
---|---|
Windows OpenGL: Making Window Application with OpenGL (0) | 2014.04.19 |
Windows OpenGL: Setting and selecting Pixel format (0) | 2014.04.19 |
OPENGL color define (0) | 2014.04.16 |
Setting Up OpenGL in an MFC control (0) | 2014.04.15 |