我正在尝试使用GLfloats的2D矢量数组来绘制网格。我似乎无法使用2d向量获取glBufferData的正确代码,而不是我在网上看到的用于1D的示例。
UPDATED - 我必须将glBufferData乘以2,否则只有一半的网格被绘制....
struct point
{
GLfloat x;
GLfloat y;
};
float gridMinus = flatGrid_lines / 2.0f;
//point Vertices[20][20];
GLfloat HEIGHT = 20.0f;
GLfloat WIDTH = 20.0f;
vector<point> VerticesD(flatGrid_lines * flatGrid_lines);
//VERTICAL LINES
for (int i = 0; i < flatGrid_lines; i++)
{
for (int j = 0; j < flatGrid_lines; j++)
{
VerticesD[i + j * flatGrid_lines].x = (j - gridMinus) / gridMinus;
VerticesD[i + j * flatGrid_lines].y = (i - gridMinus) / gridMinus;
}
}
glGenVertexArrays(1, &vao_grid1);
glBindVertexArray(vao_grid1);
glGenBuffers(1, &vbo_grid1);
glBindBuffer(GL_ARRAY_BUFFER, vbo_grid1);
glBufferData(GL_ARRAY_BUFFER, VerticesD.size() * 2 * sizeof(GLfloat), &VerticesD[0], GL_STATIC_DRAW);