From 420abba60ded94afa7f05fd0f27ce789569f9c91 Mon Sep 17 00:00:00 2001 From: Qi Date: Sun, 20 Nov 2022 23:08:00 +0800 Subject: [PATCH] Refined README.md --- README.md | 20 +++--- .../{algorithms.h => algorithms_warpup.h} | 0 src/gl_egine/include/gl_egine.h | 2 +- src/gl_egine/include/vertices.h | 64 +++++++++++++++++-- 4 files changed, 70 insertions(+), 16 deletions(-) rename src/algorithms/{algorithms.h => algorithms_warpup.h} (100%) diff --git a/README.md b/README.md index 7b0fe8a..06e3d81 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,15 @@ 2. basic key bindings, e.g. esc->quit 3. using texture with stb_image 4. use imgui for interaction -5. work with cmake -6. Updating into OpenGL3 with GLSL. -7. Allowing many interaction based on ImGui(for graphics study). +5. work with cmake (submodule, external depedencies) +6. Updating into OpenGL3 with GLSL, with GLFW +7. Basic algorithms: Float param, Halfedge structure(still caution with boundary) + ### TODO: -1. add light (commonly good for light) settings, summarize those rendering things into imgui. -2. Allow more man-graphics interaction (mouse rasting) -3. Integral algorithms like meshlab. -4. Add more things I know: multy threads, argparser, json file for rendering, ply loader(![happly](happly)) -5. CMake Tests and run time config(and loader) -6. More intuitive rotation.(4-dim numbers). -7. github workflows (and submodules for cross platform) -8. LICENSE(finally) +1. Package many things(light, material, shader, texture) into one `GL` object to manage, and allow more graphics lab. +2. Allow more human-graphics interaction (mouse rasting => select vertices, faces, change shapes, rotate => Hamilton number) +3. Using more fancy libs: argparser, json loader(for scenerio); make more concept about config. +4. More fancy algorithms: (marching cubes, ray tracing). +5. More modern things (tiny-cuda-nn). ### Main reference Mainly learnt from [polyscope](), [libigl](), [learnopengl], thanks to all of them! without who I will never be able to play on such an amazing graphics playground. \ No newline at end of file diff --git a/src/algorithms/algorithms.h b/src/algorithms/algorithms_warpup.h similarity index 100% rename from src/algorithms/algorithms.h rename to src/algorithms/algorithms_warpup.h diff --git a/src/gl_egine/include/gl_egine.h b/src/gl_egine/include/gl_egine.h index b893b24..48455b5 100644 --- a/src/gl_egine/include/gl_egine.h +++ b/src/gl_egine/include/gl_egine.h @@ -40,7 +40,7 @@ class GL } public: int add_obj(){ - + } public: diff --git a/src/gl_egine/include/vertices.h b/src/gl_egine/include/vertices.h index 215ac1c..580e5cc 100644 --- a/src/gl_egine/include/vertices.h +++ b/src/gl_egine/include/vertices.h @@ -10,23 +10,79 @@ class Vertices int vao_ID; int vbo_ID; int veo_ID; + int n_faces; + float *vbo; +private: + void assign(float* vbo_, unsigned int element, unsigned delta, std::vector& vx, std::vector fx){ + for (int i = 0; i < fx.size(); i++) + { + glm::vec3 va = v[f[i].x]; + glm::vec3 vb = v[f[i].y]; + glm::vec3 vc = v[f[i].z]; + vbo[i*3*element + element*0 + delta + 0]=va.x, vbo[i*3*element + element*0 + delta + 1]=va.y, vbo[i*3*element + element*0 + delta + 2]=va.z; + vbo[i*3*element + element*1 + delta + 0]=va.x, vbo[i*3*element + element*1 + delta + 1]=va.y, vbo[i*3*element + element*1 + delta + 2]=va.z; + vbo[i*3*element + element*2 + delta + 0]=va.x, vbo[i*3*element + element*2 + delta + 1]=va.y, vbo[i*3*element + element*2 + delta + 2]=va.z; + } + } + + void assign(float* vbo_, unsigned int element, unsigned delta, std::vector& vx, std::vector fx){ + for (int i = 0; i < fx.size(); i++) + { + glm::vec3 va = v[f[i].x]; + glm::vec3 vb = v[f[i].y]; + glm::vec3 vc = v[f[i].z]; + vbo[i*3*element + element*0 + delta + 0]=va.x, vbo[i*3*element + element*0 + delta + 1]=va.y; + vbo[i*3*element + element*1 + delta + 0]=va.x, vbo[i*3*element + element*1 + delta + 1]=va.y; + vbo[i*3*element + element*2 + delta + 0]=va.x, vbo[i*3*element + element*2 + delta + 1]=va.y; + } + } + public: Vertices(std::vector& v, std::vector& f){ - float a; + vbo = new float[3*(3+2+3)*f.size()]; + assign(vbo, 8, 0, v, f); + n_faces = f.size(); }; Vertices(std::vector& v, std::vector& f, std::vector& vt, std::vector& ft){ + vbo = new float[3*(3+2+3)*f.size()]; + assign(vbo, 8, 0, v, f); + n_faces = f.size(); + assign(vbo, 8, 3, vt, ft); } - Vertices(std::vector& v, std::vector& f, std::vector& vt, std::vector& ft, std::vector& vn, std::vector& fn){ - + vbo = new float[3*(3+2+3)*f.size()]; + assign(vbo, 8, 0, v, f); + n_faces = f.size(); + assign(vbo, 8, 3, vt, ft); + assign(vbo, 8, 5, vn, fn); } ~Vertices(){}; public: void load(){ + glGenBuffers(1, &vbo_ID); + glBindBuffer(GL_ARRAY_BUFFER, vbo_ID); + glBufferData(GL_ARRAY_BUFFER, sizeof(vbo), vbo, GL_STATIC_DRAW); + delete vbo; + glGenVertexArrays(1, &vao_ID); + glBindVertexArray(vao_ID); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void*)0); + glEnableVertexAttribArray(0); + + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void*)(3*sizeof(float))); + glEnableVertexAttribArray(1); }; void bind(){ - + glBindBuffer(GL_ARRAY_BUFFER, vbo_ID); + glBindVertexArray(vao_ID); + } + void render(){ + if(false) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glDrawArrays(GL_TRIANGLES, 0, 3*f.size()); } };