?? glframework.cpp
字號:
/*
glframework.cpp - OpenGL framework
Copyright (c) HalfLucifer, 2001.6.20
*/
#include "glframework.h"
bool SetScreenResolution(int width, int height, int bpp)
{
DEVMODE ScreenSettings;
ZeroMemory(&ScreenSettings, sizeof(DEVMODE));
ScreenSettings.dmSize = sizeof(DEVMODE);
ScreenSettings.dmPelsWidth = width;
ScreenSettings.dmPelsHeight = height;
ScreenSettings.dmBitsPerPel = bpp;
ScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings (&ScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
return FALSE;
return TRUE;
}
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
return 0;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
switch (wParam)
{
case SIZE_MINIMIZED:
VISIBLE_FLAG = false;
return 0;
case SIZE_MAXIMIZED:
VISIBLE_FLAG = true;
glReshape(LOWORD(lParam), HIWORD(lParam));
return 0;
case SIZE_RESTORED:
VISIBLE_FLAG = true;
glReshape(LOWORD(lParam), HIWORD(lParam));
return 0;
}
break;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
bool glCreateWindow(char *title, int width, int height, int bpp, bool fsflag)
{
unsigned int PixelFormat;
WNDCLASS WindowClass;
DWORD WindowExStyle;
DWORD WindowStyle;
RECT WindowRect;
WindowRect.left = (long)0;
WindowRect.top = (long)0;
WindowRect.right = (long)width;
WindowRect.bottom = (long)height;
FULLSCREEN_FLAG = fsflag;
hInstance = GetModuleHandle(NULL);
WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
WindowClass.lpfnWndProc = (WNDPROC) WindowProcedure;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = hInstance;
WindowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WindowClass.hbrBackground = NULL;
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = "OpenGLFrameWork";
if (!RegisterClass(&WindowClass))
{
MessageBox(NULL,"RegisterClass() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (fsflag)
{
if (!SetScreenResolution(width, height, bpp))
{
MessageBox(HWND_DESKTOP, "SetScreenResolution() Error", "ERROR", MB_OK | MB_ICONEXCLAMATION);
FULLSCREEN_FLAG = false;
}
else
{
ShowCursor(FALSE);
WindowStyle = WS_POPUP;
WindowExStyle = WS_EX_APPWINDOW;
}
}
else
{
WindowStyle = WS_OVERLAPPEDWINDOW;
WindowExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
AdjustWindowRectEx(&WindowRect, WindowStyle, 0, WindowExStyle);
}
if ( !( hWnd = CreateWindowEx( WindowExStyle,
"OpenGLFrameWork",
title,
WindowStyle |
WS_CLIPSIBLINGS |
WS_CLIPCHILDREN,
0, 0,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
NULL,
NULL,
hInstance,
NULL ) ) )
{
glDestroyWindow();
MessageBox(NULL,"CreateWindowEx() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of the pixel format descriptor
1, // Version number
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
bpp, // Select 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, // Accumulation bits ignored
16, // 16bits Z-buffer (depth buffer)
0, // No stencil buffer
0, // No auxiliary buffer
PFD_MAIN_PLANE, // Main drawing layer
0, // Reserved
0, 0, 0 // Layer masks ignored
};
if (!(hDC=GetDC(hWnd)))
{
glDestroyWindow();
MessageBox(NULL,"GetDC() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
glDestroyWindow();
MessageBox(NULL,"ChoosePixelFormat() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd))
{
glDestroyWindow();
MessageBox(NULL,"SetPixelFormat() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!(hRC=wglCreateContext(hDC)))
{
glDestroyWindow();
MessageBox(NULL,"wglCreateContext() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if(!wglMakeCurrent(hDC,hRC))
{
glDestroyWindow();
MessageBox(NULL,"wglMakeCurrent() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
glReshape(width, height);
VISIBLE_FLAG = true;
return true;
}
bool glDestroyWindow(void)
{
if (FULLSCREEN_FLAG)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(true);
}
if (hWnd != NULL)
{
if (hDC != NULL)
{
wglMakeCurrent(hDC, NULL);
if (hRC != NULL)
{
wglDeleteContext(hRC);
hRC = NULL;
}
ReleaseDC (hWnd, hDC);
hDC = NULL;
}
DestroyWindow (hWnd);
hWnd = NULL;
}
UnregisterClass("OpenGLFrameWork", hInstance);
return true;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
bool fsflag = true;
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
fsflag = false;
if (glCreateWindow("HalfLucifer's OpenGL Framework", 800, 600, 32, fsflag))
{
if (!glInitialize())
{
glDestroyWindow();
MessageBox(NULL,"glInitialize() Error","ERROR",MB_OK|MB_ICONEXCLAMATION);
}
else
{
while (!PROGRAM_QUIT)
{
if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE) != 0)
{
if (msg.message != WM_QUIT)
DispatchMessage(&msg);
else
PROGRAM_QUIT = true;
}
else
{
if (VISIBLE_FLAG == false)
WaitMessage();
else
{
// Begin of application main loop
glDrawScene(); // Draw Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
// End of application main loop
}
}
}
}
}
glDestroyWindow();
return (msg.wParam);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -