1 year ago

#237073

test-img

Kouki

Android OpenGl ES 3.0 update VBO data on button click?

Is there any way to draw mesh dynamically. like on press of a button send new float array to openGL ES 30 VBO. currently i draw both rectangle and triangle STATIC in Native C++ they are visible, But when i pass triangle array from java using JNI. I got an error

call to OpenGL ES API with no current context (logged once per thread)

Native C++.

GLuint fvao, bvao;
GLuint VBO[2];

void setupBuffers() {
    glGenVertexArrays(1,&bvao);
    glBindVertexArray(bvao);
    glGenBuffers(1, &VBO[0]);
    glBindBuffer(GL_ARRAY_BUFFER, VBO[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(rect), rect, GL_STATIC_DRAW);
    .
    .
    .

    
    // Triangle --------------------------------------
    glGenVertexArrays(1,&fvao);
    glBindVertexArray(fvao);
    glGenBuffers(1, &VBO[1]);
    glBindBuffer(GL_ARRAY_BUFFER, VBO[1]);
    glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);
    glEnableVertexAttribArray(0);   // pos
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(0 * sizeof(GLfloat)));
    glEnableVertexAttribArray(1);   // color
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
    glEnableVertexAttribArray(2);   // texture
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
    glBindVertexArray(0);   //Unbind VAO

}


// UPDATE -----------------------
void updateBuffer(float triangle[]) {
    glBindBuffer(GL_ARRAY_BUFFER, VBO[1]); //Bind array for OpenGL to use
    glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}


// update Buffer JNI
extern "C" JNIEXPORT void JNICALL
Java_com_test_nativetest_GL3JNILib_update(JNIEnv * env, jclass obj, jfloatArray triangle)
{
    updateBuffer(triangle);
}

If anyone can tell me what i am missing or doing wrong. Any help would be appreciated.

android

c++

opengl-es-3.0

0 Answers

Your Answer

Accepted video resources