2016-09-24 34 views
0

试图在opengl中绘制顶点,但我只能从顶点分配一个元素到TaskTwoVerticesN,请帮助...!我究竟做错了什么?请让我知道如果你需要所有的代码,我可以通过电子邮件发送或张贴在这里只有一个值被添加到矢量

typedef struct Vertex { 
    float XYZW[4]; 
    float RGBA[4]; 
    void SetCoords(float *coords) { 
     XYZW[0] = coords[0]; 
     XYZW[1] = coords[1]; 
     XYZW[2] = coords[2]; 
     XYZW[3] = coords[3]; 
    } 
    void SetColor(float *color) { 
     RGBA[0] = color[0]; 
     RGBA[1] = color[1]; 
     RGBA[2] = color[2]; 
     RGBA[3] = color[3]; 
    } 
}; 

Vertex Vertices[] = 
{ 
    { { 1.0f, 1.0f, 0.0f, 1.0f },{ 0.0f, 0.0f, 0.0f, 1.0f } }, // 0 
    { { 0.0f, 1.4f, 0.0f, 1.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } }, // 
}; 

std::vector<Vertex>TaskTwoVerticesN; 

void createObjects(void) 
{ 
    TaskTwoVerticesN.clear(); 
    // and this, running them one by one in a for loop does not work either 
    TaskTwoVerticesN.insert(TaskTwoVerticesN.begin(), Vertices, Vertices + (sizeof(Vertices)/sizeof(Vertices[0]))); 
} 

main(){ 
    createObjects(); 
} 

回答

1

其实,篡改你的代码足以运行

int main(){ 
    createObjects(); 
    std::cout << ((sizeof(Vertices)/sizeof(Vertices[0]))) << std::endl; 
    std::cout << TaskTwoVerticesN[0].XYZW[1] << std::endl; 
    std::cout << TaskTwoVerticesN[1].XYZW[1] << std::endl; 
    return 0; 
} 

导致这个输出

2 
1 
1.4 

因此,看起来这两个元素都是按照您的意图插入的。我真正改变的唯一的事情是main(),一些std :: cout和在你的结构体上删除typedef。

总之,你的插入是好的。

+0

我的代码仍然没有运行...!测试了一个类型的矢量,它工作正常...不工作这种类型,虽然....也尝试push_back(),但它也失败 –

+0

我应该发布我的整个代码? –

+0

抱歉,延迟。发布或发送给我,我会很高兴看。 –

相关问题