dm.dmPelsWidth = gInfo.resWidth;
dm.dmPelsHeight = gInfo.resHeight;
dm.dmBitsPerPel = gInfo.bpp;
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
return ChangeDisplaySettings (&dm, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
}
bool CreateGLWindow()
{
DWORD
style = WS_OVERLAPPEDWINDOW,
exStyle = WS_EX_APPWINDOW; // Forces a top-level window onto the taskbar when the window is visible
int width = gInfo.width, // Prepare to windowed mode
height = gInfo.height;
RECT rect = {0, 0, width, height};
AdjustWindowRectEx (&rect, style, 0, exStyle); // Account For Window Borders
if (gInfo.bFull) // Switch to full screen mode if needed
{
if (ToFullScreen()) // If the switch was successful
{
ShowCursor (FALSE);
style = WS_POPUP;
exStyle |= WS_EX_TOPMOST;
width = gInfo.resWidth;
height = gInfo.resHeight;
}
else
{
MessageBox (HWND_DESKTOP,
"Full Screen Mode Failed.\nRunning In Windowed Mode.",
"Error", MB_OK | MB_ICONEXCLAMATION);
gInfo.bFull = false;
}
}
//==== Desktop Is Window's Parent
gInfo.hWnd = CreateWindowEx (exStyle, gInfo.cls, gInfo.title, style,
0, 0, width, height, HWND_DESKTOP, 0, gInfo.hInst, &gInfo);
if (gInfo.hWnd == 0)
return false;
gInfo.hDC = GetDC (gInfo.hWnd); // Grab A Device Context For This Window
if (gInfo.hDC == 0)
{
DestroyWindow (gInfo.hWnd);
gInfo.hWnd = 0;
return false;
}
PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
gInfo.bpp, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, 0, 0, 0, 0, 0, 0,
24, // 24 Bit Z-Buffer (Depth Buffer)
0, 0, 0, 0, 0, 0, 0
};
UINT fmt = ChoosePixelFormat (gInfo.hDC, &pfd);
if (fmt == 0)
{
ReleaseDC (gInfo.hWnd, gInfo.hDC);
gInfo.hDC = 0;
DestroyWindow (gInfo.hWnd);
gInfo.hWnd = 0;
return false;
}
if (SetPixelFormat (gInfo.hDC, fmt, &pfd) == FALSE)
{
ReleaseDC (gInfo.hWnd, gInfo.hDC);
gInfo.hDC = 0;
DestroyWindow (gInfo.hWnd);
gInfo.hWnd = 0;
return false;
}
gInfo.hRC = wglCreateContext (gInfo.hDC);
if (gInfo.hRC == 0)
{
ReleaseDC (gInfo.hWnd, gInfo.hDC);
gInfo.hDC = 0;
DestroyWindow (gInfo.hWnd);
gInfo.hWnd = 0;
return false;
}
if (wglMakeCurrent (gInfo.hDC, gInfo.hRC) == FALSE)
{
wglDeleteContext (gInfo.hRC);
gInfo.hRC = 0;
ReleaseDC (gInfo.hWnd, gInfo.hDC);
gInfo.hDC = 0;
DestroyWindow (gInfo.hWnd);
gInfo.hWnd = 0;
return false;
}
ShowWindow (gInfo.hWnd, SW_NORMAL);
gInfo.bVisible = true;
Resize (width, height);
ZeroMemory (gInfo.keys, sizeof (gInfo.keys)); // Clear All Keys
gInfo.ticks = GetTickCount (); // Get Tick Count
return true;
}
BOOL DestroyGLWindow ()// Destroy The OpenGL Window & Release Resources
{
if (gInfo.hWnd != 0)
{
if (gInfo.hDC != 0)
{
wglMakeCurrent (gInfo.hDC, 0);
if (gInfo.hRC != 0)
{
wglDeleteContext (gInfo.hRC);
gInfo.hRC = 0;
}
ReleaseDC (gInfo.hWnd, gInfo.hDC);
gInfo.hDC = 0;
}
DestroyWindow (gInfo.hWnd);
gInfo.hWnd = 0;
}
if (!gInfo.bFull)
{
ChangeDisplaySettings (0, 0);// Switch Back To Desktop Resolution
ShowCursor (TRUE);
}
return true;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
// Prevent From Starting Screensaver & Monitor Entering to Powersave
case WM_SYSCOMMAND:
if (wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER)
return 0; // This message is handled
break; // This message is not handled
case WM_CLOSE:
gInfo.bQuit = true;
PostMessage (hWnd, WM_QUIT, 0, 0);
return 0; // Handled
case WM_SIZE:
switch (wParam)
{
case SIZE_MINIMIZED:
gInfo.bVisible = false;
return 0;
case SIZE_MAXIMIZED:
gInfo.bVisible = true;
Resize (LOWORD(lParam), HIWORD(lParam));
return 0;
case SIZE_RESTORED:
gInfo.bVisible = true;
if (!gInfo.bFull)
{
gInfo.width = LOWORD(lParam);
gInfo.height = HIWORD(lParam);
}
Resize (LOWORD (lParam), HIWORD (lParam));
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.