Creating OpenGL context without window

孤者浪人 提交于 2019-11-26 21:31:13

问题


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);
}

Is this safe to use? What is the "standard" way to create a windowless OpenGL program?

Edit: I'm using FBO for the offscreen rendering.


回答1:


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.

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.

The bleeding edge, and yet not very well supported method (except on certain embedded devices) is using EGL for drawable creation.



来源:https://stackoverflow.com/questions/12482166/creating-opengl-context-without-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!