diff --git a/src/main.c b/src/main.c index 17d2d45..e7e2298 100644 --- a/src/main.c +++ b/src/main.c @@ -67,7 +67,7 @@ int main() glBindVertexArray(vertexArrayID); - GLuint programID = loadShaders( "src/SimpleVertexShader.vertexshader", "src/SimpleFragmentShader.fragmentshader" ); + GLuint programID = loadShaders( "src/shader.vert", "src/shader.frag" ); GLuint matrixID = glGetUniformLocation(programID, "MVP"); @@ -78,7 +78,7 @@ int main() vec3s up = {0.0f, 1.0f, 0.0f}; vec3s planetPos = {0.0f, 0.0f, 0.0f}; - worldMesh mesh = generateWorld(planetPos); + worldMesh* mesh = generateWorld(planetPos); setVertexBufferData(mesh.vertices, mesh.triangles, mesh.triangleArrayCount); GLuint vertexbuffer; diff --git a/src/SimpleFragmentShader.fragmentshader b/src/shader.frag similarity index 100% rename from src/SimpleFragmentShader.fragmentshader rename to src/shader.frag diff --git a/src/SimpleVertexShader.vertexshader b/src/shader.vert similarity index 100% rename from src/SimpleVertexShader.vertexshader rename to src/shader.vert diff --git a/src/worldgen.c b/src/worldgen.c index 7f4c3e6..9c7a7e4 100644 --- a/src/worldgen.c +++ b/src/worldgen.c @@ -9,17 +9,18 @@ #define TWICE_RSQRT5 0.8944271909999159f #define GOLDEN 1.618033988749895f -worldMesh generateWorld(vec3s position) +worldMesh* generateWorld(vec3s position) { // placeholder struct for world mesh - world + worldMesh* mesh = (worldMesh*) malloc(sizeof(worldMesh)); + return mesh; } -void populateIcosphere(unsigned char order, GLfloat radius) +void populateIcosphere(worldMesh* mesh, unsigned char order, GLfloat radius) { int T = powf(4, order); - mesh.vertexArrayCount = (10*T + 2) * 3; // Final heap array size for vertices + mesh->vertexArrayCount = (10*T + 2) * 3; // Final heap array size for vertices // Initial vertex array. Not used other than to initialize heap array in mesh GLfloat vertices[] = { @@ -36,15 +37,15 @@ void populateIcosphere(unsigned char order, GLfloat radius) 9, 8, 1, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7 }; - mesh.triangleArrayCount = 20*T*3; - normalizeVertices(vertices, mesh.vertexArrayCount, radius); + mesh->triangleArrayCount = 20*T*3; + normalizeVertices(vertices, mesh->vertexArrayCount, radius); // Move vetex and triangle data into mesh struct - mesh.vertices = (GLfloat*) malloc(sizeof(GLfloat) * mesh.vertexArrayCount); - memcpy(mesh.vertices, vertices, sizeof(GLfloat) * mesh.vertexArrayCount); + mesh->vertices = (GLfloat*) malloc(sizeof(GLfloat) * mesh->vertexArrayCount); + memcpy(mesh->vertices, vertices, sizeof(GLfloat) * mesh->vertexArrayCount); - mesh.triangles = (unsigned int*) malloc(sizeof(unsigned int) * mesh.triangleArrayCount); - memcpy(mesh.triangles, triangles, sizeof(unsigned int) * 60); + mesh->triangles = (unsigned int*) malloc(sizeof(unsigned int) * mesh->triangleArrayCount); + memcpy(mesh->triangles, triangles, sizeof(unsigned int) * 60); } void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat radius) diff --git a/src/worldgen.h b/src/worldgen.h index 0786695..273da62 100644 --- a/src/worldgen.h +++ b/src/worldgen.h @@ -16,6 +16,6 @@ typedef struct worldMesh * @param[in] pos the position of the center of the roughly spherical world * @return the world mesh as a heap-allocated list of vertices. */ -worldMesh generateWorld(vec3s pos); -worldMesh populateIcosphere(unsigned char order, GLfoat radius); - +worldMesh* generateWorld(vec3s pos); +void populateIcosphere(worldMesh* mesh, unsigned char order, GLfoat radius); +void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat radius);