我非常怀疑任何人都可以帮助我,但是嘿嘿。

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

我按照这个关于将blender对象引入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);
    }
}

===============>>#1 票数:2 已采纳

您正在尝试将VAO与客户端顶点数组一起使用。 这不受支持。 引自扩展规范

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

    已解决:否.OpenGL ES工作组一致认为,与OpenGL的兼容性以及通过强制执行VBO来指导开发人员进行更高性能绘图的能力比伤害VAO采用的可能性更重要。

如果要使用VAO,则需要启用代码中最常出现的VBO代码,但目前已注释掉。

  ask by Burf2000 translate from so

未解决问题?本站智能推荐: