[英]Creating OpenGL context without window
I'm trying to figure out what is the simplest way to create a windowless OpenGL program for offscreen rendering. 我试图找出最简单的方法来创建用于离屏渲染的无窗口OpenGL程序。
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);
}
Is this safe to use? 使用安全吗? What is the "standard" way to create a windowless OpenGL program? 创建无窗口OpenGL程序的“标准”方法是什么?
Edit: I'm using FBO for the offscreen rendering. 编辑:我正在使用FBO进行屏幕外渲染。
The old method for purely windowless OpenGL is using a PBuffer. 纯无窗口OpenGL的旧方法是使用PBuffer。 On Windows this requires the creation of a intermediate OpenGL context using a regular window to obtain the required extension function pointers. 在Windows上,这需要使用常规窗口创建中间OpenGL上下文,以获得所需的扩展功能指针。 On X11/GLX it works without further ado. 在X11 / GLX上,无需费一切功夫。
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. 实现屏幕外渲染的现代方法是使用常规但隐藏的窗口,该窗口具有常规的OpenGL上下文和FBO作为渲染目标。
The bleeding edge, and yet not very well supported method (except on certain embedded devices) is using EGL for drawable creation. 前沿技术,但尚未得到很好的支持(某些嵌入式设备除外),正在使用EGL进行可绘制的创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.