I'm struggling with the OpenGL 3.3 core profile. I'm trying to get a simple shader rendered on the screen, but I get only a black screen. I'm using a Intel® HD Graphics 4000,
The vertex shader
Code :#version 330 layout(location = 0) in vec2 pos; out vec2 c; void main(void) { gl_Position = vec4(pos, 0.0, 1.0); c = (pos+1)*0.5; }
The fragment shader
Code :#version 330 in vec2 c; out vec4 color; void main(void) { color = vec4(c, 1, 1); }
in vbo[0] the vertex points are stored, vbo[1] stores the indices
Code :GLFWwindow* window; GLuint vao; GLuint vbo[2]; GLuint program; const GLfloat square[8] = { -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0 }; const GLfloat indices[4] = { 0, 1, 2, 3 };
Init OpenGL 3.3 core context
glGetString(GL_VERSION) returns "3.3 (Core Profile) Mesa 10.2.1"
glGetString(GL_SHADING_LANGUAGE_VERSION) returns "3.30"
Code :if( !glfwInit() ) { std::cerr << "Failed to initialize GLFW\n"; return -1; } glfwWindowHint(GLFW_SAMPLES, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Open a window and create its OpenGL context window = glfwCreateWindow( 1024, 768, "", 0, 0); if( window == NULL ) { std::cerr << "Failed to open GLFW window.\n"; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Initialize GL3W if (gl3wInit()) { std::cerr << "Failed to initialize GL3W" << std::endl; return -1; } if (!gl3wIsSupported(3, 3)) { std::cerr << "OpenGL Version 3.0 not supported" << std::endl; return -1; } std::cout << "OpenGL " << glGetString(GL_VERSION) << ", GLSL " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
The shaders compile successfully, I've checked it with glGetShaderiv
Code :glGenBuffers(2, vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBufferData(GL_ARRAY_BUFFER, 8*sizeof(GLfloat), square, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); glBufferData(GL_ARRAY_BUFFER, 4*sizeof(GLushort), indices, GL_STATIC_DRAW); glGenVertexArrays(1, &vao); glBindVertexArray(vao); program = glCreateProgram(); GLuint vertex_shader, fragment_shader; loadShader_FILE(vertex_shader, "shader/default.vsh", GL_VERTEX_SHADER); glAttachShader(program, vertex_shader); loadShader_FILE(fragment_shader, "shader/default.fsh", GL_FRAGMENT_SHADER); glAttachShader(program, fragment_shader); glLinkProgram(program); glUseProgram(program); glViewport(0, 0, 1024, 768); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, (void*)0); glEnableVertexAttribArray(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]); glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void*)0); glDisableVertexAttribArray(0); glfwSwapBuffers(window);
Filtered output of glxinfo
Code :$ glxinfo | grep OpenGL OpenGL vendor string: Intel Open Source Technology Center OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.2.1 OpenGL core profile shading language version string: 3.30 OpenGL core profile context flags: (none) OpenGL core profile profile mask: core profile OpenGL core profile extensions: OpenGL version string: 3.0 Mesa 10.2.1 OpenGL shading language version string: 1.30 OpenGL context flags: (none)