黑色屏幕上安东的OpenGL你好三角教程 [英] Black screen on Anton's OpenGL Hello Triangle Tutorial
问题描述
我刚接触OpenGL,并开始使用 Anton的OpenGL 教学课程学习。
我完成了Hello Triangle教程,并使用以下g ++命令编译了它:
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.
glGetString(GL_RENDERER)和glGetString(GL_VERSION)的输出如下:
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?
如果你想检查代码,看看'00_hello_triangle'代码。 / p>
If you want to check the code just look at the '00_hello_triangle' code.
推荐答案
As @ gnimuc-key建议,当我改变着色器代码的版本时,
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\n"
"in vec3 vp;"
"void main () {"
" gl_Position = vec4 (vp, 1.0);"
"}";
const char* fragment_shader =
"#version 130\n"
"out vec4 frag_colour;"
"void main () {"
" frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"
"}";
我将#version 150更改为#version 130并正常工作
I changed "#version 150" to "#version 130" and worked properly
这篇关于黑色屏幕上安东的OpenGL你好三角教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!