Мерцание точек при отрисовке GLFW Opengl

Пытаюсь нарисовать треугольник серпинского. Проблема в том что при отрисовке точки в случайной позиции, точки начинают мерцать. Код:

#include <GLFW/glfw3.h>
#include <ctime>
#include <cstdlib>
#include <iostream>


const unsigned int WIN_WIDTH = 640;
const unsigned int WIN_HEIGHT = 480;


struct colorRGB_t
{
    float red;
    float green;
    float blue;
};


struct point_crd_t
{
    float x;
    float y;
};


struct point_t
{
    point_crd_t position;
    float point_size;
    colorRGB_t point_color;
};


void init()
{
    //glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(0.1608, 0.1608, 0.1608, 0);
    glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, WIN_WIDTH, 0, WIN_HEIGHT, -1, 1);
    //glOrtho(0, WIN_WIDTH, WIN_HEIGHT, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}


void drawPoint(const point_t& point)
{
    glColor3f(point.point_color.red, point.point_color.green, point.point_color.blue);
    glPointSize(point.point_size);
    glBegin(GL_POINTS);
    glVertex2d(point.position.x, point.position.y);
    glEnd();
    
    glFlush();
}


point_crd_t getRandomPointCrd(const point_t* arr_point, size_t arr_size)
{
    int index = rand() % arr_size;
    return {arr_point[index].position.x, arr_point[index].position.y};
}


point_crd_t getMiddleDot(const point_crd_t& a, const point_crd_t& b)
{
    float middle_x = (a.x + b.x) / 2;
    float middle_y = (a.y + b.y) / 2;
    
    return { middle_x, middle_y };
}


int main(void)
{
    srand(time(NULL));
    const int ARR_MAIN_POINT_SIZE = 3;
    point_t arr_main_point[ARR_MAIN_POINT_SIZE] =
    {
    { {30, 140}, 5, {0.898, 0.898, 0} },
    { {500, 45}, 5, { 0.898, 0.898, 0 } },
    { {170, 300}, 5, { 0.898, 0.898, 0 }}
    };


    GLFWwindow* window;
    // Initialize the library
    if (!glfwInit())
        return -1;
    
    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(WIN_WIDTH, WIN_HEIGHT, "Hello World", NULL, NULL);
    if (!window){
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);
    
    point_t curr_dot = { {90, 140}, 5, {0.898, 0.898, 0} };
    while (!glfwWindowShouldClose(window)){
        init();
        //for (int i = 0; i < ARR_MAIN_POINT_SIZE; i++) {
        //    drawPoint(arr_main_point[i]);
        //}
        
        drawPoint(curr_dot);
        curr_dot.position = getMiddleDot(curr_dot.position, getRandomPointCrd(arr_main_point, ARR_MAIN_POINT_SIZE));
            
        glfwSwapBuffers(window);
        glfwPollEvents();
    }


    glfwTerminate();
    return 0;
}

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