Question

I read a lot about the new concepts in OpenGL 4 in comparison to OpenGL 1. My problem is, that in old GLSL I could use the predefined gl_Vertex for calculations in my vertex shader out of the box. But in the current version 4.1 this has been removed.

There are many questions about this, but no one gives an example in how to actually make the old gl_Vertex available in the shader. I found some possibilities like layout (location = 0) in vec3 vertexpos; or glBindAttribLocation(shader, 0, "vertexpos");. But nowhere is explained where I got the knowledge in which index the current vertex position is stored. Actually I found this site with indexes but that doesn't seem to work with the above mentioned code snippets.

Maybe someone could bring light in the dark and show a very little example.

Was it helpful?

Solution

The reason why gl_Vertex no longer available is because pre-defined attributes were removed. What was glVertexPointer - now have to be manually set to user-defined named attribute with glVertexAttribPointer. There is no way for shader to know what data comes to what attribute - because it is just numbers; however, how this numbers are handled is up to programmer.

So, you have to define at least one attribute (say vertexpos, as in your example - but name could be almost anything), get attribute location (glGetAttribLocation, or use location specifier to assign default location) to convert symbolic name to attribute slot number, then assign attribute array with glVertexAttribPointer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top