From 9cf523fb6c1d2299b674478b537dc642ea7e6c5b Mon Sep 17 00:00:00 2001 From: MrFloor Date: Fri, 27 May 2022 00:05:18 +0200 Subject: [PATCH] Hehehehe it still doesn't work --- src/Renderer.c | 6 ++++++ src/Renderer.h | 2 ++ src/lorenz.c | 42 +++++++++++++++++++++++++----------------- src/utils.c | 14 ++++++++++++++ src/utils.h | 8 ++++++++ 5 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 src/utils.c create mode 100644 src/utils.h diff --git a/src/Renderer.c b/src/Renderer.c index fc61075..62953b4 100644 --- a/src/Renderer.c +++ b/src/Renderer.c @@ -152,4 +152,10 @@ unsigned int createTexture(char* path){ return texture; } +void buffercpy(int VBO, void* ptr, int size){ + glBindBuffer(GL_ARRAY_BUFFER, VBO); + void* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); + memcpy(buffer, ptr, size); + glUnmapBuffer(GL_ARRAY_BUFFER); +} diff --git a/src/Renderer.h b/src/Renderer.h index 2c512e2..1a479e4 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -20,4 +20,6 @@ unsigned int createShader(char* vertexPath, char* fragmentPath); unsigned int createTexture(char* path); + +void buffercpy(int VBO, void* ptr, int size); #endif diff --git a/src/lorenz.c b/src/lorenz.c index bc16706..441903f 100644 --- a/src/lorenz.c +++ b/src/lorenz.c @@ -7,6 +7,7 @@ #include #include "Renderer.h" #include "Input.h" +#include "utils.h" float pos[3] = {0.0f, 0.0f, 0.0f}; @@ -29,6 +30,7 @@ void lorenzStep(float next[3], vec3 prev, float dt) { } int main(int argc, char *argv[]) { + GLFWwindow* window = initOpenGL(); glfwSetKeyCallback(window, &key_pressed); @@ -42,7 +44,7 @@ int main(int argc, char *argv[]) { glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, 10* sizeof(vec3), NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, 100* sizeof(vec3), NULL, GL_STREAM_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 ); glEnableVertexAttribArray(0); @@ -52,39 +54,44 @@ int main(int argc, char *argv[]) { mat4x4_ortho(proj, 0.0, 400.0, 0.0, 400.0, 0.1, 100.0); glUseProgram(shader1); - int projLoc = glGetUniformLocation(shader1, "proj"); + //int projLoc = glGetUniformLocation(shader1, "proj"); //glUniformMatrix4fv(projLoc, 1, GL_FALSE, *proj); // PointsArray vec3* lorenzPoints = malloc(3000 * sizeof(vec3)); memset(lorenzPoints, 0, 3000 * sizeof(vec3)); - vec3 initial = {0.1f, 0.1f, 0.1f}; - memcpy(lorenzPoints, initial, sizeof(vec3)); - vec3 sec = {0.2f, 0.2f, 0.2f}; - memcpy(lorenzPoints[1] , sec, sizeof(vec3)); + vec3 initial[] = {{0.1f, 0.1f, 0.1f},{ + 0.2f, 0.7f, 0.7f }}; + memcpy(lorenzPoints, initial, 2 * sizeof(vec3)); + int i = 2; + for (i=2; i<10; i++){ + vec3 next; + lorenzStep(next, lorenzPoints[i-1], 0.01); - for (int i=2; i<10; i++){ - float inc = 0.1 * (float)i; - vec3 next = {inc, inc, inc}; memcpy(lorenzPoints[i], next, sizeof(vec3)); + //printf("%f, %f\n", lorenzPoints[i][0], lorenzPoints[i][1]); } - float* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - memcpy(buffer, lorenzPoints, 10 * sizeof(vec3)); - glUnmapBuffer(GL_ARRAY_BUFFER); + vec3* mapped = malloc(3000 * sizeof(vec3)); + memset(mapped, 0, 3000 * sizeof(vec3)); + for(int j=0; j>=i; j++){ + mapped[j][0] = remap( -20.0f, 20.0f, -1.0f, 1.0f, lorenzPoints[j][0]); + mapped[j][1] = remap( -20.0f, 20.0f, -1.0f, 1.0f, lorenzPoints[j][1]); + mapped[j][2] = remap( -20.0f, 20.0f, -1.0f, 1.0f, lorenzPoints[j][2]); + + } + printf("%f \n", mapped[0][0]); + + buffercpy(VBO, lorenzPoints, sizeof(vec3) * 100); - int i=1; while(!glfwWindowShouldClose(window)) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(shader1); - i++; - if(i>10) - i=1; - glDrawArrays(GL_LINE_STRIP, 0, i); + glDrawArrays(GL_LINE_STRIP, 0, 10); glfwSwapBuffers(window); glfwPollEvents(); processInput(); @@ -93,6 +100,7 @@ int main(int argc, char *argv[]) { glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); free(lorenzPoints); + free(mapped); glfwTerminate(); return 0; } diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..ad5948c --- /dev/null +++ b/src/utils.c @@ -0,0 +1,14 @@ +#include "utils.h" + +float lerp(float a, float b, float t) { + return (1.0f - t) * a + b * t; +} + +float invLerp(float a, float b, float v){ + return (v - a) / (b - a); +} + +float remap(float a, float b, float A, float B, float value) { + float t = invLerp(a,b,value); + return lerp(A,B,t); +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..7cc0d23 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,8 @@ +#ifndef UTILS +#define UTILS + +float lerp(float a, float b, float t); +float invLerp(float a, float b, float value); +float remap(float a,float b, float A, float B, float value); + +#endif