OpenGL

Windows OpenGL: Setting and selecting Pixel format

FunnyPR 2014. 4. 19. 14:19

◆ 윈도우즈 OPENGL - 픽셀 포맷 설정 


필요에 맞는 픽셀 포맷을 찾기 위해 모든 픽셀 포맷을 나열하고 하나씩 확인하는 과정은 상당히 복잡함

따라서 단축함수 ChoosePixelFormat를 제공

 - 먼저 사용자가 원하는 3D 창의 속성들을 포함하는 픽셀 포맷 구조체를 만듬

 - ChoosePixelFormat는  만들어진 사용자 요구 픽셀 포맷 구조체에 가장 유사한 픽셀 포맷을 찾아 이에 해당하는 Index를 리턴함

 - 이 index를 SetPixelFormat에 전달하여 픽셀 포맷을 지정함


[step 1] 원하는 PIXELFORMATDESCRIPTOR을 만듬

[step 2] ChoosePixelFormat 로 유사한 픽셀 포맷 Index를 얻음

[step 3] SetPixelFormat에 획득한 index를 넣어 픽셀 포맷을 지정


----소스 코드 

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
// Select the pixel format for a given device context
void SetDCPixelFormat(HDC hDC)
    {
    int nPixelFormat;  
 
    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
        8,                                // Want 8 bit color 
        0,0,0,0,0,0,                    // Not used to select mode
        0,0,                            // Not used to select mode
        0,0,0,0,0,                        // Not used to select mode
        16,                                // Size of depth buffer
        0,                                // Not used to select mode
        0,                                // Not used to select mode
        PFD_MAIN_PLANE,                    // Draw in main plane
        0,                                // Not used to select mode
        0,0,0 };                        // Not used to select mode
 
    // Choose a pixel format that best matches that described in pfd
    nPixelFormat = ChoosePixelFormat(hDC, &pfd);
 
    // Set the pixel format for the device context
    SetPixelFormat(hDC, nPixelFormat, &pfd);
    }