Creating OpenGL context without window(在没有窗口的情况下创建 OpenGL 上下文)
问题描述
我正在尝试找出为离屏渲染创建无窗口 OpenGL 程序的最简单方法是什么.
I'm trying to figure out what is the simplest way to create a windowless OpenGL program for offscreen rendering.
目前我使用这个,到目前为止它工作正常:(为了清楚起见,这里删除了错误检查)
Currently I use this, and it works fine so far: (error checks removed here for clarity)
BOOL create_opengl_context(){
GLuint PixelFormat;
static PIXELFORMATDESCRIPTOR pfd;
hDC = GetDC(NULL);
PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, PixelFormat, &pfd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
}
这样使用安全吗?创建无窗口 OpenGL 程序的标准"方法是什么?
Is this safe to use? What is the "standard" way to create a windowless OpenGL program?
我使用 FBO 进行离屏渲染.
I'm using FBO for the offscreen rendering.
推荐答案
纯无窗口 OpenGL 的旧方法是使用 PBuffer.在 Windows 上,这需要使用常规窗口创建中间 OpenGL 上下文以获得所需的扩展函数指针.在 X11/GLX 上,它可以毫不费力地工作.
The old method for purely windowless OpenGL is using a PBuffer. On Windows this requires the creation of a intermediate OpenGL context using a regular window to obtain the required extension function pointers. On X11/GLX it works without further ado.
实现离屏渲染的现代方法是使用常规但隐藏的窗口,其中包含常用的 OpenGL 上下文和 FBO 作为渲染目标.
The modern way to implement off-screen rendering is using a regular, but hidden window with the usual OpenGL context and a FBO as render target.
最前沿但支持度不高的方法(某些嵌入式设备除外)是使用 EGL 创建可绘制对象.
The bleeding edge, and yet not very well supported method (except on certain embedded devices) is using EGL for drawable creation.
这篇关于在没有窗口的情况下创建 OpenGL 上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在没有窗口的情况下创建 OpenGL 上下文


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01