-1

I'm trying to port an OpenGL program to GLESv2. The program uses the following code a texture to the default framebuffer (it also fails if I render it to an fbo which also works on OpenGL).

    glBindFramebuffer(GL_FRAMEBUFFER, 0); 
    glVertexAttribPointer(bgra_texcoords, 2, GL_FLOAT, GL_FALSE, 0, display_texcoords);
    glEnableVertexAttribArray(bgra_texcoords);
    DEBUG_ERROR_CHECK();

    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glUseProgram(bgra_program);
    glBindTexture(GL_TEXTURE_2D, inst->texture);
    glUniform1i(bgra_texture, 0); 
    glViewport(inst->x, root_surface->h - (inst->y + inst->h), inst->w, inst->h);
    DEBUG_ERROR_CHECK();

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 
    DEBUG_ERROR_CHECK();
    glBindBuffer(GL_ARRAY_BUFFER, 0); 
    glFlush();

This works fine with OpenGL but it fails on glDrawArrays() under GLESv2. I read this question: glDrawElements throw GL_INVALID_VALUE​ error which is very similar to my problem but I can't figure out how to apply the solution to my code since I'm not using VertexArray and I'm very new to GL.

inst->texture is a texture uploaded with glTexImage2D(). I created the vertex_buffer right after initializing EGL and compiling the shaders:

    glGenBuffers(1, &vertex_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), 
            vertices, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glVertexAttribPointer(bgra_pos, 2, GL_FLOAT, GL_FALSE, 0, 0); 
    glEnableVertexAttribArray(bgra_pos);
    DEBUG_ERROR_CHECK();

Edit: You can look at the whole source file here: https://github.com/fernando-rodriguez/mediabox/blob/bc4135d9568b2c5b4e8f39ac63ded2cb66023bcd/src/lib/ui/video-opengl.c. The file is a video "driver" for a compositor, all it does is creates 2D surfaces and render them to the screen. If there is anything wrong with the question or am missing something please post a comment so I can fix it. Thanks.

fernan
  • 349
  • 1
  • 6

1 Answers1

0

I figured it out. I was calling eglBindAPI() after eglCreateContext() so I think I was actually creating a GLES1 context.

fernan
  • 349
  • 1
  • 6