I was going along just fine working on an opengles 2.0 application until I tested it on an older phone that doesn't support VAO and now I seem to have fallen into a marsh.
I started using opengl after VAO's were sorta standard and everywhere so I never had to render without using one. Now that I have to write code that supports it I am having some trouble.
vertex shader
attribute vec3 position;
attribute vec4 icolor;
varying vec4 fcolor;
void main()
{
gl_Position = vec4(position, 1.0);
fcolor = icolor;
}
fragment shader
precision mediump float;
varying vec4 fcolor;
void main (void)
{
gl_FragColor = fcolor;
}
application side of things
init code:
glGenBuffers(1, &verticesBuffer);
glBindBuffer(GL_ARRAY_BUFFER, verticesBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(rend2d->vertices), rend2d->vertices, GL_STATIC_DRAW);
glGenBuffers(1, &indicesBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(rend2d->indices), rend2d->indices, GL_STATIC_DRAW);
glGenBuffers(1, &colorBuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(rend2d->colors), rend2d->colors, GL_STATIC_DRAW);
rendering code: glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(sp);
GLint posLoc = glGetAttribLocation(sp, "position");
GLint colLoc = glGetAttribLocation(sp, "icolor");
glBindBuffer(GL_ARRAY_BUFFER, verticesBuffer);
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glVertexAttribPointer(colLoc, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer);
glDrawElements(GL_TRIANGLES, rend2d->vertexCount, GL_UNSIGNED_INT, 0);
my error might be glaringly obvious but I just don't see what part I am currently not doing correctly and hoping to get some help with semi-modern opengl. This is mainly to provide support for apps that are opengles 2.0 but do not support the GL_OES_vertex_array_object extension.
glEnableVertexAttribArray()calls in your code. The enable state per attribute is also stored in VAOs. - derhass