|
|
|
// clang-format off
|
|
|
|
#include <glad/glad.h>
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "shader.h"
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
std::cout << "Hello, World!" << std::endl;
|
|
|
|
|
|
|
|
glfwInit();
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
|
|
|
|
|
|
|
GLFWwindow* window = glfwCreateWindow(800, 600, "Voronoi", nullptr, nullptr);
|
|
|
|
if (window == nullptr) {
|
|
|
|
std::cout << "Failed to create GLFW window" << std::endl;
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
|
|
|
if (gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) == 0) {
|
|
|
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glViewport(0, 0, 800, 600);
|
|
|
|
|
|
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
|
|
|
|
|
|
// Add shaders
|
|
|
|
Shader shader("/home/olivier/CodeProject/Voronoi_2/src/shaders/shader.vert", "/home/olivier/CodeProject/Voronoi_2/src/shaders/shader.frag");
|
|
|
|
|
|
|
|
|
|
|
|
float vertices[] = {
|
|
|
|
0.5f, 0.5f, 0.0f, // top right
|
|
|
|
0.5f, -0.5f, 0.0f, // bottom right
|
|
|
|
-0.5f, -0.5f, 0.0f, // bottom left
|
|
|
|
-0.5f, 0.5f, 0.0f // top left
|
|
|
|
};
|
|
|
|
unsigned int indices[] = {
|
|
|
|
// note that we start from 0!
|
|
|
|
0, 1, 3, // first triangle
|
|
|
|
1, 2, 3 // second triangle
|
|
|
|
};
|
|
|
|
unsigned int VBO, VAO, EBO;
|
|
|
|
|
|
|
|
// Generate buffers
|
|
|
|
glGenVertexArrays(1, &VAO);
|
|
|
|
glGenBuffers(1, &VBO);
|
|
|
|
glGenBuffers(1, &EBO);
|
|
|
|
|
|
|
|
|
|
|
|
// Bind buffers
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
|
|
glBindVertexArray(VAO);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
|
|
|
|
|
|
|
// Copy data to buffers
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,
|
|
|
|
GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
// Set vertex attributes
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float),
|
|
|
|
(void*)nullptr);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glBindVertexArray(0);
|
|
|
|
|
|
|
|
// Copy data to buffers
|
|
|
|
|
|
|
|
// Draw loop
|
|
|
|
while (!glfwWindowShouldClose(window)) {
|
|
|
|
glfwPollEvents();
|
|
|
|
glClearColor(0.2f, 0.3f, 1.0f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
shader.use();
|
|
|
|
glBindVertexArray(VAO);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
glDrawElements(GL_LINES, 6, GL_UNSIGNED_INT, nullptr);
|
|
|
|
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwTerminate();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
}
|