Voilà, je travaille actuellement sur l'amélioration d'unmoteur 3D passant par une machine virtuelle qui lance une fenêtre mère sur laquelle vient se placer une fenêtre OpenGL comme fenêtre fille.
Je désire implémenter le multisampling pour un antialias de toute la scène,
cependant il m'est impossible de créer un contexte avec une fenêtre par défaut puis de vérifier l'extension pour le multisampling pour supprimer la fenêtre et la recréer après avoir implémenter le multisampling,
Voici un bout du code qui déterminer le contexte openGL du moteur,
Je vous remercie d'avance pour tout conseil..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 //////////////////////////////////////////////////////////////////////////////////////////////
///        CreateMainContext                                                        
//////////////////////////////////////////////////////////////////////////////////////////////
 
HGLRC CreateMainContext()
{
 
      // On définit le context par défault !!
 
    MMechostr ( 1, " ************Définition du Contexte par default!! ********************\n" ) ;
    ZDetector detect ;
    int        pf=0;
    HDC        hdc ;
    PIXELFORMATDESCRIPTOR pfd;
    HWND    hwnd = CreateWindow("scolGL", "scolGL", WS_CHILD, 0, 0, 1, 1, HScol, NULL, NULL, 0);
    hdc = GetDC(hwnd);
    MMechostr(1," *********************** Format de pixel par défaut *********************\n") ;
 
 
        ZeroMemory(&pfd, sizeof(pfd));
        pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
        pfd.nVersion = 1;
        pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_TYPE_RGBA|WGL_SAMPLE_BUFFERS_EXT|WGL_SAMPLES_EXT ;
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.cColorBits = 32;
        pfd.cDepthBits = 32;
        pfd.cRedBits = 0;
        pfd.cRedShift = 0;
        pfd.cGreenBits = 0;
        pfd.cGreenShift = 0;
        pfd.cBlueBits = 0;
        pfd.cBlueShift = 0;
        pfd.cAlphaBits = 0;
        pfd.cAlphaShift = 0;
        pfd.cAccumBits = 0;
        pfd.cAccumRedBits = 0;
        pfd.cAccumGreenBits = 0;
        pfd.cAccumBlueBits = 0;
        pfd.cAccumAlphaBits = 0;
        pfd.cStencilBits = 0;
        pfd.cAuxBuffers = 0;
        pfd.iLayerType = PFD_MAIN_PLANE;
        pfd.bReserved = 0;
        pfd.dwLayerMask = 0;
        pfd.dwVisibleMask = 0;
        pfd.dwDamageMask = 0;
 
 
    // On créer le contexte OpenGl par défaut
 
        MMechostr(1, "***************** Contexte openGL par defaut!!!****************************\n") ;
            if(!(pf = ChoosePixelFormat(hdc, &pfd)))
                    {
                         MMechostr(1, "Failed to choose pixel format." );
                         return NULL;
                     }
 
                if(!SetPixelFormat(hdc, pf, &pfd))
                     {
                         MMechostr(1, "Failed to set pixel format." );
                        return NULL ;
                    }
 
            mainBPP        = 1;
            mainDEPTH    = pfd.cColorBits;
            mainDBLBUF    = 1;
            mainPIXELFORMAT = pf;
            mainhdc     = hdc;
 
            mainglrc = wglCreateContext(hdc);
 
            if(wglGetCurrentContext()!=mainglrc)        wglMakeCurrent(hdc,mainglrc);
        if ( detect.WGLisExtensionSupported ("GL_ARB_multisample") == false)
        {
            MMechostr(1, "***************** Le multisampling n'est pas pris en charge****************************\n") ;
            arbMultisampleSupported = false ;
            mainhwnd = hwnd;
            return mainglrc ;
        }
        // Création du nouveau contexte avec prise en charge du multisampling
 
    if ( detect.WGLisExtensionSupported ("GL_ARB_multisample") == true)
        {
            MMechostr(1, "***************** Le format de pixel multisampling est pris en charge!!!****************************\n") ;    
            arbMultisampleSupported = true ;
            int        valid;
            UINT    numFormats;
            float    fAttributes[] = {0,0};
 
            int iAttributes[] =
        {
            WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
            WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
            WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
            WGL_COLOR_BITS_ARB,24,
            WGL_ALPHA_BITS_ARB,8,
            WGL_DEPTH_BITS_ARB,16,
            WGL_STENCIL_BITS_ARB,0,
            WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
            WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
            WGL_SAMPLES_ARB,4,
            0,0
        };
 
        PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
            MMechostr(1, "--> Chargement du process : OK\n" );
        // First We Check To See If We Can Get A Pixel Format For 4 Samples
        valid = wglChoosePixelFormatARB(hdc,iAttributes,fAttributes,1,&pf,&numFormats) ;
            mainBPP        = 1;
            mainDEPTH    = pfd.cColorBits;
            mainDBLBUF    = 1;
            mainPIXELFORMAT = pf;
            mainhdc     = hdc;
            mainglrc = wglCreateContext(hdc);
            if(wglGetCurrentContext()!=mainglrc)        wglMakeCurrent(hdc,mainglrc);
 
    if(mainglrc)
    {
        if(wglMakeCurrent(NULL,NULL)==FALSE)        MMechostr(1, "------ Can't set the current rendering context to NULL ! ------\n" );
 
        if(wglDeleteContext(mainglrc)==FALSE)        MMechostr(1, "------ Can't delete the MAIN rendering context ! ------\n" );
        else                                        MMechostr(1, "--> mainglrc released : OK\n" );
    }
 
    if(mainhdc) 
    {
        if(ReleaseDC(mainhwnd, mainhdc)==0)            MMechostr(1, "------ Can't release the MAIN device context ! ------\n" );
        else                                        MMechostr(1, "--> mainhdc released : OK\n" );
    }
 
    if(mainhwnd)
    {
        if(DestroyWindow(mainhwnd)==0)                MMechostr(1, "------ Can't destroy the MAIN window ! ------\n" );
        else                                        MMechostr(1, "--> mainhwnd released : OK\n" );
    }
 
            mainhwnd = hwnd;
            return mainglrc ;
            return mainglrc ;
    }
 
 
}