Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

c++ - Black screen on Anton's OpenGL Hello Triangle Tutorial

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...