
#include "GL/glew.h"
#include "GLFW/glfw3.h"
#include "glm/glm.hpp"
#include <iostream>
#include "utils.h"
using namespace std;
#define numVAOs 1
GLuint renderingProgram;
GLuint vao[numVAOs];
float x = 0.0f; // location of triangle on x axis
float inc = 0.01f; // offset for moving the triangle
float theta = 0;

void init(GLFWwindow* window) {
	renderingProgram = createShaderProgram(); //load, compile, create, attach and link shader programmes done here
	glGenVertexArrays(numVAOs, vao);
	glBindVertexArray(vao[0]);
}
void display(GLFWwindow* window, double currentTime) {
	glClearColor(1.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glUseProgram(renderingProgram); //specify linked program to use

	theta += inc;
	if (theta > glm::radians(360.0))
		theta = 0;
	GLuint offsetLoc = glGetUniformLocation(renderingProgram, "offset"); // get ptr to "offset" variable in vertex shader
	glProgramUniform1f(renderingProgram, offsetLoc, theta); // send value in "x" to "offset"

	glDrawArrays(GL_TRIANGLES, 0, 3);  //three vertices of triangle primitive

}
int main(void) {
	if (!glfwInit()) { exit(EXIT_FAILURE); }
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	GLFWwindow* window = glfwCreateWindow(600, 600, "Triangle glfw window", NULL, NULL);
	glfwMakeContextCurrent(window);
	if (glewInit() != GLEW_OK) { exit(EXIT_FAILURE); }
	glfwSwapInterval(1);
	init(window);
	while (!glfwWindowShouldClose(window)) {
		display(window, glfwGetTime());
		glfwSwapBuffers(window);
		glfwPollEvents();
	}
	glfwDestroyWindow(window);
	glfwTerminate();
	exit(EXIT_SUCCESS);
}

