本文整理汇总了C++中KillGLWindow函数的典型用法代码示例。如果您正苦于以下问题:C++ KillGLWindow函数的具体用法?C++ KillGLWindow怎么用?C++ KillGLWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了KillGLWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetModuleHandle
// 创建Render环境
int RenderClass::CreaterRender(const wchar_t *windows_name)
{
GLuint PixelFormat; // 保存查找匹配的结果
WNDCLASS wc; // 窗口类结构
DWORD dwExStyle; // 扩展窗口风格
DWORD dwStyle; // 窗口风格
RECT WindowRect; // 取得矩形的左上角和右下角的坐标值
WindowRect.left=(long)0; // 将Left 设为 0
WindowRect.right=(long)width_; // 将Right 设为要求的宽度
WindowRect.top=(long)0; // 将Top 设为 0
WindowRect.bottom=(long)height_; // 将Bottom 设为要求的高度
hinstance_ = GetModuleHandle(NULL); // 取得我们窗口的实例
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // 移动时重画,并为窗口取得DC
wc.lpfnWndProc = (WNDPROC) window_sun_proc_; // WndProc处理消息
wc.cbClsExtra = 0; // 无额外窗口数据
wc.cbWndExtra = 0; // 无额外窗口数据
wc.hInstance = hinstance_; // 设置实例
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // 装入缺省图标
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // 装入鼠标指针
wc.hbrBackground = NULL; // GL不需要背景
wc.lpszMenuName = NULL; // 不需要菜单
wc.lpszClassName = L"OpenGL"; // 设定类名字
if (!RegisterClass(&wc)) // 尝试注册窗口类
{
MessageBox(NULL,L"注册窗口失败",L"错误",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // 退出并返回FALSE
}
if (full) // 要尝试全屏模式吗?
{
DEVMODE dmScreenSettings; // 设备模式
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // 确保内存清空为零
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Devmode 结构的大小
dmScreenSettings.dmPelsWidth = width_; // 所选屏幕宽度
dmScreenSettings.dmPelsHeight = height_; // 所选屏幕高度
dmScreenSettings.dmBitsPerPel = 32; // 每象素所选的色彩深度
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// 尝试设置显示模式并返回结果。注: CDS_FULLSCREEN 移去了状态条。
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// 若模式失败,提供两个选项:退出或在窗口内运行。
if (MessageBox(NULL,L"全屏模式在当前显卡上设置失败!\n使用窗口模式?",L" G",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
full=FALSE; // 选择窗口模式(Fullscreen=FALSE)
}
else
{
// 弹出一个对话框,告诉用户程序结束
MessageBox(NULL,L"程序将被关闭",L"错误",MB_OK|MB_ICONSTOP);
return FALSE; // 退出并返回 FALSE
}
}
}
if (full) // 仍处于全屏模式吗?
{
dwExStyle=WS_EX_APPWINDOW; // 扩展窗体风格
dwStyle=WS_POPUP; // 窗体风格
ShowCursor(FALSE); // 隐藏鼠标指针
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // 扩展窗体风格
dwStyle=WS_OVERLAPPEDWINDOW; // 窗体风格
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // 调整窗口达到真正要求的大小
if (!(hwnd_=CreateWindowEx( dwExStyle, // 扩展窗体风格
L"OpenGL", // 类名字
windows_name, // 窗口标题
WS_CLIPSIBLINGS | // 必须的窗体风格属性
WS_CLIPCHILDREN | // 必须的窗体风格属性
dwStyle, // 选择的窗体属性
0, 0, // 窗口位置
WindowRect.right-WindowRect.left, // 计算调整好的窗口宽度
WindowRect.bottom-WindowRect.top, // 计算调整好的窗口高度
NULL, // 无父窗口
NULL, // 无菜单
hinstance_, // 实例
NULL))) // 不向WM_CREATE传递任何东东
{
KillGLWindow(); // 重置显示区
MessageBox(NULL,L"不能创建一个窗口设备描述表",L"错误",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // 返回 FALSE
}
static PIXELFORMATDESCRIPTOR pfd= // /pfd 告诉窗口我们所希望的东东,即窗口使用的像素格式
{
sizeof(PIXELFORMATDESCRIPTOR), // 上述格式描述符的大小
1, // 版本号
PFD_DRAW_TO_WINDOW | // 格式支持窗口
PFD_SUPPORT_OPENGL | // 格式必须支持OpenGL
PFD_DOUBLEBUFFER, // 必须支持双缓冲
PFD_TYPE_RGBA, // 申请 RGBA 格式
32, // 选定色彩深度
0, 0, 0, 0, 0, 0, // 忽略的色彩位
0, // 无Alpha缓存
//.........这里部分代码省略.........
示例2: AdjustWindowRect
bool CoreWindow::createWindow(int x, int y, int width, int height, const TCHAR* title, bool fullscreenmode)
{
WNDCLASS wc;
HWND hWnd;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left = 0;
WindowRect.right = width;
WindowRect.top = 0;
WindowRect.bottom = height;
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
if (fullscreenmode)
dwStyle = WS_POPUPWINDOW | WS_MAXIMIZE;
else
dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
AdjustWindowRect(&WindowRect, dwStyle, FALSE);
if (!GetClassInfo(GetModuleHandle(NULL), _TX("CoreWindow_wgl"), &wc))
{
// memset(&wcx, 0, sizeof(WNDCLASSEX));
// wcx.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) CoreWindow::BaseWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = 0;
wc.lpszClassName = _TX("CoreWindow_wgl");
if (!RegisterClass(&wc))
{
MessageBox(NULL,_TX("Failed To Register The Window Class."),_TX("ERROR"),MB_OK|MB_ICONEXCLAMATION);
ExitProcess(0);
return FALSE;
}
}
hWnd = CreateWindowEx(dwExStyle,
_TX("CoreWindow_wgl"),
title,
dwStyle,
x, y,
WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top,
NULL,
NULL,
GetModuleHandle(NULL),
(void*)this);//BaseWndProcにthisを渡してやる
if (!hWnd)
{
KillGLWindow();
MessageBox(NULL,_TX("Window Creation Error."),_TX("ERROR"),MB_OK|MB_ICONEXCLAMATION);
ExitProcess(0);
return FALSE;
}
// ウィンドウハンドルとCWindowBaseオブジェクトを結びつける
SetProp(hWnd, _TX("CoreWindow_wgl"), (HANDLE)this);
m_hWnd = hWnd;
if (!g_mainWin)
g_mainWin = this;
return TRUE;
}
示例3: WinMain
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
BOOL done=FALSE;
// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE; // Windowed Mode
}
// Create Our OpenGL Window
if (!CreateGLWindow("NeHe's Solid Object Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE;
}
else
{
SwapBuffers(hDC);
}
if (keys[VK_F1])
{
keys[VK_F1]=FALSE;
KillGLWindow();
fullscreen=!fullscreen;
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's Solid Object Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
示例4: WinMain
//.........这里部分代码省略.........
done = TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
if (keys['L'] && !lp)
{
lp = TRUE;
light = !light;
if (!light)
{
glDisable(GL_LIGHTING);
}
else
{
glEnable(GL_LIGHTING);
}
}
if (!keys['L'])
{
lp = FALSE;
}
if (keys['F'] && !fp)
{
fp = TRUE;
filter += 1;
if (filter>2)
{
filter = 0;
}
}
if (!keys['F'])
{
fp = FALSE;
}
if (keys[VK_PRIOR])
{
z -= 0.02f;
}
if (keys[VK_NEXT])
{
z += 0.02f;
}
if (keys[VK_UP])
{
xspeed -= 0.01f;
}
if (keys[VK_DOWN])
{
xspeed += 0.01f;
}
if (keys[VK_RIGHT])
{
yspeed += 0.01f;
}
if (keys[VK_LEFT])
{
yspeed -= 0.01f;
}
// Blending Code Starts Here
if (keys['B'] && !bp)
{
bp = TRUE;
blend = !blend;
if (blend)
{
glEnable(GL_BLEND); // Turn Blending On
glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off
}
else
{
glDisable(GL_BLEND); // Turn Blending Off
glEnable(GL_DEPTH_TEST); // Turn Depth Testing On
}
}
if (!keys['B'])
{
bp = FALSE;
}
// Blending Code Ends Here
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1] = FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen = !fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("Tom Stanis & NeHe's Blending Tutorial", 640, 480, 16, fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
示例5: GetModuleHandle
BOOL OpenGLWindow::CreateGLWindow()
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = &OpenGLWindow::WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = (LPCWSTR)"OpenGL"; // Set The Class Name
::TlsSetValue(s_tlsIndex, this);
if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,(LPCWSTR)"Failed To Register The Window Class.", (LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
(LPCWSTR)"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Window Creation Error.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
DeleteMenu(GetSystemMenu(hWnd, false), SC_CLOSE, MF_BYCOMMAND); //Deactivate Closing by x-Button
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This 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
bits, // Select Our 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, // 16Bit 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))) // Did We Get A Device Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Can't Create A GL Device Context.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Can't Find A Suitable PixelFormat.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Can't Set The PixelFormat.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
//.........这里部分代码省略.........
示例6: WinMain
int WINAPI WinMain( HINSTANCE hInstance, // 当前窗口实例
HINSTANCE hPrevInstance, // 前一个窗口实例
LPSTR lpCmdLine, // 命令行参数
int nCmdShow) // 窗口显示状态
{
MSG msg; // Windowsx消息结构
BOOL done=FALSE; // 用来退出循环的Bool 变量
// 提示用户选择运行模式
if (MessageBox(NULL,"你想在全屏模式下运行么?", "设置全屏模式",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE; // FALSE为窗口模式
}
// 创建OpenGL窗口
if (!CreateGLWindow("OpenGL程序加速样例",640,480,16,fullscreen))
{
return 0; // 失败退出
}
while(!done) // 保持循环直到 done=TRUE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))// 有消息在等待吗?
{
if (msg.message==WM_QUIT) // 收到退出消息?
{
done=TRUE; // 是,则done=TRUE
}
else // 不是,处理窗口消息
{
TranslateMessage(&msg); // 翻译消息
DispatchMessage(&msg); // 发送消息
}
}
else // 如果没有消息
{
// 绘制场景。监视ESC键和来自DrawGLScene()的退出消息
if (active) // 程序激活的么?
{
if (keys[VK_ESCAPE]) // ESC 按下了么?
{
done=TRUE; // ESC 发出退出信号
}
else // 不是退出的时候,刷新屏幕
{
DrawGLScene(); // 绘制场景
SwapBuffers(hDC); // 交换缓存 (双缓存)
if (keys[VK_LEFT]) // 左键是否按下
{
yrot-=0.2f; // 如果是,向左旋转
}
if (keys[VK_RIGHT]) // 右键是否按下
{
yrot+=0.2f; // 如果是向右旋转
}
if (keys[VK_UP]) // 上键是否按下
{
xrot-=0.2f; // 如果是向上旋转
}
if (keys[VK_DOWN]) // 下键是否按下
{
xrot+=0.2f; // 如果是向下旋转
}
}
}
if (keys[VK_F1]) // F1键按下了么?
{
keys[VK_F1]=FALSE; // 若是,使对应的Key数组中的值为 FALSE
KillGLWindow(); // 销毁当前的窗口
fullscreen=!fullscreen; // 切换 全屏 / 窗口 模式
// 重建 OpenGL 窗口(修改)
if (!CreateGLWindow("OpenGL旋转实例",640,480,16,fullscreen))
{
return 0; // 如果窗口未能创建,程序退出
}
}
}
}
// 关闭程序
KillGLWindow(); // 销毁窗口
return (msg.wParam); // 退出程序
}
示例7: CreateGLWindow
BOOL CreateGLWindow(HWND hWnd, HDC *phDC, HGLRC *phRC)
{
GLuint nPixelFormat; // Holds The Results After Searching For A Match
RECT rect;
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This 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
0, // Select Our 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
0, // 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 (!(*phDC = GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Create A GL Device Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!(nPixelFormat = ChoosePixelFormat(*phDC, &pfd)))// Did Windows Find A Matching Pixel Format?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Find A Suitable PixelFormat."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!SetPixelFormat(*phDC, nPixelFormat, &pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Set The PixelFormat."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!(*phRC = wglCreateContext(*phDC))) // Are We Able To Get A Rendering Context?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Create A GL Rendering Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!wglMakeCurrent(*phDC, *phRC)) // Try To Activate The Rendering Context
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Activate The GL Rendering Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
GetClientRect(hWnd, &rect);
ReSizeGLScene(rect.right, rect.bottom); // Set Up Our Perspective GL Screen
if (!InitGL()) // Initialize Our Newly Created GL Window
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Initialization Failed."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
return TRUE; // Success
}
示例8: ScreenSaverProc
EXTERN_C LONG WINAPI ScreenSaverProc(
HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
{
static HDC hDC = NULL; // Private GDI Device Context
static HGLRC hRC = NULL; // Permanent Rendering Context
static int nState;
static int nFrames;
switch (uMsg) // Check For Windows Messages
{
case WM_CREATE:
{
// Load settings
CCuckooSettings settings;
settings.Load();
// Load clock
switch (settings.GetClockType())
{
case 2: // Mickey
g_pClock = new CClockMickey;
break;
case 1: // Wesminster
g_pClock = new CClockWestminster;
break;
case 0: // Cuckoo
g_pClock = new CClockCuckoo;
break;
default: // Error
MessageBox(hWnd, _T("Unknown clock: Please configure the screen saver.\n\nHorloge inconnue: Veuillez reconfigurer l'écran de veille."), _T("Cuckoo"), MB_ICONEXCLAMATION);
return -1;
}
if (g_pClock == NULL)
{
MessageBox(hWnd, _T("Not enought memory to load the clock."), _T("Cuckoo"), MB_ICONERROR);
return -1;
}
// Initialize OpenGL on hWnd.
if (!CreateGLWindow(hWnd, &hDC, &hRC))
return -1;
// Starting state
nState = STATE_SWAP_TEST;
// Set timers
SetTimer(hWnd, 1, 10, NULL);
return 0;
}
case WM_DESTROY:
// Timers
KillTimer(hWnd, 1);
// Clock
if (g_pClock != NULL)
{
delete g_pClock;
g_pClock = NULL;
}
// OpenGL
KillGLWindow(hWnd, hDC, hRC);
return 0;
case WM_TIMER:
switch (nState)
{
case STATE_SWAP_TEST:
// Check if SwapBuffers() swap or copy back to front
if (IsSwapBufferCopyingBackToFront(hDC))
g_pClock->SetSwapBufferMode(CClock::COPY_BACK_TO_FRONT);
else
g_pClock->SetSwapBufferMode(CClock::SWAP_BACK_AND_FRONT);
nState++;
break;
case STATE_INIT_CLOCK:
{
// Load settings
CCuckooSettings settings;
settings.Load();
// Clock
g_pClock->EnableSounds(settings.HasTicTacSound(), settings.BellsOnHours(), settings.BellsOnHalfHours(), settings.BellsOnQuartHours());
g_pClock->Init();
// Precise timing
g_swTimer.Init();
g_swTimer.Start();
// Frame counter
nFrames = 0;
nState++;
break;
}
case STATE_RENDER:
//.........这里部分代码省略.........
示例9: WinMain
int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop
// Ask The User Which Screen Mode They Prefer
fullscreen=true; // Fullscreen Mode
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=false;
}
// Create Our OpenGL Window
if (!CreateGLWindow("Zombie City!",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
for(int i=0; i<256; ++i) {
keys[i] = 0;
}
i_tick = float(GetTickCount()); //Set i_tick to the new tick count - so the difference does not exponentially increase
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
do
{
} while (( GetTickCount() - i_tick ) < 10 );
framelength = (GetTickCount() - i_tick) * GAMESPEED; //When the frame starts, find out how many 'ticks' have occurred since the last frame
if(framelength > 10.0f) framelength = 10.0f;
leveltime += int(GetTickCount() - i_tick);
i_tick = float(GetTickCount()); //Set i_tick to the new tick count - so the difference does not exponentially increase
i_frame+=1;
if ((i_tick_2 + 1000) < GetTickCount())
{
i_frame_rate = i_frame;
i_frame=0;
i_tick_2 = float(GetTickCount());
};
update();
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("Zombie City",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
if(end) done=true;
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
示例10: WinMain
/******************* WIN32 FUNCTIONS ***************************/
int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
bool done=false; // Bool Variable To Exit Loop
StartGame n = StartGame();
activityManager.push(&n);
console.Open();
// Create Our OpenGL Window
if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight))
{
return 0; // Quit If Window Was Not Created
}
Clock clock;
double timeSinceLastUpdate = 0.0;
Clock fpsCounterClock;
double fpsCounterTime = 0.0;
int fpsCounter = 0;
clock.start();
fpsCounterClock.start();
//*******************************************GAME LOOP***********************************************************//
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=true; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
if(keys[VK_ESCAPE])
done = true;
if (!keys[VK_RETURN]){
fpsCounterTime += fpsCounterClock.restart();
timeSinceLastUpdate += clock.restart();
while (timeSinceLastUpdate > TIME_PER_FRAME) {
fpsCounter++;
timeSinceLastUpdate -= TIME_PER_FRAME;
update(TIME_PER_FRAME);
}
if (fpsCounterTime > 1){
#ifdef displayFPS
std::cout<<"\t\t\t\t\tFPS: "<<fpsCounter<<std::endl;
#endif
fpsCounterTime = 0;
fpsCounter = 0;
}
}
display(); // Draw The Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}
console.Close();
// Shutdown
KillGLWindow(); // Kill The Window
return (int)(msg.wParam); // Exit The Program
}
示例11: WinMain
//.........这里部分代码省略.........
filter+=1;
if (filter>2)
{
filter=0;
}
}
if (!keys['F'])
{
fp=FALSE;
}*/
if (keys[VK_PRIOR])//strafe up
{
posy += 0.2f;
looky += 0.2f;
}
if (keys[VK_NEXT])//strafe down
{
posy -= 0.2f;
looky -= 0.2f;
}
if (keys[VK_UP])//look up
{
myCamera.RotateCamera(0.0f,0.03f);
//looky += 0.2f;
//xspeed-=0.1f;
}
if (keys[VK_DOWN])//look down
{
myCamera.RotateCamera(0.0f,-0.03f);
//looky -= 0.2f;
//xspeed+=0.1f;
}
if (keys[VK_RIGHT])//look right
{
myCamera.RotateCamera(0.03f,0.0f);
//lookx -= 0.5f;
//yspeed+=0.1f;
}
if (keys[VK_LEFT])//look left
{
myCamera.RotateCamera(-0.03f,0.0f);
lookx += 0.5f;
//yspeed-=0.1f;
}
if (keys['W'])//forward
{
velocity += 1;
/*posz +=0.5f;
lookz +=0.5f;*/
}
if (keys['S']) //backward
{
velocity -= 1;
/*posz -=0.5f;
lookz -=0.5f;*/
}
if (keys['A'])//strafe left
{
myCamera.SlideCamera(-10.0f,0.0f);
/*posx +=0.2f;
lookx += 0.2f;*/
}
if (keys['D'])//strafe right
{
myCamera.SlideCamera(10.0f,0.0f);
/*posx -=0.2f;
lookx -= 0.2f;*/
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow(L"NeHe's Textures, Lighting & Keyboard Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow(L"NeHe's Rotation Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
示例12: CreateGLWindow
bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds the results after searching for a match
WNDCLASS wc; // Windows class structure
DWORD dwExStyle; // Window extended style
DWORD dwStyle; // Window style
RECT WindowRect; // Grabs rctangle upper left / lower right values
WindowRect.left = (long)0; // Set left value to 0
WindowRect.right = (long)width; // Set right value to requested width
WindowRect.top = (long)0; // Set top value to 0
WindowRect.bottom = (long)height; // Set bottom value to requested height
fullscreen = fullscreenflag; // Set the global fullscreen flag
hInstance = GetModuleHandle(NULL); // Grab an instance for our window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on size, and own DC for window
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc handles messages
wc.cbClsExtra = 0; // No extra window data
wc.cbWndExtra = 0; // No extra window data
wc.hInstance = hInstance; // Set the Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the arrow pointer
wc.hbrBackground = NULL; // No background required for GL
wc.lpszMenuName = NULL; // We don't want a menu
wc.lpszClassName = "OpenGL"; // Set the class name
if (!RegisterClass(&wc)) // Attempt to register the window class
{
MessageBox(NULL,"Failed to register the window class.","Error",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
//Only a windowed style
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window extended style
dwStyle = WS_OVERLAPPEDWINDOW; // Windows style
AdjustWindowRectEx(&WindowRect,dwStyle,false,dwExStyle); // Adjust window to true requested size
// Create the window
if (!(hWnd = CreateWindowEx(dwExStyle, // Extended Style For The Window
"OpenGL", // Class name
title, // Window title
dwStyle | // Defined window style
WS_CLIPSIBLINGS | // Required window style
WS_CLIPCHILDREN, // Required window style
0, 0, // Window position
WindowRect.right-WindowRect.left, // Calculate window width
WindowRect.bottom-WindowRect.top, // Calculate window height
NULL, // No parent window
NULL, // No menu
hInstance, // Instance
NULL))) // Dont pass anything to WM_CREATE
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Window creation error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
static PIXELFORMATDESCRIPTOR pfd = // pfd tells windows how we want things to be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of this 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
bits, // Select our 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, // 16Bit 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
};
//We need to get the device context from the frames handle
//then maybe we can draw in the frame?
if (!(hDC = GetDC(hWnd))) // Did we get a device context?
//if (!(hDC = GetDC(Frame->)))
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't create a GL device context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
if (!(PixelFormat = ChoosePixelFormat(hDC,&pfd))) // Did windows find a matching pixel format?
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't find a suitable pixelformat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are we able to set the pixel format?
//.........这里部分代码省略.........
示例13: CreateGLWindow
/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Full screen Mode *
* height - Height Of The GL Window Or Full screen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Full screen Mode (TRUE) Or Windowed Mode (FALSE) */
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullScreenFlag)
{
GLuint PixelFormat; // Holds the results after searching for a match
WNDCLASS wc; // Windows class structure
DWORD dwExStyle; // Window extended style
DWORD dwStyle; // Window style
RECT WindowRect; // Grabs rectangle upper left/lower right values
WindowRect.left = (long)0; // Set left value to 0
WindowRect.right = (long)width; // Set right value to requested width
WindowRect.top = (long)0; // Set top value to 0
WindowRect.bottom = (long)height; // Set bottom value to requested height
g_bFullscreen = fullScreenFlag; // Set the global full screen flag
hInstance = GetModuleHandle(NULL); // Grab an instance for out window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on size, and own DC for window
wc.lpfnWndProc = (WNDPROC)WndProc; // WndProc handles messages
wc.cbClsExtra = 0; // No extra window data
wc.cbWndExtra = 0; // No extra window data
wc.hInstance = hInstance; // Set the instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the arrow pointer
wc.hbrBackground = NULL; // No background required for GL
wc.lpszMenuName = NULL; // We don't want a menu
wc.lpszClassName = CLASSNAME; // Set the class name
if (!RegisterClass(&wc)) // Attempt to register the window class
{
MessageBox(NULL, MSG_REGISTERCLASSFAILED,
ERR_ERROR, MB_OK | MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (g_bFullscreen)
{
DEVMODE dmScreenSettings; // Device mode
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); // Makes sure memory's cleared
dmScreenSettings.dmSize = sizeof(dmScreenSettings); // Size of the devmode structure
dmScreenSettings.dmPelsWidth = width; // Selected screen width
dmScreenSettings.dmPelsHeight = height; // Selected screen height
dmScreenSettings.dmBitsPerPel = bits; // Selected bits per pixel
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
// If the mode failed, offer two options. Quit or use windowed mode.
if (MessageBox(NULL, MSG_FULLSCREENNOTSUPPORT,
ARTIST_NAME, MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
{
g_bFullscreen = FALSE; // Windowed mode selected. Fullscreen = FALSE
}
else
{
// Pop up a message box letting user know the program is closing.
MessageBox(NULL, MSG_PROGRAMNOTCLOSE,
ERR_ERROR, MB_OK | MB_ICONSTOP);
return FALSE; // Return FALSE
}
}
}
if (g_bFullscreen) // Are we still in fullscreen mode?
{
dwExStyle = WS_EX_APPWINDOW; // Window extended style
dwStyle = WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide mouse pointer
}
else
{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Windows Extended style
dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust window to true requested size
// Create the window
if (!(hWnd = CreateWindowEx(dwExStyle, // Extended style for the window
CLASSNAME, // Class name
title, // Window title
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, // Defined window style
0, 0, // Window position
WindowRect.right - WindowRect.left, // Calculate window width
WindowRect.bottom - WindowRect.top, // Calculate window height
NULL, // No parent window
NULL, // No menu
hInstance, // Instance
NULL))) // Don't pass anything to WM_CREATE
{
KillGLWindow(); // Reset the display
MessageBox(NULL, MSG_CREATEWINDOWFAILED,
ERR_ERROR, MB_OK | MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
static PIXELFORMATDESCRIPTOR pfd = // pfd tells widows how we want things to be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of this pixel format descriptor
1, // Version number
//.........这里部分代码省略.........
示例14: WinMain
//.........这里部分代码省略.........
{
translatez-=0.01f;
}
if (keys['A'] )
{
rotatey+=0.01f;
}
if (keys['D'] )
{
rotatey-=0.01f;
}
if (keys[VK_UP] )
{
rotatex+=0.025f;
}
if (keys[VK_DOWN] )
{
rotatex-=0.025f;
}
if (keys[VK_LEFT] )
{
rotatez+=0.1f;
}
if (keys[VK_RIGHT] )
{
rotatez-=0.1f;
}
if (keys[VK_F1] )
{
wireframemode=!wireframemode;
if(wireframemode)
{
WireframeMode();
Sleep(100);
}
else
{
TextureMode();
Sleep(100);
}
}
if (keys[VK_ESCAPE]) // Was ESC pressed?
{
done = true; // ESC signalled a quit
}
// Not time to quit, Update screen
if (isRClicked) // If Right Mouse Clicked, Reset All Rotations
{
Matrix3fSetIdentity(&LastRot); // Reset Rotation
Matrix3fSetIdentity(&ThisRot); // Reset Rotation
Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot); // Reset Rotation
}
if (!isDragging) // Not Dragging
{
if (isClicked) // First Click
{
isDragging = true; // Prepare For Dragging
LastRot = ThisRot; // Set Last Static Rotation To Last Dynamic One
ArcBall.click(&MousePt); // Update Start Vector And Prepare For Dragging
}
}
if (isClicked) // Still Clicked, So Still Dragging
{
Quat4fT ThisQuat;
ArcBall.drag(&MousePt, &ThisQuat); // Update End Vector And Get Rotation As Quaternion
Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat); // Convert Quaternion Into Matrix3fT
Matrix3fMulMatrix3f(&ThisRot, &LastRot); // Accumulate Last Rotation Into This One
Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot); // Set Our Final Transform's Rotation From This One
}
else // No Longer Dragging
isDragging = false;
DrawGLScene(); // Draw the scene
SwapBuffers(hDC); // Swap buffers (Double buffering)
}
}
}
// Shutdown
KillGLWindow(); // Kill the window
return (msg.wParam); // Exit the program
}
示例15: WinMain
int WINAPI WinMain(HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL bDone = FALSE; // Bool Variable To Exit Loop
// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL, MSG_RUNINFULLSCREEN,
MSG_STARTFULLSCREEN, MB_YESNO | MB_ICONQUESTION) == IDNO)
{
g_bFullscreen = FALSE; // Windowed Mode
}
// Create Our OpenGL Window
if (!CreateGLWindow(WINDOW_TITLE, WINDOW_WIDTH,
WINDOW_HEIGHT, WINDOW_BIT, g_bFullscreen))
{
return 0; // Quit If Window Was Not Created
}
while (!bDone) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message == WM_QUIT) // Have We Received A Quit Message?
{
bDone = TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if (g_bActive) // Program Active?
{
if (g_bKeysArr[VK_ESCAPE]) // Was ESC Pressed?
{
bDone = TRUE; // ESC Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
DrawGLScene(); // Draw The Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}
if (g_bKeysArr[VK_F1]) // Is F1 Being Pressed?
{
g_bKeysArr[VK_F1] = FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
g_bFullscreen = !g_bFullscreen; // Toggle Full screen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BIT, g_bFullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}