简体   繁体   English

如何在不创建窗口的情况下检查OpenGL和GLSL版本?

[英]How to check OpenGL and GLSL Version without creating a window?

I tried with following methods - 1. using glew 2. using glut 我尝试了以下方法 - 1.使用glew 2.使用过剩

both almost similar ways as follows - 几乎类似的方式如下 -

 #include <stdio.h>
 #include <stdlib.h>
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>

 int main(int agrc, char **argv)
 {
    //do windowing related stuff here

    if ( !glfwInit())
    {
            printf("Error: Failed to initialize GLFW\n");
            return -1;
    }

    GLFWwindow* window = glfwCreateWindow(800, 600, "Triangle", NULL, NULL);
    if (window == NULL)
    {
            printf("Failed to create GLFW window\n");
            glfwTerminate();
            return -1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK)
    {
            printf("Error: Failed to initialize GLEW\n");
            return -1;
    }

    printf("GL version: %s\n", glGetString(GL_VERSION));
    printf("GL shading language version: %s\n", 
    glGetString(GL_SHADING_LANGUAGE_VERSION));
}

Question - Is it possible to check GL and GLSL Version with creating native window? 问题 - 是否可以通过创建本机窗口来检查GL和GLSL版本?

As per my understanding it is necessary to create GL context which is usually done by creating a window, Please tell me alternative without creating window. 根据我的理解,有必要创建GL上下文,这通常通过创建一个窗口来完成,请告诉我替代方案而不创建窗口。

According to the OpenGL Wiki FAQ (emphasis mine). 根据OpenGL Wiki FAQ (强调我的)。

You must create a GL context in order for your GL function calls to make sense. 您必须创建GL上下文才能使GL函数调用有意义。 You can't just write a minimal program such as this: 你不能只写一个像这样的小程序:

int main(int argc, char **argv)
{
    char *GL_version=(char *)glGetString(GL_VERSION);
    char *GL_vendor=(char *)glGetString(GL_VENDOR);
    char *GL_renderer=(char *)glGetString(GL_RENDERER);
    return 0;
}

In the above, the programmer simply wants to get information about this system (without rendering anything) but it simply won't work because no communication has been established with the GL driver. 在上面,程序员只是想获得有关这个系统的信息(没有渲染任何东西),但它根本不起作用,因为没有与GL驱动程序建立通信。 The GL driver also needs to allocate resources with respect to the window such as a backbuffer. GL驱动程序还需要相对于窗口分配资源,例如后备缓冲区。 Based on the pixelformat you have chosen, there can be a color buffer with some format such as GL_BGRA8. 根据您选择的pixelformat,可以使用某种格式的颜色缓冲区,例如GL_BGRA8。 There may or may not be a depth buffer. 可能有也可能没有深度缓冲区。 The depth might contain 24 bits. 深度可能包含24位。 There might be a 8 bit stencil. 可能有8位模板。 There might be an accumulation buffer. 可能存在累积缓冲区。 Perhaps the pixelformat you have chosen can do multisampling. 也许您选择的像素格式可以进行多重采样。 Up until now, no one has introduced a windowless context. 到目前为止,还没有人引入无窗口环境。

You must create a window. 您必须创建一个窗口。 You must select a pixelformat. 您必须选择pixelformat。 You must create a GL context. 您必须创建GL上下文。 You must make the GL context current (wglMakeCurrent for Windows and glXMakeCurrent for *nix). 您必须使GL上下文为当前(Windows为wglMakeCurrent,* nix为glXMakeCurrent)。

That said, if you're just looking to avoid a temporary window popping up, create a non-visible window, so the end-user doesn't have any idea that you're creating the window. 也就是说,如果您只是想避免弹出临时窗口,请创建一个不可见的窗口,这样最终用户就不会知道您正在创建窗口。 In GLFW, it appears you can do this by setting the window hint GLFW_VISIBLE to false with glfwWindowHint before creating the window. 在GLFW中,您可以通过在创建窗口之前使用glfwWindowHint将窗口提示GLFW_VISIBLE设置为false来执行此操作。 All other windowing systems I've worked with have a similar concept of setting the visibility of a window. 我使用的所有其他窗口系统都有类似的设置窗口可见性的概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM