C++/OpenGL VAO Problems

不羁的心 提交于 2019-11-28 13:59:31

The sizeof operator always returns the size of the underlying type. When you copy the content of loadToVAO to the update function, sizeof(vertices) is basically sizeof(float[18]), which is the total size of the array.

But inside the loadToVAO, the sizeof(vertices) takes the function parameter vertices as input and not the global variable. Since array parameters of undefined size in C++ are treated as points of the same type we have here:

sizeof(vertices) == sizeof(float[]) == sizeof(float*)

which is the size of a pointer (4 or 8) and not the size of the data anymore.

To solve this, you can either pass the size of the array also to the function, which is the C way to go. The more modern way is to use std::array or std::vector to store the data in the first place.

Edit: On the second look I saw that you used sizeof(vertices) * 8 in the first place. I'm not really sure where the 8 comes from, since you neither have 8 elements nor does a float have a size of 8 bytes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!