创建不带窗口的OpenGL上下文 [英] Creating OpenGL context without window

查看:722
本文介绍了创建不带窗口的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天全站免登陆