2016-09-24 44 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

抱歉,延遲。發佈或發送給我,我會很高興看。 –

相關問題