在OpenGL中渲染屏幕外而不打开窗口?

时间:2019-12-18 21:05:56

标签: c++ opengl glfw render-to-texture

我想使用OpenGL在屏幕外渲染一些图像。

每次运行程序时,都会弹出一个窗口,然后立即关闭,这很烦人。我想这是因为即使我只想进行屏幕外渲染,此处的代码段也是如此:

// Initialise GLFW
if( !glfwInit() )
{
    fprintf( stderr, "Failed to initialize GLFW\n" );
    getchar();
    return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);
if( window == NULL ){
    fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
    getchar();
    glfwTerminate();
    return -1;
}
glfwMakeContextCurrent(window);

// We would expect width and height to be 1024 and 768
int windowWidth = 1024;
int windowHeight = 768;
// But on MacOS X with a retina screen it'll be 1024*2 and 768*2, so we get the actual framebuffer size:
glfwGetFramebufferSize(window, &windowWidth, &windowHeight);

它仍然尝试使用窗口初始化opengl上下文。

有什么解决方法可以摆脱这个烦人的窗口吗?

0 个答案:

没有答案