Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm new to OpenGL and started studying using Anton's OpenGL tutorials. I finished the "Hello Triangle" tutorial and compiled it without errors with the following g++ command:

g++ -o hello_triangle main.c -lGLEW -lglfw -lGL -lX11 -lXxf86vm -lXrandr -lpthread -lXi -lm

However, the system window shows only a black screen, both in my code and in the code from the book repository.

The output from glGetString(GL_RENDERER) and glGetString(GL_VERSION) is the following:

Renderer: Mesa DRI Intel(R) Sandybridge Mobile  
OpenGL version supported 3.0 Mesa 11.0.6

What might be the reason of this black screen?

If you want to check the code just look at the '00_hello_triangle' code.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

As @gnimuc-key suggested, when I changed the version in the shaders code, both vertex and fragment shader, it worked:

const char* vertex_shader =
    "#version 130
"
    "in vec3 vp;"
    "void main () {"
    " gl_Position = vec4 (vp, 1.0);"
    "}"; 

const char* fragment_shader =
    "#version 130
"
    "out vec4 frag_colour;"
    "void main () {"
    " frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"
    "}"; 

I changed "#version 150" to "#version 130" and worked properly


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...