'Not rendering of triangle in opengl 2.1 (arch linux C++)

I am trying to render a triangle here in arch linux using opengl 2.1 but it wont render.

It wont say anything like an error.

my code:

engine.cpp

#include "engine.h"

int SCREEN_WDTH = 900;
int SCREEN_HEIGHT = 600;

float vertices[6] = {
    -0.5f,-0.5f,
    0.0f,0.5f,
    0.5f,-0.5f
};

void error_check()
{
    unsigned int error =glGetError();
    if (error != NULL)
    {
        std::cout << error << std::endl;
        std::cout << "error" << std::endl;
    }
    
}

int main()
{
    glfwInit();
    GLFWwindow* engine_window = glfwCreateWindow(SCREEN_WDTH,SCREEN_HEIGHT,"Senku engine 5",NULL,NULL);
    if (engine_window == NULL)
    {
        std::cout << "Glfw not working.." << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(engine_window);
    glewInit();
    glewExperimental = GL_TRUE;
    error_check();

    unsigned int buffer;

    glGenBuffers(1,&buffer);
    glBindBuffer(GL_ARRAY_BUFFER,buffer);
    glBufferData(GL_ARRAY_BUFFER,6,vertices,GL_STATIC_DRAW);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,2 * sizeof(float),0);

    error_check();
    
    while (!glfwWindowShouldClose(engine_window))
    {
        glfwPollEvents();

        glDrawArrays(GL_TRIANGLES,0,3);

        glfwSwapBuffers(engine_window);
    }
    glfwTerminate();
    return 0;
}

engine.h:

#include <iostream>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GLFW/glfw3.h>

makefile:

CC = g++
CF = -w

BINARY_NAME = -o Senku-engine-5

INCLUDE_LIBS = -lglfw -lGL -lX11 -lGLU -lGLEW

FILES = engine/engine.cpp 

all:engine/engine.cpp
    ${CC} ${CF} ${BINARY_NAME} ${FILES} ${INCLUDE_LIBS}

I dont is there is anything wrong with my code or my system So

Provide me an example on how to do it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source