Two things I'm quite confused about.

1) OpenGL ES 2.0 creates primitives before the vertex shader is invoked. Why, then, does it not automatically provide the vertex shader the position of the vertex?

2) OpenGL ES 2.0 supports glDrawElements(), but it does not support glEnableClientState() or GL_VERTEX_ARRAY, so how can this call possibly be used to construct primitives?

NOTE: this is OpenGL ES 2.0, NOT normal OpenGL!



I think my confusion was stemming from the built in variable gl_Vertex that some versions of GLSL support (according to some sources, I couldn't find this in the official documentation at http://www.opengl.org/sdk/docs/manglsl/) which gives you the position of the vector provided to the draw command. This isn't present in GL ES. Further, my code was't working, and as GLSL can be difficult to debug, I had no idea what was going on :)

In this case, using vertex attributes and passing the model-space location of the vertices and my transformation matrix allows me to transform the vertices correctly.

  • \$\begingroup\$ Did you get glDrawElements to work? I'm running into this problem right now trying to get it to work. \$\endgroup\$ Nov 18, 2015 at 2:15

2 Answers 2


1: Primitives are not "created" before the vertex shader is invoked. Primitive assembly is a part of the pipeline after the vertex shader executes. Using the parameter passed to glDraw*, groups of vertex data output by the vertex shader are used to create primitives, which are then clipped, culled, and rasterized.

There is no "position of the vertex" attribute. That's because vertex shaders are arbitrary code. They take whatever attributes you want them to, and those attributes have whatever meaning your code desires them to have. If you want a position value as an attribute, name it position in your shader.

A vertex shader is required to output a position in clip-space, but how the vertex shader creates that data is up to the shader. It could do some matrix transforms on an attribute, which is the typical method. But it could also do more arbitrary things. Depending on the extensions available to you in your ES 2.0 implementation, it could fetch data from a texture to compute the position. It could use a Perlin noise function to generate the height for a height map. And so forth.

2: The functions you're looking for are glEnableVertexAttribArrays and glDisableVertexAttribArrays.

this is OpenGL ES 2.0, NOT normal OpenGL!

It may as well be, since nothing you asked is different between desktop GL and GL-ES 2.0.


2) You must provide vertices using glVertexAttribPointer(). You can store vertices in system memory or in VBO.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .