Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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.

share|improve this question
Did you get glDrawElements to work? I'm running into this problem right now trying to get it to work. – Christopher Perry Nov 18 '15 at 2:15
up vote 4 down vote accepted

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.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.