我试图在 OpenGL ES 2.0 中不使用 VBO 来绘制对象。我的代码往往会不时使应用程序崩溃(并非总是如此,甚至没有任何改变)。以下是代码。我认为问题在于我只启用 m_distLocation 而不向着色器发送任何数据。所有统一值都已正确设置。我认为问题仅在于属性变量(m_posAttr 和 m_distLocation)、绑定。
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnableVertexAttribArray(m_posAttr);
glEnableVertexAttribArray(m_distLocation);
int posAttrSize = sizeof(float) * 2;
GLintptr posAttrStart = reinterpret_cast<GLintptr>(&vertices[0]);
glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, posAttrSize, reinterpret_cast<GLvoid*>(posAttrStart));
glVertexAttribPointer(m_distLocation, 0, GL_FLOAT, GL_FALSE, 0, 0);
glBindAttribLocation(m_programID, m_posAttr, "posAttr" );
glBindAttribLocation(m_programID, m_distLocation, "distance" );
glUniform1i(m_patternLocation, -1);
glUniform4fv(m_colorAttr, 1, vColor);
glUniform1f(m_depthAttr, z);
glUniform1f(m_zoom, _zoom / 100);
glUniform2fv(m_scale, 1, _scale);
glUniform2fv(m_translate, 1, _trans);
glUniform1f(m_theta, _theta);
glDrawArrays(et, offsetInBytesFill, nVerticesFill );
glDisableVertexAttribArray(m_posAttr);
glDisableVertexAttribArray(m_distLocation);
我将不胜感激任何帮助。