diff --git a/.cache/clangd/index/coil.cpp.430626AC9C964D13.idx b/.cache/clangd/index/coil.cpp.430626AC9C964D13.idx index 159e30a..9bbceaf 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 a72632b..950db7b 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 0e4a6a2..8830485 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 5165fd0..2fb475a 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 798e13e..d0e2e74 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 index eea7dd7..9078e7b 100644 Binary files a/.cache/clangd/index/utils.cpp.9EA3B96F5F89167F.idx 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 index 880aea6..7e1faef 100644 Binary files a/.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx and b/.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx differ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..10efcb2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/", + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b622d94..9095e13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(TimeCoil) include(FetchContent) +SET(CMAKE_BUILD_TYPE Debug) 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 diff --git a/build.sh b/build.sh index eb5b42b..bee13f6 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_C_FLAGS="-g -v -da -Q -O0" .. && make && ./TimeCoil > ../points.csv && python ../tools/build_3d.py ../points.csv +cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_C_FLAGS="-g -v -da -Q -O0" .. && make && ./TimeCoil # > ../points.csv && python ../tools/build_3d.py ../points.csv diff --git a/shaders/shader.vert b/shaders/shader.vert index a287f1b..06e3b69 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -1,10 +1,15 @@ #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 col; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + out vec3 frag_col; void main() { frag_col = col; - gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); + gl_Position = projection * view * model * vec4(aPos, 1.0); } \ No newline at end of file diff --git a/src/coil/coil.cpp b/src/coil/coil.cpp index def6554..c57988a 100644 --- a/src/coil/coil.cpp +++ b/src/coil/coil.cpp @@ -1,15 +1,18 @@ +#include #include #include +#include #include #include #include -Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments) - : currentYear(currentYear) { +Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width) + : radius(radius), width(width), currentYear(currentYear) { for (short i = amountOfSegments / -2.; i < amountOfSegments / 2.; i++) { uint32_t year = this->currentYear + i; - segments.push_back(CoilSegment(this, year, segmentHeight, i, 3,false)); + + segments.push_back(CoilSegment(this, year, segmentHeight, i, sliceDetalization,false)); } }; @@ -17,20 +20,47 @@ std::vector &Coil::getSegments() { return segments; } -double Coil::getWidth() { +float 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); - +float Coil::getRadius() { + return radius; +} +void Coil::initGLBuffers() { + + glGenVertexArrays(1, &VAO); + glGenBuffers(1, &VBO); + glGenBuffers(1, &EBO); + + glBindVertexArray(VAO); + + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); + + // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0); + glEnableVertexAttribArray(0); + + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) (3 * sizeof(float))); + glEnableVertexAttribArray(1); + + glBindVertexArray(0); +} + +void Coil::render() { + glBindVertexArray(VAO); + std::cout << "Rendering a coil." << std::endl; + for (CoilSegment segment : segments) { + std::cout << "Rendering " << segment.getYear() << std::endl; + segment.fillVBO(); + uint64_t indicesCount = segment.fillEBO(EBO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); + // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + // glDrawArrays(GL_POINTS, 0, segment.getVerticesLength()); + glDrawElements(GL_TRIANGLES_ADJACENCY, sizeof(unsigned int)*indicesCount, GL_UNSIGNED_INT, 0); } + glBindVertexArray(0); } \ No newline at end of file diff --git a/src/coil/coil.hpp b/src/coil/coil.hpp index f4b5d75..c06eb5e 100644 --- a/src/coil/coil.hpp +++ b/src/coil/coil.hpp @@ -1,5 +1,6 @@ #include #include "segment.hpp" +#include #ifndef COIL_HPP #define COIL_HPP @@ -9,18 +10,22 @@ class Coil { // distance between coil center and nearest to it coil edge - double radius; + float radius; // distance between coil slices edges - double width; - double segmentHeight; + float width; + float segmentHeight; uint32_t currentYear; std::vector segments; + GLuint VBO, VAO, EBO; + public: - Coil(uint32_t currentYear, uint32_t amountOfSegments); + Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width); std::vector &getSegments(); - double getWidth(); + float getWidth(); + float getRadius(); void render(); + void initGLBuffers(); }; #endif // COIL_HPP \ No newline at end of file diff --git a/src/coil/segment.cpp b/src/coil/segment.cpp index da5e022..1f2267b 100644 --- a/src/coil/segment.cpp +++ b/src/coil/segment.cpp @@ -1,8 +1,10 @@ +#include #include #include #include #include #include +#include #include #include @@ -44,11 +46,12 @@ CoilSegment::CoilSegment( void CoilSegment::init () { verticesLength = DAYS_IN_YEAR * FIELDS_IN_POINT * (sliceDetalization+2); - vertices = (double *) calloc(verticesLength, sizeof(double)); + vertices = (float *) calloc(verticesLength, sizeof(float)); if (vertices == NULL) { cerr << "Allocation failed" << endl; exit(-1); } + calculate(); // cout << "Initialized CoilSegment" // << "(year: " << year // << ", height: " << height @@ -69,9 +72,19 @@ void CoilSegment::printVertices() { } -double *CoilSegment::calculateSlice() { - uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(double); - double *slice = (double *)malloc(size); +float *CoilSegment::calculateSlice() { + uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(float); + float *slice = (float *)malloc(size); + mat4 transform = mat4(1.); + transform = glm::scale( + transform, + vec3( + coil->getWidth(), + 10, + 1 + ) + ); + vec3 point = vec3(cos(0), sin(0), 0); // Start of a slice slice[0] = cos(0); slice[1] = sin(0); @@ -80,7 +93,7 @@ double *CoilSegment::calculateSlice() { slice[4] = 1; slice[5] = 1; - double degreeByPoint = -180. / (sliceDetalization + 1); + float degreeByPoint = -180. / (sliceDetalization + 1); for (uint32_t i = 1; i <= sliceDetalization; i ++) { uint32_t offset = FIELDS_IN_POINT * i; @@ -94,7 +107,7 @@ double *CoilSegment::calculateSlice() { } // End of a slice - uint32_t endIndex = (size / sizeof(double) - FIELDS_IN_POINT); + uint32_t endIndex = (size / sizeof(float) - FIELDS_IN_POINT); slice[endIndex + 0] = round_to_presicion(cos(radians(180.)), 5); slice[endIndex + 1] = round_to_presicion(sin(radians(180.)), 5); slice[endIndex + 2] = 0; @@ -105,17 +118,15 @@ double *CoilSegment::calculateSlice() { return slice; } -void CoilSegment::constructSegment(double *slice) { - - double degreesPerDay = 360.f / DAYS_IN_YEAR; +void CoilSegment::constructSegment(float *slice) { + float degreesPerDay = 360.f / DAYS_IN_YEAR; for (uint32_t day = 0; day < DAYS_IN_YEAR; day ++) { float daysDegree = day * degreesPerDay; - // TODO: replace hardcoded value to coil->getWidth(); vec3 daysPosition = vec3( - cos(radians(daysDegree)) * 200, + cos(radians(daysDegree)) * coil->getRadius(), 10* daysDegree/360., - sin(radians(daysDegree)) * 200 + sin(radians(daysDegree)) * coil->getRadius() ); mat4 transform = mat4(1.); @@ -150,14 +161,78 @@ void CoilSegment::constructSegment(double *slice) { vertices[currentPointOffset + 1] = point.y; vertices[currentPointOffset + 2] = point.z; - memcpy( - vertices + currentPointOffset + 3, - slice + slicePointOffset + 3, - 3 - ); + vertices[currentPointOffset + 3] = 0.5; + vertices[currentPointOffset + 4] = 0.5; + vertices[currentPointOffset + 5] = 0.5; + + // memcpy( + // vertices + currentPointOffset + 3, + // slice + slicePointOffset + 3, + // 3 + // ); } } } +void CoilSegment::fillVBO() { + // printVertices(); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * verticesLength, vertices, GL_STATIC_DRAW); +} +uint64_t CoilSegment::fillEBO(uint64_t EBO) { + uint64_t indicesLength = 6 * (sliceDetalization+2) * DAYS_IN_YEAR; + uint64_t currentIndex = 0; + uint64_t* indices = (uint64_t*) calloc(indicesLength, sizeof(uint64_t)); + for (uint64_t day = 0; day < DAYS_IN_YEAR; day ++) { + for (uint64_t pointOfSlice = 0; pointOfSlice < (sliceDetalization+2); pointOfSlice ++) { + // cout << currentIndex << endl; + uint64_t dayOffset = day * (sliceDetalization+2); + uint64_t offset = dayOffset + pointOfSlice; + //First triangle + indices[currentIndex] = offset; + currentIndex ++; + indices[currentIndex] = offset + (sliceDetalization+2); + currentIndex ++; + indices[currentIndex] = offset + 1; + currentIndex++; + //Second triangle + + if (pointOfSlice % (sliceDetalization+1) == 0 && pointOfSlice != 0) { + indices[currentIndex] = offset - (sliceDetalization+2); + currentIndex++; + indices[currentIndex] = offset + 1; + currentIndex++; + indices[currentIndex] = offset; + } else { + indices[currentIndex] = offset + 1; + currentIndex++; + indices[currentIndex] = offset + (sliceDetalization+3); + currentIndex ++; + indices[currentIndex] = offset + (sliceDetalization+2); + } + currentIndex ++; + } + } + + // for (uint64_t i = 0; i < indicesLength; i ++) { + // cout << indices[i] << ","; + // } + // cout << endl; + // cout << indicesLength << endl; + + if (currentIndex != indicesLength) { + cerr << "currentIndex == indicesLength assertion failed" << endl; + cerr << currentIndex << " " << indicesLength << endl; + } + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned long) * indicesLength, indices, GL_STATIC_DRAW); + free(indices); + return indicesLength; +} + +// void testEBO(uint64_t *EBO, uint64_t length) { +// for (uint64_t i = 0; i < length; i ++) { + +// } +// } // Sample layout of 2 slices with 3 points. // |x |y |z |r |g |b | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 @@ -165,45 +240,48 @@ void CoilSegment::constructSegment(double *slice) { // | slice | slice | // void CoilSegment::calculate() { - double *slice = calculateSlice(); + float *slice = calculateSlice(); constructSegment(slice); exportSegmentToCsv(); } -double *CoilSegment::getVertices() { - return vertices; -} +float *CoilSegment::getVertices() { return vertices; } -uint64_t CoilSegment::getVerticesLength() { - return verticesLength; -} +uint64_t CoilSegment::getVerticesLength() { return verticesLength; } + +uint16_t CoilSegment::getYear() { return year; } void CoilSegment::render() { } +void CoilSegment::exportSliceToCSV(float *slice) { + cout << "Exporting slice to csv" << endl; + std::ofstream outFile("./slice_export.csv"); -void CoilSegment::exportSliceToCSV(double *slice) { - cout << "x,y,z" << endl; + outFile << "x,y,z" << endl; for (uint32_t i = 0; i < sliceDetalization+2; i ++) { uint32_t offset = FIELDS_IN_POINT * i; - cout + outFile << slice[offset + 0] << "," << slice[offset + 1] << ",0" << endl; } } void CoilSegment::exportSegmentToCsv() { - cout << "x,y,z" << endl; + cout << "Exporting segment to csv" << endl; + std::ofstream outFile("./segment_export.csv"); + + outFile << "x,y,z" << endl; for (uint16_t day = 0; day < DAYS_IN_YEAR; day ++) { uint64_t dayOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT; for (uint32_t point_in_slice = 0; point_in_slice < (2+sliceDetalization); point_in_slice ++) { uint32_t sliceOffset = point_in_slice * FIELDS_IN_POINT; - cout << vertices[dayOffset + sliceOffset + 0] << "," + outFile << vertices[dayOffset + sliceOffset + 0] << "," << vertices[dayOffset + sliceOffset + 1] << "," << vertices[dayOffset + sliceOffset + 2] << endl; } diff --git a/src/coil/segment.hpp b/src/coil/segment.hpp index 9de3dba..2f4f5cd 100644 --- a/src/coil/segment.hpp +++ b/src/coil/segment.hpp @@ -13,23 +13,26 @@ class CoilSegment { int shift; uint32_t sliceDetalization; bool isLeap; - double *vertices; + float *vertices; uint64_t verticesLength; void init(); - double* calculateSlice(); - void constructSegment(double *slice); + float* calculateSlice(); + void constructSegment(float *slice); public: CoilSegment(Coil* coil, uint16_t year, uint16_t height, int shift, uint32_t sliceDetalization, bool isLeap); void calculate(); void printVertices(); - double *getVertices(); + float *getVertices(); uint64_t getVerticesLength(); - void printSlice(double *slice); - void exportSliceToCSV(double *slice); + void printSlice(float *slice); + void exportSliceToCSV(float *slice); void exportSegmentToCsv(); void render(); + void fillVBO(); + uint64_t fillEBO(uint64_t EBO); + uint16_t getYear(); }; #endif // COIL_SEGMENT_HPP \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1e3b595..a7b5a76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,11 +3,23 @@ #include #include #include +#include +#include +#include +#include +#include -#include "coil/coil.hpp" -#include "coil/segment.hpp" +#include +#include +#include -#define RAND_0_1 ((double)rand()) / RAND_MAX +using std::cerr; +using std::cout; +using std::endl; + +#define RAND_0_1 ((float)rand()) / RAND_MAX +#define DISPLAY_WIDTH 800 +#define DISPLAY_HEIGHT 600 void framebufferSizeCallback(GLFWwindow *window, int width, int height) { glViewport(10, 10, width-10, height-10); @@ -19,28 +31,108 @@ void processInput(GLFWwindow *window) { } } -void updateVertices(double (&vertices)[24]) { - // if (RAND_0_1 < 0.99f) return; - double a[] = { - -1.0f, 1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1, // upper left - -1.0f, -1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1, // bottom left - 1.0f, 1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1, // upper right - 1.0f, -1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1 // bottom right - }; - - // vertices = a; - memcpy(vertices, a, sizeof(a)); -} int main () { - Coil c = Coil(2025, 1); + + Coil c = Coil(2025, 1, 5, 50, 10); + + srand(time(0)); + glfwInit(); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#ifdef __APPLE__ + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif + + GLFWwindow *window = glfwCreateWindow(DISPLAY_WIDTH, DISPLAY_HEIGHT, "TimeCoil", NULL, NULL); + if (window == NULL) { + cerr << "Failed to create GLFW window." << endl; + gracefulExit(-1); + } + + glfwMakeContextCurrent(window); + glfwSetFramebufferSizeCallback(window, framebufferSizeCallback); + + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { + cerr << "Failed to initialize GLAD." << endl; + gracefulExit(-1); + } + + uint64_t shaderProgram = prepareShaders(); + glUseProgram(shaderProgram); + + glm::mat4 projection = glm::mat4(1.0f); + projection = glm::perspective(glm::radians(50.0f), (float)DISPLAY_WIDTH / (float)DISPLAY_HEIGHT, 0.001f, 2000.0f); + + unsigned int projectionLoc = glGetUniformLocation(shaderProgram, "projection"); + glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection)); + + + c.initGLBuffers(); + + // float vertices[] = { + // // positions // texture coords + // 05.5f, 0.5f, 0.0f, 1.0f, 1.0f, // top right + // 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // bottom right + // -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, // bottom left + // -0.5f, 0.5f, 0.0f, 0.0f, 1.0f // top left + // }; + // unsigned int indices[] = { + // 0, 1, 3, // first triangle + // 1, 2, 3 // second triangle + // }; + // unsigned int VBO, VAO, EBO; + // glGenVertexArrays(1, &VAO); + // glGenBuffers(1, &VBO); + // glGenBuffers(1, &EBO); + + // glBindVertexArray(VAO); + + // glBindBuffer(GL_ARRAY_BUFFER, VBO); + // glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); + // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + + // // position attribute + // glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); + // glEnableVertexAttribArray(0); + // // texture coord attribute + // glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); + // glEnableVertexAttribArray(1); + + while(!glfwWindowShouldClose(window)) { + processInput(window); + + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glm::mat4 model = glm::mat4(1.0f); + glm::mat4 view = glm::mat4(1.0f); + model = glm::rotate(model, glm::radians(5.0f), glm::vec3(1.0f, 0.0f, 0.0f)); + view = glm::translate(view, glm::vec3(0.0f, 0.0f, -89.0f)); + + unsigned int modelLoc = glGetUniformLocation(shaderProgram, "model"); + unsigned int viewLoc = glGetUniformLocation(shaderProgram, "view"); + + glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); + glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); + + c.render(); + // glBindVertexArray(VAO); + // glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + + glfwSwapBuffers(window); + glfwPollEvents(); + } // CoilSegment cs = CoilSegment(10, 0, false); - for (auto segment : c.getSegments()) { - // segment.printVertices(); - } + // for (auto segment : c.getSegments()) { + // // segment.printVertices(); + // } // cs.printVertices(); - return 0; + gracefulExit(0); // srand(time(0)); // glfwInit(); // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); @@ -66,10 +158,10 @@ int main () { // unsigned int shaderProgram = prepareShaders(); -// double *vertices = cs.getVertices(); +// float *vertices = cs.getVertices(); // unsigned int amountOfVerticies = cs.getVerticesLength(); // std::cout << amountOfVerticies << std::endl; -// // double vertices[] = { +// // float vertices[] = { // // -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, // upper left // // -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left // // 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // upper right @@ -92,10 +184,10 @@ int main () { // glBufferData(GL_ARRAY_BUFFER, amountOfVerticies, vertices, GL_STATIC_DRAW); // // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); -// glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(double), (void*)0); +// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0); // glEnableVertexAttribArray(0); -// glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(double), (void*) (3 * sizeof(double))); +// glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) (3 * sizeof(float))); // glEnableVertexAttribArray(1); // glBindVertexArray(0); @@ -108,8 +200,8 @@ int main () { // glUseProgram(shaderProgram); -// // double time = glfwGetTime(); -// // double greenValue = sin(time); +// // float time = glfwGetTime(); +// // float greenValue = sin(time); // // int vertexColorLocation = glGetUniformLocation(shaderProgram, "MyColor"); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 8b0b629..a6df396 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -5,7 +5,7 @@ #include #include -double round_to_presicion( double value, int precision ) { +float round_to_presicion( float value, int precision ) { const int adjustment = pow(10,precision); return floor( value*(adjustment) + 0.5 )/adjustment; } @@ -32,7 +32,7 @@ void gracefulExit(int code) { exit(code); } -unsigned int prepareShaders() { +uint64_t prepareShaders() { unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER); unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index 29f684d..ffdbe53 100644 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -3,10 +3,10 @@ #include #include -double round_to_presicion( double value, int precision ); +float round_to_presicion( float value, int precision ); std::string readFile(std::string path); void gracefulExit(int code); -unsigned int prepareShaders(); \ No newline at end of file +uint64_t prepareShaders(); \ No newline at end of file