OpenGL GLKit:将不同大小的顶点对象渲染在一起.ios opengl绘图调用超出了数组缓冲区界限



我很怀疑有人能帮我,但嘿。

我有一个我一直在研究的3D框架,世界上大多数东西都是立方体(36个顶点)。

我遵循了这个关于将混合器对象引入OpenGL的伟大教程:http://www.raywenderlich.com/48293/how-to-export-blender-models-to-opengl-es-part-1

我把立方体带进来,一切都很好,然后我试着把一个球体、立方体、圆柱体等带进来,结果它爆炸了ios opengl绘图调用超出数组缓冲区界限

我知道这些对象很好,因为它们可以与演示应用程序一起使用,但它只渲染1个对象,并且没有数组和顶点等的绑定

无论如何

我确信这个代码是垃圾,但我已经尝试了所有

- (void)setupSphere;
{
    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);
//////
    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(&sphereVertices), &sphereVertices, GL_STATIC_DRAW);
////
    glGenBuffers(1, &_position);
    glBindBuffer(GL_ARRAY_BUFFER, _position);
    glBufferData(GL_ARRAY_BUFFER, sizeof(spherePositions),spherePositions, GL_STATIC_DRAW);
////
    glGenBuffers(1, &_texture);
    glBindBuffer(GL_ARRAY_BUFFER, _texture);
    glBufferData(GL_ARRAY_BUFFER, sizeof(sphereTexels),sphereTexels, GL_STATIC_DRAW);
////
    glGenBuffers(1, &_normal);
    glBindBuffer(GL_ARRAY_BUFFER, _normal);
    glBufferData(GL_ARRAY_BUFFER, sizeof(sphereNormals),sphereNormals, GL_STATIC_DRAW);
//////
//    glBindVertexArrayOES(0);
    // Positions
    //glBindBuffer(GL_ARRAY_BUFFER, _position);
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, spherePositions);
    // Texels
    //glBindBuffer(GL_ARRAY_BUFFER, _texture);
    glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, sphereTexels);
    // Normals
    //glBindBuffer(GL_ARRAY_BUFFER, _normal);
    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 0, sphereNormals);
    //glBindVertexArrayOES(_vertexArray);
    glBindVertexArrayOES(0);
}
- (void)drawSphere:(float)eyeOffset
{
    // Calculate the per-eye model view matrix:
    GLKMatrix4 temp = GLKMatrix4MakeTranslation(eyeOffset, 0.0f, 0.0f);
    GLKMatrix4 eyeBaseModelViewMatrix = GLKMatrix4Multiply(temp, self.baseModelViewMatrix);
    if (self.isTransparant)
    {
        glEnable (GL_BLEND);
        glDisable(GL_CULL_FACE);
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    if (self.textureInfo)
    {
        glBindTexture(self.textureInfo.target, self.textureInfo.name);
    }

    glBindVertexArrayOES(_vertexArray);
    glUseProgram(_program);
    self.modelViewMatrix = GLKMatrix4MakeTranslation(self.position.x,self.position.y, self.position.z );//(float)x, (float)y, -1.5f)
    self.modelViewMatrix = GLKMatrix4Scale(self.modelViewMatrix, self.scale.x, self.scale.y, self.scale.z);
    //rotation +=0.01;
    self.modelViewMatrix = GLKMatrix4Rotate(self.modelViewMatrix,rotation, 0.0 ,0.0 ,1.0);
    self.modelViewMatrix = GLKMatrix4Multiply(eyeBaseModelViewMatrix, self.modelViewMatrix);
    GLKMatrix3 normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(self.modelViewMatrix), NULL);
    GLKMatrix4 modelViewProjectionMatrix = GLKMatrix4Multiply(self.projectionMatrix, self.modelViewMatrix);
    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, modelViewProjectionMatrix.m);
    glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, normalMatrix.m);
    _colorSlot = glGetUniformLocation(_program, "color");
    GLfloat color[] = {
        self.color.x, self.color.y, self.color.z, self.color.a};
    glUniform4fv(_colorSlot, 1, color);
    glDrawArrays(GL_TRIANGLES, 0, sphereVertices);
    if (self.isTransparant)
    {
        glEnable(GL_CULL_FACE);
        //glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
    }
}

您正试图将VAO与客户端顶点数组一起使用。不支持此操作。引用扩展规范:

  • 是否应允许顶点数组对象封装客户端顶点阵列?

    决议:不。OpenGL ES工作组同意兼容性使用OpenGL并能够引导开发人员获得更多通过强制使用VBO进行的高性能绘图比损害VAO采用的可能性。

如果要使用VAO,则需要启用VBO代码,该代码似乎主要存在于代码中,但当前已注释掉。

最新更新