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
| void __fastcall TForm1::InitOpenGL()
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), //taille du descripteur de format
1, //version
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, //Propriété
PFD_TYPE_RGBA, //Mode de couleurs
16, //Bits de couleur
0, 0, 0, 0, 0, 0, //Paramètres des couleurs
0,0, //Paramètres alpha
0,0, 0, 0, 0, //Paramètres du buffer d'accumulation
32, //Bits de profondeur
0, //Bits du buffer stencil
0, //Nombre de buffers auxiliaires
0, //ignoré (obsolète)
0, //réservé/code>
0, //ignoré (obsolète)
0, //Couleur de transparence
0 //Ignoré (obsolète)
};
int pixelFormat;
pixelFormat = [b]ChoosePixelFormat(hDC, &pfd);[/b]
if (!pixelFormat)
{
MessageBox
(
WindowFromDC(hDC),
"Mode graphique non supporté",
"Problème",
MB_ICONERROR | MB_OK
);
exit(1);
/*Vérifie si un PixelFormat du type demandé existe*/
}
if (!SetPixelFormat(hDC, pixelFormat, &pfd))
{
MessageBox
(
WindowFromDC(hDC),
"Mode graphique non supporté",
"Problème",
MB_ICONERROR | MB_OK
);
exit(1);
/*Applique le PixelFormat. Arrête si erreur*/
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hDC=GetDC(Handle);
[b]InitOpenGL();[/b]
rc = wglCreateContext(hDC);
wglMakeCurrent(hDC,rc);
glEnable(GL_DEPTH_TEST);
} |