Specify opengl version in cmake, fix some artifacts

This commit is contained in:
2025-11-18 00:17:47 +03:00
parent 5ae1c82ef6
commit 8b84258c1a
7 changed files with 18 additions and 68 deletions

3
.vscode/launch.json vendored
View File

@@ -1,7 +1,4 @@
{
// 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": [
{

View File

@@ -21,6 +21,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
add_executable(TimeCoil ${PROJECT_SOURCES})
find_package(glfw3 3.4 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(OpenGL 3.3 REQUIRED)
find_package(glm REQUIRED)
target_link_libraries(TimeCoil glfw OpenGL::GL glm::glm)

View File

@@ -87,6 +87,10 @@ uint32_t Coil::fillEBO() {
for (CoilSegment &segment : segments) {
indicesLength += segment.getDaysAmount() * segment.getSlicePointsAmount() * 6;
}
// We subtract this because last day of the uppermost segment will not have connections to
// the next day beacuse there is no next day :)
indicesLength -= segments[segments.size() - 1].getSlicePointsAmount() * 6;
uint32_t *indices = (uint32_t *)malloc(indicesLength * sizeof(uint32_t));
uint32_t currentIndex = 0;
@@ -100,7 +104,10 @@ uint32_t Coil::fillEBO() {
for (uint32_t day = 0; day < segment.getDaysAmount(); day++) {
for (uint32_t pointOfSlice = 0; pointOfSlice < slicePointsAmount; pointOfSlice++) {
uint32_t dayOffset = day * slicePointsAmount;
uint32_t currentPointIndex = yearOffset + dayOffset + pointOfSlice - 1;
uint32_t currentPointIndex = yearOffset + dayOffset + pointOfSlice;
if (segmentNumber == segments.size() - 1 && day == segment.getDaysAmount() - 1) {
continue;
}
// First triangle
indices[currentIndex] = currentPointIndex;
currentIndex++;
@@ -108,18 +115,17 @@ uint32_t Coil::fillEBO() {
currentIndex++;
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
std::cout << segment.getSlicePointsAmount() << " " << pointOfSlice << std::endl;
// Second triangle
//if (pointOfSlice % (sliceDetalization+1) == 0 && pointOfSlice != 0) {
if (pointOfSlice == segment.getSliceDetailization() - 1 &&
pointOfSlice != 0) {
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
if (pointOfSlice == segment.getSlicePointsAmount() - 1) {
indices[currentIndex] = currentPointIndex - (slicePointsAmount - 1);
currentIndex++;
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
indices[currentIndex] = currentPointIndex;
} else {
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
indices[currentIndex] = currentPointIndex + slicePointsAmount + 1;
currentIndex++;
indices[currentIndex] = currentPointIndex + slicePointsAmount;

View File

@@ -7,7 +7,7 @@
// Coil segment is a one turn of a coil
// Coil slice is a set of points that define slice of coil
// (Segment) slice is a set of points that define shape of the segment
class Coil {
// distance between coil center and nearest to it coil edge

View File

@@ -151,58 +151,6 @@ void CoilSegment::constructSegment(float *slice) {
}
free(slice);
}
uint64_t CoilSegment::fillEBO(uint64_t EBO) {
uint64_t indicesLength = 6 * slicePointsAmount * getDaysAmount();
uint64_t currentIndex = 0;
uint64_t* indices = (uint64_t*) calloc(indicesLength, sizeof(uint64_t));
for (uint64_t day = 0; day < getDaysAmount() - 1; day ++) {
for (uint64_t pointOfSlice = 0; pointOfSlice < slicePointsAmount; pointOfSlice ++) {
// cout << currentIndex << endl;
uint64_t dayOffset = day * slicePointsAmount;
uint64_t currentPointIndex = dayOffset + pointOfSlice;
//First triangle
indices[currentIndex] = currentPointIndex;
currentIndex ++;
indices[currentIndex] = currentPointIndex + slicePointsAmount;
currentIndex ++;
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
//Second triangle
// if (pointOfSlice % (sliceDetalization+1) == 0 && pointOfSlice != 0) {
if (pointOfSlice == sliceDetailization+1) {
indices[currentIndex] = currentPointIndex - (slicePointsAmount - 1);
currentIndex++;
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
indices[currentIndex] = currentPointIndex;
} else {
indices[currentIndex] = currentPointIndex + 1;
currentIndex++;
indices[currentIndex] = currentPointIndex + slicePointsAmount + 1;
currentIndex ++;
indices[currentIndex] = currentPointIndex + slicePointsAmount;
}
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;
}
// 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

View File

@@ -34,7 +34,6 @@ class CoilSegment {
void printSlice(float *slice);
void exportSliceToCSV(float *slice);
void exportSegmentToCsv();
uint64_t fillEBO(uint64_t EBO);
uint16_t getYear();
uint16_t getDaysAmount();

View File

@@ -57,7 +57,7 @@ void processMousePosCallback(GLFWwindow *window, double deltaX, double deltaY) {
}
int main () {
Coil coil = Coil(2025, 3, 10, 2, 50, 10);
Coil coil = Coil(2024, 3, 10, 1, 50, 10);
srand(time(0));
glfwInit();
@@ -115,7 +115,7 @@ int main () {
coil.render();
glfwSwapBuffers(window);
glfwPollEvents();
glfwPollEvents();
}
gracefulExit(0);