Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <glm/glm.hpp>
- #include <glm/gtc/matrix_transform.hpp>
- #include <glm/gtc/type_ptr.hpp>
- #include <glm/gtx/string_cast.hpp>
- #include "shader.h"
- #include "sphere.h"
- int main()
- {
- if( !glfwInit() )
- {
- std::cerr << "GLFW nije inicijaliziran\n";
- getchar();
- return -1;
- }
- glfwWindowHint(GLFW_SAMPLES, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // samo za MacOS
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- GLFWwindow* window = glfwCreateWindow( 1024, 768, "prog", nullptr, nullptr);
- if( window == nullptr )
- {
- std::cerr << "Nije prošao init glfw prozora. Npr. neki Intel GPU nisu 3.3 kompatibilni.\n";
- getchar();
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- if (glewInit() != GLEW_OK)
- {
- std::cerr << "GLEW nije inicijaliziran\n";
- getchar();
- glfwTerminate();
- return -1;
- }
- glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
- Sphere sphere(2.0f, 36, 18, true);
- unsigned int VAO, VBO, EBO;
- glGenVertexArrays(1, &VAO);
- glBindVertexArray(VAO);
- glGenBuffers(1, &VBO);
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, sphere.getInterleavedVertexSize(), sphere.getInterleavedVertices(), GL_STATIC_DRAW);
- glGenBuffers(1, &EBO);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sphere.getIndexSize(), sphere.getIndices(), GL_STATIC_DRAW);
- int stride = sphere.getInterleavedStride();
- // index, broj, tip, normalited, stride, offset
- glVertexAttribPointer(0, 3, GL_FLOAT, false, stride, (void*)0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 3, GL_FLOAT, false, stride, (void*)(3 * sizeof(float)));
- glEnableVertexAttribArray(1);
- glVertexAttribPointer(2, 2, GL_FLOAT, false, stride, (void*)(6 * sizeof(float)));
- glEnableVertexAttribArray(2);
- // const std::string vert_glsl = shaders_folder + "/vert.glsl";
- // const std::string frag_glsl = shaders_folder + "/frag.glsl";
- std::vector<ShaderInfo> shaders = {
- {GL_VERTEX_SHADER, "shaders/vert.glsl"},
- {GL_FRAGMENT_SHADER, "shaders/frag.glsl"}
- };
- Shader shader(shaders);
- do {
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- shader.use();
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
- glBindVertexArray(VAO);
- glDrawElements(GL_TRIANGLES, sphere.getIndexCount(), GL_UNSIGNED_INT, (void*)0);
- glBindVertexArray(0);
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
- glfwWindowShouldClose(window) == 0 );
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment