I need to generate a NxN resolution grid in the xy-plane with OpenGL. The final grid needs to be made by triangles (GL_TRIANGLES), so it should seem like the following example:
^
* | ----------
* | |\ |\ |\ |
* | | \| \| \|
* | ----------
* | |\ |\ |\ |
* y | | \| \| \|
* | ----------
* | |\ |\ |\ |
* | | \| \| \|
* | ----------
* |
* |-------------->
* x
Note that I need to store the grid in vertex-index form (given the structures by parameters).
My code at this point:
void generate_grid(
std::uint32_t N,
std::vector<glm::vec3>* vertices,
std::vector<glm::uvec3>* indices)
{
for (int i = 0; i < N; i++) {
glBegin(GL_TRIANGLES);
for (int j = 0; j < N; j++) {
int vertexNum = indices; // Index for vertex j of face i.
double[] vertexCoords = vertices[vertexNum]; // The vertex itself.
glVertex3f(vertexCoords, 0);
}
glEnd();
}
Any advice? Regards.
Aucun commentaire:
Enregistrer un commentaire