I've been trying to learn the basics of Opengl, following this series of tutorials :
http://in2gpu.com/2014/12/21/change-triangle-color-opengl-4-5/
I am therefore using freeglut and glew (version 1.13).
I had no issue with the first few tutorials, until the vertex shader started using explicit locations for attributes.
When compiling the shaders, I would get an 'error : GL_ARB_explicit_attrib_location not supported in this version', even though the context I had asked for was 4.0.
Looking at my graphics card, I realised that I had two and was using the less powerful Intel one when I had a Radeon R9 M295x that supported OpenGL 4.5.
I then switched the context to Opengl 4.3, and this time got this error : 'error #5 : Extension : explicit location is not supported in this version'.
What am I understanding incorrectly ? I thought I could use GL_ARB_explicit_attrib_location with 3.3 or above. Why can't I in the first case ?
And what does the second error mean ? I can't find any relevant information.
Here's the context creation :
glutInit(&argc, argv);
glutInitContextVersion(4,3);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(500, 500);//optional
glutInitWindowSize(800, 600); //optional
glutCreateWindow("OpenGL First Window");
glewExperimental = GL_TRUE;
GLenum err = glewInit();
Here's the vao and vbo binding (vertex contains position and color) :
std::vector<Vertex> vertices;
vertices.push_back(Vertex(Vec3f(0.25, -0.25, 0.0), Vec4f(1,0,0,1)));
vertices.push_back(Vertex(Vec3f(-0.25, -0.25, 0.0), Vec4f(0, 1, 0, 1)));
vertices.push_back(Vertex(Vec3f(0.25, 0.25, 0.0), Vec4f(0, 0, 1, 1)));
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * 3, &vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)12);
and here's the vertex shader :
#version 430 core
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec4 in_color
out vec4 color;
void main(){
color = in_color;
gl_Position = vec4(in_position,1);
}
On a sidenote, where on earth is the documentation for glew ? Can't seem to find it on the website or in the zip folder, and typing a few keywords doesn't seem to yield any results.
Edit : A pointer to a workaround if I simply cannot use this extension would be interesting as well. I don't yet fully understand everything there is to understand about linking attributes.
Edit #2 : The other strange thing is that the fragment shader I'm using apparently compiles with no issues :
#version 430 core
layout(location = 0) out vec4 out_color; // location specified
in vec4 color;
void main()
{
out_color =color;
}
Ah, it seems I've found the problem.
There's a semi-colon missing in the vertex shader (sigh) and an 'out' attribute missing. I had two near-identical vertex shaders, and it seems I was debugging the wrong one part of the time, which didn't help.
The errors are really unintuitive and in this case seem not to help much though. Ah well.