Нужно вывести треугольники в виде сетки 9 на 9

Сам код, пишу в Visual Studio, вроде написал правильно, но что-то не выводит правильно.

#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <vector>
#include <glm/glm.hpp>
#include <iostream>


GLuint VBO;
std::vector<glm::vec3> Vertices;


static void RenderSceneCB()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glDrawArrays(GL_TRIANGLES, 0, Vertices.size());

    glDisableVertexAttribArray(0);

    glutSwapBuffers();
}


static void InitializeGlutCallbacks()
{
    glutDisplayFunc(RenderSceneCB);
}

static void CreateVertexBuffer()
{
    double x = -0.8;
    double y = 0.8;
    double z = 0;

    for (int i = 0; i < 9; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            /**/Vertices.push_back(glm::vec3(x, y, z));
            Vertices.push_back(glm::vec3(x + 0.1, y, z));
            Vertices.push_back(glm::vec3(x, y + 0.1, z));

            x += 0.2;
            
          
        }
        
        x = -0.8;
        y += 0.4;
       
        
   
    }
    
    std::cout<<Vertices.size();

    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, Vertices.size() * sizeof(glm::vec3), Vertices.data(), GL_STATIC_DRAW);
}


int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(1024, 768);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("OpenGL");

    InitializeGlutCallbacks();

    // Must be done after glut is initialized!
    GLenum res = glewInit();
    if (res != GLEW_OK) {
        fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
        return 1;
    }

    glClearColor(0.3f, 0.3f, 0.3f, 0.0f);

    CreateVertexBuffer();

    glutMainLoop();

    return 0;
}

Ответы (1 шт):

Автор решения: daniyar shukur

Ответ крылся в переменной Y, которая должна была спуститься на -0,4. В коде она была поднята на 0,4 тем самым уходя вверх за поле зрения.

Сам цикл:

for (int i = 0; i < 9; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            /**/
            Vertices.push_back(glm::vec3(x, y, z));
            Vertices.push_back(glm::vec3(x + 0.1, y, z));
            Vertices.push_back(glm::vec3(x, y + 0.1, z));

            x += 0.1;
            
          
        }
        x = -0.8;
        y -= 0.1;
       
         
}
→ Ссылка