简体   繁体   English

如何在 linux(Ubuntu 14.04) 中找到我的 OpenGL 版本

[英]How to find my OpenGL version in linux(Ubuntu 14.04)

I started reading OpenGL 4.0 Shading Language version 1. At the start of the book they show have code to find out OpenGL version but is does not work.我开始阅读 OpenGL 4.0 Shading Language version 1。在本书的开头,他们展示了一些代码来找出 OpenGL 版本,但它不起作用。 I would like to know how to find out if set it up correctly.我想知道如何确定是否正确设置。

#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <iostream>
#include <stdio.h>

int main(int argc, char** argv) {
/*
GLenum err = glewInit();
if( GLEW_OK != err ) {
    fprintf(stderr, "Error initializing GLEW: %s\n",
    glewGetErrorString(err) );
}
*/
const GLubyte *renderer = glGetString( GL_RENDERER );
const GLubyte *vendor = glGetString( GL_VENDOR );
const GLubyte *version = glGetString( GL_VERSION );
const GLubyte *glslVersion = glGetString( GL_SHADING_LANGUAGE_VERSION );
GLint major, minor;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
printf("GL Vendor : %s\n", vendor);
printf("GL Renderer : %s\n", renderer);
printf("GL Version (string) : %s\n", version);
printf("GL Version (integer) : %d.%d\n", major, minor);
printf("GLSL Version : %s\n", glslVersion);
}

The code gives me null out puts.代码给了我空输出。 I do not believe that this is correct because before starting this book I found code online for displaying a box in openGL 2.0 which worked.我不相信这是正确的,因为在开始这本书之前,我在网上找到了在 openGL 2.0 中显示一个框的代码。

GL Vendor : (null)
GL Renderer : (null)
GL Version (string) : (null)
GL Version (integer) : 0.0
GLSL Version : (null)

Also I have looked at this link which gives information about my graphics card.我还查看了此链接,其中提供了有关我的显卡的信息。 I think that this has nothing to do with my development package installed.我认为这与我安装的开发包无关。

I need to find a way to confirm I have openGL 4.0 installed.我需要找到一种方法来确认我安装了 openGL 4.0。 I would prefer a terminal command or my code fixed.我更喜欢终端命令或修复我的代码。

Edit: I have added a additional question about the code McLovin provided: I noticed that I get a extra line 'Segmentation fault (core dumped)'.编辑:我添加了一个关于 McLovin 提供的代码的附加问题:我注意到我得到了一个额外的行“Segmentation fault (core dumped)”。 I have a 7970 AMD GPU.我有一个 7970 AMD GPU。 Is this output an error?这个输出是错误吗?

You need to create an OpenGL context before you get any data about OpenGL.在获取有关 OpenGL 的任何数据之前,您需要创建一个 OpenGL 上下文。 A context is essentially the set of data related to the OpenGL instance used in your application.上下文本质上是与应用程序中使用的 OpenGL 实例相关的一组数据。 It is usually created by opening a window with a library like freeglut, SFML, GLFW, or SDL.它通常是通过打开一个带有 freeglut、SFML、GLFW 或 SDL 等库的窗口来创建的。
The following code uses freeglut:以下代码使用 freeglut:

#include <stdio.h>
#include <GL/gl.h>
#include <GL/freeglut.h>

int main(int argc, char **argv)
{
        glutInit(&argc, argv); /* create opengl context */
        glutInitContextVersion(4, 4); /* use version 4.4 */
        /* there's no main loop, so the window will close immediately */
        glutCreateWindow("You won't see this window");

        /* we can now get data for the specific OpenGL instance we created */
        const GLubyte *renderer = glGetString( GL_RENDERER );
        const GLubyte *vendor = glGetString( GL_VENDOR );
        const GLubyte *version = glGetString( GL_VERSION );
        const GLubyte *glslVersion = glGetString( GL_SHADING_LANGUAGE_VERSION );
        GLint major, minor;
        glGetIntegerv(GL_MAJOR_VERSION, &major);
        glGetIntegerv(GL_MINOR_VERSION, &minor);
        printf("GL Vendor : %s\n", vendor);
        printf("GL Renderer : %s\n", renderer);
        printf("GL Version (string) : %s\n", version);
        printf("GL Version (integer) : %d.%d\n", major, minor);
        printf("GLSL Version : %s\n", glslVersion);
        return 0;
}

For example, this is the output it gave me (Currently using Ubuntu 12.04).例如,这是它给我的输出(目前使用 Ubuntu 12.04)。

GL Vendor : NVIDIA Corporation
GL Renderer : GeForce GTX 660/PCIe/SSE2
GL Version (string) : 4.4.0 NVIDIA 331.20
GL Version (integer) : 4.4
GLSL Version : 4.40 NVIDIA via Cg compiler

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

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