Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 330 core
- layout (location = 0) in vec3 aPos;
- void main()
- {
- gl_Position = vec4(aPos, 1.0f);
- }
- #version 330 core
- out vec4 FragColor;
- void main()
- {
- FragColor = vec4(1.0f,1.0f,1.0f,1.0f);
- }
- #include <glad/glad.h>
- #include <GLFW/glfw3.h>
- #include "shader.h"
- #include <glm/glm.hpp>
- #include <glm/gtc/matrix_transform.hpp>
- #include <glm/gtc/type_ptr.hpp>
- #include "Object.h"
- int width = 600;
- int height = 600;
- int main()
- {
- //window creation -----------------------------------------------------------
- glfwInit();
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_SAMPLES, 16);
- GLFWwindow* window = glfwCreateWindow(width, height, "Mumel", NULL, NULL);
- glfwMakeContextCurrent(window);
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
- {
- std::cout << "Error during GLAD initialization" << std::endl;
- glfwTerminate();
- return -1;
- }
- glViewport(0, 0, width, height);
- //----------------------------------------------------------------------
- Shader sh("./shader/vShader.vSh", "./shader/fShader.fSh");
- Circle * circle = new Circle(0.5); //is explained later in the post
- while (!glfwWindowShouldClose(window))
- {
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- sh.use();
- circle->draw();
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- }
- #ifndef OBJECT_H
- #define OBJECT_H
- #include <glad/glad.h>
- #include <iostream>
- #include "shader.h"
- #include <vector>
- class Circle
- {
- public:
- static const int size = 6;
- Circle()
- {
- std::vector<float> vertexData(3 * size);
- // center
- vertexData.at(0) = 0.0f;
- vertexData.at(1) = 0.0f;
- vertexData.at(2) = 0.0f;
- vertexData.at(3) = 0.5f;
- vertexData.at(5) = 0.0f;
- vertexData.at(4) = -0.5f;
- vertexData.at(6) = -0.5f;
- vertexData.at(8) = 0.0f;
- vertexData.at(7) = -0.5f;
- vertexData.at(9) = -0.5f;
- vertexData.at(11) = 0.0f;
- vertexData.at(10) = 0.5f;
- vertexData.at(12) = 0.5f;
- vertexData.at(14) = 0.0f;
- vertexData.at(13) = 0.5f;
- vertexData.at(15) = 0.5f;
- vertexData.at(17) = 0.0f;
- vertexData.at(16) = -0.5f;
- glGenBuffers(1, &VBO);
- glGenVertexArrays(1, &VAO);
- glBindVertexArray(VAO);
- float * dataArr = vertexData.data(); //The GLSL shader needs a C Array, this returns the pointer to the first array object used by std::vector
- int dataSize = vertexData.size();
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, dataSize * sizeof(float), dataArr, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- glBindVertexArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- void draw()
- {
- glBindVertexArray(VAO);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 3 * (size - 2));
- glBindVertexArray(0);
- }
- private:
- unsigned int VBO, VAO;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement