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
|
int COpenGLControl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
char* extensions = NULL;
if (CWnd::OnCreate(lpCreateStruct) == -1) return -1;
// Initial Setup:
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32, // bit depth
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16, // z-buffer depth
0, 0, 0, 0, 0, 0, 0,
};
// Get device context only once.
m_hdc = GetDC()->m_hDC;
// Pixel format.
m_nPixelFormat = ChoosePixelFormat(m_hdc, &pfd);
SetPixelFormat(m_hdc, m_nPixelFormat, &pfd);
// Setup the OpenGL Window's timer to render
m_uipTimer = SetTimer(1, 1, NULL);
// Create the OpenGL Rendering Context.
m_hrc = wglCreateContext(m_hdc);
wglMakeCurrent(m_hdc, m_hrc);
SetCursor(LoadCursor(NULL, IDC_ARROW));
// Enable/Disable the vertical synchronization
extensions = (char*)glGetString(GL_EXTENSIONS);
if (strstr(extensions, "WGL_EXT_swap_control"))
{
//MessageBox(extensions);
wglSwapInterval = reinterpret_cast<PFNWGLSWAPINTERVALEXT>(wglGetProcAddress("wglSwapIntervalEXT"));
wglGetSwapInterval = reinterpret_cast<PFNWGLGETSWAPINTERVALEXT>(wglGetProcAddress("wglGetSwapIntervalEXT"));
wglSwapInterval(1);
//if (wglGetSwapInterval() > 0) MessageBox("Synchronisation Verticale activée");
}
oglInitialize();
return 0;
} |