I am writing some OpenGL code to draw a small dot in a window, but when I try to use my own shaders, I get an error message which I don't understand.
So, here's my main function:
int main(int argc, char** argv)
{
// Initialize some things
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(100, 100);
glutCreateWindow("OpenGL Test");
glutDisplayFunc(RenderScene);
glewInit();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Make the vertex buffer
Vector3f vertices[1];
vertices[0] = Vector3f(0.0f, 0.0f, 0.0f);
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Main GLUT loop
glutMainLoop();
}
And here's my rendering callback function:
static void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_POINTS, 0, 1);
glDisableVertexAttribArray(0);
glutSwapBuffers();
}
This compiles and runs fine, displaying a small white dot against a black background, as expected.
Now, I want to use my own shaders instead of the default ones. So, in the main function, just before glutMainLoop()
, I include the line:
MakeShaderProgram("vertex-shader.glsl");
And this function is defined as:
static void MakeShaderProgram(std::string shader_filename)
{
GLuint program = glCreateProgram();
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
const GLchar* ptr_filename = &shader_filename[0];
const GLchar** ptr_filenames = &ptr_filename;
int filename_lengths[] = {1};
glShaderSource(shader, 1, ptr_filenames, &filename_lengths[0]);
glCompileShader(shader);
glAttachShader(program, shader);
glLinkProgram(program);
glUseProgram(program);
}
Finally, the file "vertex-shader.glsl", which is located in the same directory as the executable, has the following contents:
#version 330
layout (location = 0) in vec3 Position;
void main()
{
gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0);
}
Now, compiling this is fine. However, on running it, I receive the following error:
Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed!
The program breaks right after the main function starts. I have no idea what this error message means, but it is caused by attempting to use my own shaders rather than the default shaders.
Can somebody explain what is going wrong?
If it is relevant, here is my CMakeLists.txt
file:
cmake_minimum_required(VERSION 2.8.1)
set(CMAKE_CXX_FLAGS "-std=c++11")
project(OpenGLTest)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLUT REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})
file(GLOB SRCS *.cpp)
add_executable(${PROJECT_NAME} ${SRCS})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLEW_LIBRARY} ${GLUT_LIBRARY})