OpenGL窗口居中顯示
方法1:
使用函數int glutGet(),參數設為GLUT_SCREEN_WIDTH、GLUT_SCREEN_HEIGHT獲得屏幕的寬度和高度.
int cx = glutGet(GLUT_SCREEN_WIDTH);
int cy = glutGet(GLUT_SCREEN_HEIGHT);
假設窗口的寬度和高度分別是:m_winWidth, m_winHeight;
設置窗口居中:
glutInitWindowPosition((cx-m_winWidth)/2, (cy-m_winHeight)/2);
方法2:
使用WindowsAPI函數GetSystemMetrics(),參數設置為SM_CXSCREEN、SM_CYSCREEN獲得屏幕的寬度和高度
int cx = GetSystemMetrixs(SM_CXSCREEN);
int cy = GetSystemMetrixs(SM_CYSCREEN);
假設窗口的寬度和高度分別是:m_winWidth, m_winHeight;
設置窗口居中:
glutInitWindowPosition((cx-m_winWidth)/2, (cy-m_winHeight)/2);