![](/img/trans.png)
[英]OpenGL Non-exclusive Fullscreen Mode (A.K.A. Fullscreen Borderless Window)
[英]OpenGL exclusive mode fullscreen
DirectX允許應用程序獨占一個GPU並將其內容發送到監視器。 這被稱為全屏。 使用OpenGL時,使用ChangeDisplaySettings(&dv, CDS_FULLSCREEN)
激活全屏。 然而,這樣做的結果是“假的”全屏 - 全屏窗口。 這兩者的行為方式存在一些差異,特別是當alt-tabbing失焦時。
有沒有辦法像DirectX一樣只使用Win32 api和OpenGL來全屏創建一個窗口,或者這是DirectX獨有的功能?
如果你願意讓GLUT為你做窗口任務,你可以看一下: 在openGL中全屏
如果您想自己進入WIN32詳細信息,可以執行以下操作:
#include <stdlib.h>
#include <Windows.h>
#include "glew.h"
#include <gl/GL.h>
#include <gl/GLU.h>
int main()
{
HWND hwnd;
HDC hdc;
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd;
// First create the full screen window
hwnd = CreateWindowEx(
0 ,"STATIC","", WS_VISIBLE|WS_EX_TOPMOST,
0,0,640,480, 0, 0, GetModuleHandle(NULL), 0
);
WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
MONITORINFO mi = { sizeof(mi) };
if (
GetWindowPlacement(hwnd, &g_wpPrev) &&
GetMonitorInfo(MonitorFromWindow(hwnd,MONITOR_DEFAULTTOPRIMARY), &mi)
) {
SetWindowLong(hwnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(
hwnd, HWND_TOP,
mi.rcMonitor.left, mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left,
mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED
);
}
// Describe the pixel format
memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
// Create the device context and rendering context
hdc = GetDC(hwnd);
pixelFormat = ChoosePixelFormat(hdc,&pfd);
SetPixelFormat(hdc,pixelFormat,&pfd);
HGLRC rendering_context = wglCreateContext(hdc);
BOOL rc = wglMakeCurrent(hdc, rendering_context);
GLenum err = glewInit();
if (GLEW_OK != err) { /*do something*/ }
// Paint the back buffer red
glClearColor(1,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
// Show on screen
rc = SwapBuffers(hdc);
while (1)
{
// Do something ...
}
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.