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
|
#include <windows.h>
#include <gl/GL.h>
//ne pas oublier de linker avec OpenGL32.lib
...
//dans n'importe quelle fonction (pas forcément OnPaint), si on veut dessiner dans l'objet toto
System::Drawing::Graphics^ graphics - toto->CreateGraphics();
HDC hdc = static_cast<HDC>(graphics->GetHdc().ToPointer());
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int iPixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, iPixelFormat, &pfd);
HGLRC oglgc = wglCreateContext(hdc);
wglMakeCurrent(hdc, oglgc);
//...ici vous faites votre tambouille en OpenGL...
//...
wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
wglDeleteContext(oglgc);
graphics->ReleaseHdc(System::IntPtr(hdc)); |