I'm trying to make a gui for my mobile program but 2D rendering doesn't work with 3D.
Yes the internet is full of the same question and all the answers I found are not for gles or do not meet my needs... There is a possibility that I didn’t look right but after two days of researching I doubt it a little.
For some reason my code breaks when I render 3D and 2D but it works with both if I render only one (regardless of which one)
My 3D draw:
glVertexAttribPointer( vertexPosition, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), 0);
glEnableVertexAttribArray( vertexPosition);
glVertexAttribPointer( texturePosition, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray( texturePosition);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebos[index]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, geometrys[index].ii*sizeof(int), geometrys[index].elements, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vbos[index]);
glBufferData(GL_ARRAY_BUFFER, geometrys[index].vi*sizeof(float), geometrys[index].vertices, GL_STATIC_DRAW);
glDrawElements( GL_TRIANGLES, geometrys[index].ii, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray( vertexPosition);
glDisableVertexAttribArray( texturePosition);
My 2D draw:
glVertexAttribPointer( vertexPosition, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), 0);
glEnableVertexAttribArray( vertexPosition);
glVertexAttribPointer( texturePosition, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)(2 * sizeof(GLfloat)));
glEnableVertexAttribArray( texturePosition);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, ui_ii*sizeof(int), ui_elements, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, ui_vi*sizeof(float), ui_vertices, GL_STATIC_DRAW);
glDrawElements( GL_TRIANGLES, ui_ii, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray( vertexPosition);
glDisableVertexAttribArray( texturePosition);
I'm working with vbos in both but the first uses multiple vbos while the second only 1:
3D:
glGenBuffers(9*9*16, &vbos[0]);
glGenBuffers(9*9*16, &ebos[0]);
2D:
glGenBuffers(1, &vbos);
glGenBuffers(1, &ebos);
I already tried to separate the gl programs and disable the depth for 2D, but everything resulted in 2D mixing with 3D and clipping the faces in random colors and strange shapes.
Aucun commentaire:
Enregistrer un commentaire