传入顶点数组不显示对象

问题描述

我注意到当我在 another.cpp 文件中有我的顶点和索引数组时我的三角形没有被渲染,我认为我错误地传入了数组,但我找不到任何解决我的问题的方法。>

Objects.h 文件

class Vertex
{
public:
    void GenVBO(unsigned int VBO)
    {
        glGenBuffers(1,&VBO);
        glBindVertexArray(VBO);
    }
    void GenVAO(unsigned int VAO,float Vertices[])
    {
        glGenVertexArrays(1,&VAO);
        glBindBuffer(GL_ARRAY_BUFFER,VAO);
        glBufferData(GL_ARRAY_BUFFER,sizeof(Vertices),Vertices,GL_STATIC_DRAW);
        glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3 * sizeof(float),(void*)0);
        glEnabLevertexAttribArray(0);
    }
    void GenEBO(unsigned int EBO,unsigned int Indices[])
    {
        glGenBuffers(1,&EBO);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(Indices),Indices,GL_STATIC_DRAW);
    }
};

Objects.cpp 文件

unsigned int VBO;
unsigned int VAO;
unsigned int EBO;

float Vertices[] =
{
   0.3f,0.3f,0.0f,-0.3f,0.0f
};
unsigned int Indices[] =
{
    0,1,2,3
};


void InitDraw()
{
    Vertex theVertex;
    theVertex.GenVBO(VBO);
    theVertex.GenVAO(VAO,Vertices);
    theVertex.GenEBO(EBO,Indices);
}

当我在 .H 文件中包含我的 Vertices 数组和 Indices 数组时,会绘制正方形。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)