Hehehehe it still doesn't work

This commit is contained in:
2022-05-27 00:05:18 +02:00
parent 0e19ef3610
commit 9cf523fb6c
5 changed files with 55 additions and 17 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -7,6 +7,7 @@
#include <linmath.h>
#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;
}

14
src/utils.c Normal file
View File

@@ -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);
}

8
src/utils.h Normal file
View File

@@ -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