只有一个值被添加到向量中
only one value being added into the vectors
试图在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();
}
实际上,修改你的代码足以运行
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和删除struct上的类型定义。
相关文章:
- 有没有办法向这个向量添加元素?
- 这种方式是否可以接受向向量添加unique_ptr?
- 向向量添加元素
- 无法向向量添加回调
- 如何将向量添加到结构中以创建一个库存系统,在该系统中,我可以仅使用一个结构向系统添加多种不同的葡萄酒
- 在一个类中向向量添加元素不适用于其他类
- 以下向 c++ 向量添加元素的方法有什么区别
- 我可以在不推送向量的情况下向向量添加值吗?
- 向向量C++添加对
- 使用单词键将多个行号的向量添加到我的地图中
- 在C++中向指针数组中的向量添加元素
- 要创建一个一开始没有特定维度的类Vector,请在类中创建一个方法,允许向向量添加维度
- 一次向 C++ 向量添加多个元素
- STL - 向存储在 STL 映射中的向量添加值
- 向向量添加向量
- 如何向结构类型的向量添加点
- 为什么我的课'当我向向量添加实例时,会调用s析构函数
- 向c++向量添加新字段
- 在c++中向向量添加对象vs向向量添加指针
- 当Type为unique_ptr时,为向量添加运算符[]