2012-08-29 10 views
18

Jestem na Linux Mint 13 XFCE. Moim problemem jest to, że kiedy uruchomić w terminalu polecenie:Dlaczego funkcja glGetString (GL_VERSION) zwraca wartość zerową/zero zamiast wersji OpenGL?

glxinfo | grep "OpenGL version" 

pojawia się następujący komunikat:

OpenGL version string: 3.3.0 NVIDIA 295.40 

Ale kiedy uruchomić glGetString(GL_VERSION) w mojej aplikacji następnie wynik jest zerowy. Dlaczego ten kod nie otrzymuje gl_version?

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

int main(int argc, char **argv) { 

    glutInit(&argc, argv); 
    glewInit(); 

    printf("OpenGL version supported by this platform (%s): \n", 
     glGetString(GL_VERSION)); 
} 
+3

Qt Creator to IDE i ma bardzo niewiele wspólnego z Twoim problemem btw. (No cóż, nic naprawdę) – Bart

+1

Nie musisz dodawać słowa "gl.h" lub "glu.h", jeśli dodasz 'glut.h' – Derek

+0

Przyczynę tego samego źródła co: http://stackoverflow.com/questions/6594214/glgetintegerv-return-garbage-value –

Odpowiedz

25

glutInit() nie tworzy GL context. Potrzebny jest bieżący kontekst GL do glewInit() i glGetString() do pracy.

Spróbuj tego:

#include <GL/glew.h> 
#include <GL/glut.h> 
#include <cstdio> 

int main(int argc, char **argv) 
{ 
    glutInit(&argc, argv); 
    glutCreateWindow("GLUT"); 

    glewInit(); 
    printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION)); 
} 
+2

To działa, dziękuję. – lyra42

+2

#include ;) dziękuję za urywek – Christoph

+1

Czy 'glutInitWindowSize' i' glutInitDisplayMode' są również obowiązkowe dla 'glGetString'? –

Powiązane problemy