在没有窗口的情况下创建 OpenGL 上下文 [英] Creating OpenGL context without window

查看:53
本文介绍了在没有窗口的情况下创建 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 上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆