diff --git a/.cache/clangd/index/coil.cpp.430626AC9C964D13.idx b/.cache/clangd/index/coil.cpp.430626AC9C964D13.idx index d8688a6..159e30a 100644 Binary files a/.cache/clangd/index/coil.cpp.430626AC9C964D13.idx and b/.cache/clangd/index/coil.cpp.430626AC9C964D13.idx differ diff --git a/.cache/clangd/index/coil.hpp.679854B715F05634.idx b/.cache/clangd/index/coil.hpp.679854B715F05634.idx index 361d0e5..a72632b 100644 Binary files a/.cache/clangd/index/coil.hpp.679854B715F05634.idx and b/.cache/clangd/index/coil.hpp.679854B715F05634.idx differ diff --git a/.cache/clangd/index/main.cpp.40336BE2C71C0AAD.idx b/.cache/clangd/index/main.cpp.40336BE2C71C0AAD.idx index 13e1b9f..0e4a6a2 100644 Binary files a/.cache/clangd/index/main.cpp.40336BE2C71C0AAD.idx and b/.cache/clangd/index/main.cpp.40336BE2C71C0AAD.idx differ diff --git a/.cache/clangd/index/segment.cpp.E58BEE5B986EAFA7.idx b/.cache/clangd/index/segment.cpp.E58BEE5B986EAFA7.idx index f871915..5165fd0 100644 Binary files a/.cache/clangd/index/segment.cpp.E58BEE5B986EAFA7.idx and b/.cache/clangd/index/segment.cpp.E58BEE5B986EAFA7.idx differ diff --git a/.cache/clangd/index/segment.hpp.C426421540A83234.idx b/.cache/clangd/index/segment.hpp.C426421540A83234.idx index c2a5228..798e13e 100644 Binary files a/.cache/clangd/index/segment.hpp.C426421540A83234.idx and b/.cache/clangd/index/segment.hpp.C426421540A83234.idx differ diff --git a/.cache/clangd/index/utils.cpp.9EA3B96F5F89167F.idx b/.cache/clangd/index/utils.cpp.9EA3B96F5F89167F.idx new file mode 100644 index 0000000..eea7dd7 Binary files /dev/null and b/.cache/clangd/index/utils.cpp.9EA3B96F5F89167F.idx differ diff --git a/.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx b/.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx new file mode 100644 index 0000000..880aea6 Binary files /dev/null and b/.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx differ diff --git a/CMakeLists.txt b/CMakeLists.txt index ece0ce6..b622d94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,14 @@ include(FetchContent) SET(PROJECT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp src/glad.c ${CMAKE_CURRENT_SOURCE_DIR}/src/coil/coil.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/coil/segment.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/utils.cpp ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src/coil ${CMAKE_CURRENT_SOURCE_DIR}/src/ui + ${CMAKE_CURRENT_SOURCE_DIR}/src/utils ) add_executable(TimeCoil ${PROJECT_SOURCES}) diff --git a/src/coil/coil.cpp b/src/coil/coil.cpp index 7f769a9..def6554 100644 --- a/src/coil/coil.cpp +++ b/src/coil/coil.cpp @@ -1,4 +1,9 @@ -#include "coil.hpp" +#include +#include + +#include +#include +#include Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments) : currentYear(currentYear) { @@ -14,4 +19,18 @@ std::vector &Coil::getSegments() { double Coil::getWidth() { return width; +} + +void Coil::render() { + prepareShaders(); + uint64_t VBO; + glGenBuffers(1, (unsigned int*) &(VBO)); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + for (CoilSegment segment : segments) { + double* vertices = segment.getVertices(); + uint64_t verticesLength = segment.getVerticesLength(); + glBufferData(GL_ARRAY_BUFFER, verticesLength, vertices, GL_STATIC_DRAW); + + + } } \ No newline at end of file diff --git a/src/coil/coil.hpp b/src/coil/coil.hpp index 456c230..f4b5d75 100644 --- a/src/coil/coil.hpp +++ b/src/coil/coil.hpp @@ -20,6 +20,7 @@ class Coil { Coil(uint32_t currentYear, uint32_t amountOfSegments); std::vector &getSegments(); double getWidth(); + void render(); }; #endif // COIL_HPP \ No newline at end of file diff --git a/src/coil/segment.cpp b/src/coil/segment.cpp index dc0ee2b..da5e022 100644 --- a/src/coil/segment.cpp +++ b/src/coil/segment.cpp @@ -1,13 +1,15 @@ -#include "segment.hpp" -#include "coil.hpp" -#include "glm/ext/matrix_float4x4.hpp" -#include "glm/ext/matrix_transform.hpp" -#include "glm/trigonometric.hpp" +#include +#include +#include #include #include #include #include +#include +#include +#include + // x, y, z, r, g, b #define FIELDS_IN_POINT 6 #define DAYS_IN_YEAR (isLeap? 366.0f : 365.0f) @@ -66,10 +68,6 @@ void CoilSegment::printVertices() { } } -double round_to_presicion( double value, int precision ) { - const int adjustment = pow(10,precision); - return floor( value*(adjustment) + 0.5 )/adjustment; -} double *CoilSegment::calculateSlice() { uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(double); @@ -129,7 +127,7 @@ void CoilSegment::constructSegment(double *slice) { transform = rotate( transform, - radians(daysDegree), + -radians(daysDegree), vec3( 0.0, 1.0, @@ -178,23 +176,12 @@ double *CoilSegment::getVertices() { return vertices; } -uint16_t CoilSegment::getVerticesLength() { +uint64_t CoilSegment::getVerticesLength() { return verticesLength; } -void CoilSegment::printSlice(double *slice) { - for (uint32_t i = 0; i < sliceDetalization+2; i ++) { - uint32_t offset = FIELDS_IN_POINT * i; - cout << "Point (" - << slice[offset + 0] << ", " - << slice[offset + 1] << ", " - << slice[offset + 2] << ", " - << ") rgb(" - << slice[offset + 3] << ", " - << slice[offset + 4] << ", " - << slice[offset + 5] << ")" - << endl; - } +void CoilSegment::render() { + } void CoilSegment::exportSliceToCSV(double *slice) { diff --git a/src/coil/segment.hpp b/src/coil/segment.hpp index a160223..9de3dba 100644 --- a/src/coil/segment.hpp +++ b/src/coil/segment.hpp @@ -14,7 +14,7 @@ class CoilSegment { uint32_t sliceDetalization; bool isLeap; double *vertices; - uint32_t verticesLength; + uint64_t verticesLength; void init(); double* calculateSlice(); @@ -25,10 +25,11 @@ class CoilSegment { void calculate(); void printVertices(); double *getVertices(); - uint16_t getVerticesLength(); + uint64_t getVerticesLength(); void printSlice(double *slice); void exportSliceToCSV(double *slice); void exportSegmentToCsv(); + void render(); }; #endif // COIL_SEGMENT_HPP \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index eb1d7b8..1e3b595 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,5 @@ #include #include -#include -#include #include #include #include @@ -21,32 +19,6 @@ void processInput(GLFWwindow *window) { } } -void renderGraphics(GLFWwindow *window) { - -} - -void gracefulExit(int code) { - glfwTerminate(); - exit(code); -} - -std::string readFile(std::string path) { - std::ifstream file(path); - if (!file.is_open()) - std::cerr << "File " << path << " was not found." << std::endl; - - std::string content = ""; - std::string buffer = ""; - - while(getline(file, buffer)) { - content += buffer + "\n"; - } - - content += '\0'; - file.close(); - return content; -} - void updateVertices(double (&vertices)[24]) { // if (RAND_0_1 < 0.99f) return; double a[] = { @@ -60,55 +32,6 @@ void updateVertices(double (&vertices)[24]) { memcpy(vertices, a, sizeof(a)); } -unsigned int prepareShaders() { - unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER); - unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - - std::string vertexShaderSourceString = readFile("../shaders/shader.vert"); - std::string fragmentShaderSourceString = readFile("../shaders/shader.frag"); - - const char *vertexShaderSource = vertexShaderSourceString.c_str(); - const char *fragmentShaderSource = fragmentShaderSourceString.c_str(); - - glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); - glCompileShader(vertexShader); - - int success; - char log[512]; - glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); - if (!success) { - glGetShaderInfoLog(vertexShader, 512, NULL, log); - std::cerr << "Could not compile vertex shader: " << log << std::endl; - gracefulExit(-1); - } - glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); - glCompileShader(fragmentShader); - - glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success); - if (!success) { - glGetShaderInfoLog(fragmentShader, 512, NULL, log); - std::cerr << "Could not compile fragment shader: " << log << std::endl; - gracefulExit(-1); - } - - unsigned int shaderProgram; - shaderProgram = glCreateProgram(); - glAttachShader(shaderProgram, vertexShader); - glAttachShader(shaderProgram, fragmentShader); - glLinkProgram(shaderProgram); - - glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); - if(!success) { - glGetProgramInfoLog(shaderProgram, 512, NULL, log); - std::cerr << "Could not link program: " << log << std::endl; - gracefulExit(-1); - } - - glDeleteShader(vertexShader); - glDeleteShader(fragmentShader); - return shaderProgram; -} - int main () { Coil c = Coil(2025, 1); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp new file mode 100644 index 0000000..8b0b629 --- /dev/null +++ b/src/utils/utils.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include +#include + +double round_to_presicion( double value, int precision ) { + const int adjustment = pow(10,precision); + return floor( value*(adjustment) + 0.5 )/adjustment; +} + +std::string readFile(std::string path) { + std::ifstream file(path); + if (!file.is_open()) + std::cerr << "File " << path << " was not found." << std::endl; + + std::string content = ""; + std::string buffer = ""; + + while(getline(file, buffer)) { + content += buffer + "\n"; + } + + content += '\0'; + file.close(); + return content; +} + +void gracefulExit(int code) { + glfwTerminate(); + exit(code); +} + +unsigned int prepareShaders() { + unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER); + unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + std::string vertexShaderSourceString = readFile("../shaders/shader.vert"); + std::string fragmentShaderSourceString = readFile("../shaders/shader.frag"); + + const char *vertexShaderSource = vertexShaderSourceString.c_str(); + const char *fragmentShaderSource = fragmentShaderSourceString.c_str(); + + glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); + glCompileShader(vertexShader); + + int success; + char log[512]; + glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(vertexShader, 512, NULL, log); + std::cerr << "Could not compile vertex shader: " << log << std::endl; + gracefulExit(-1); + } + glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); + glCompileShader(fragmentShader); + + glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(fragmentShader, 512, NULL, log); + std::cerr << "Could not compile fragment shader: " << log << std::endl; + gracefulExit(-1); + } + + unsigned int shaderProgram; + shaderProgram = glCreateProgram(); + glAttachShader(shaderProgram, vertexShader); + glAttachShader(shaderProgram, fragmentShader); + glLinkProgram(shaderProgram); + + glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); + if(!success) { + glGetProgramInfoLog(shaderProgram, 512, NULL, log); + std::cerr << "Could not link program: " << log << std::endl; + gracefulExit(-1); + } + + glDeleteShader(vertexShader); + glDeleteShader(fragmentShader); + return shaderProgram; +} \ No newline at end of file diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp new file mode 100644 index 0000000..29f684d --- /dev/null +++ b/src/utils/utils.hpp @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +double round_to_presicion( double value, int precision ); + +std::string readFile(std::string path); + +void gracefulExit(int code); + +unsigned int prepareShaders(); \ No newline at end of file