Browse Source

updated API for request functions, fixed err in add_actors_to_scene where it took an array of actors, not an array of pointers

Iver 4 months ago
parent
commit
d1f7fc1d23

BIN
build/librasteriver.so


BIN
build/main.bin


BIN
compiled_libs/librasteriver.so


BIN
fonts/ComicSans-Regular.ttf


BIN
fonts/QwitcherGrypen-Bold.ttf


+ 48 - 12
src/headers/functions.h

@@ -4,24 +4,60 @@
 #include "custom_types.h"
 #include "sourparse.h"
 
-RI_mesh* RI_request_meshes(int RI_number_of_requested_objects, char **filenames, int RI_request_just_mesh); // Load object file(s)
-RI_actor* RI_request_actors(int RI_number_of_requested_actors); // Load texture file(s)
-RI_material* RI_request_materials(int RI_number_of_requested_materials); // Create materials
-RI_texture* RI_request_textures(int RI_number_of_requested_textures, RI_texture_creation_data *texture_creation_data); // Create new actor(s)
-RI_scene* RI_request_scenes(int RI_number_of_requested_scenes);
-int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title); // Initialize RasterIver
-int RI_stop(int result); // Stop RasterIver safely and free memory
-int RI_render(RI_scene *scene, RI_texture *target_texture, int clear_texture); // Render a scene to a texture
-int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor *actors, RI_scene *scene);
-void RI_euler_rotation_to_quaternion(RI_vector_4f* quaternion, RI_vector_3f euler_rotation);
+// ----- request functions
+
+// Load an object file
+RI_mesh* RI_request_mesh(char *filename); 
+
+// Allocate a new actor
+RI_actor* RI_request_actor(); 
+
+// Allocate a new material
+RI_material* RI_request_material(); 
+
+// Load a texture
+RI_texture* RI_request_texture(char *filename); 
+
+// Allocate a new texture without using an image file
+RI_texture* RI_request_empty_texture(RI_vector_2 resolution); 
+
+// Allocate a new scene
+RI_scene* RI_request_scene(); 
+
+
+// ----- master services
+
+// Initialize RasterIver
+int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title); 
+
+// Stop RasterIver safely and free memory
+int RI_stop(int result); 
+
 // Tick RasterIver.
 // Copies the window's texture (ri.frame_buffer.image_buffer) onto the screen, calls SDL_RenderPresent, handles SDL events, increases ri.frame by 1, and optionally clears the window's texture
 void RI_tick(int clear_window_texture_after_rendering); 
+
+
+// ----- rendering services
+
+// Render a scene to a texture
+int RI_render(RI_scene *scene, RI_texture *target_texture, int clear_texture); 
+
+// Renders text to a texture
 void RI_render_text(SP_font *font, RI_texture *target_texture, RI_vector_2f position, uint32_t color, int bezier_resolution, double size, char *text);
+
+// Draws a line on a texture
 void RI_draw_line(RI_texture *target_texture, RI_vector_2 point_a, RI_vector_2 point_b, uint32_t color);
+
+// Sets all pixels in a texture to a color
+void RI_wipe_texture(RI_texture *target_texture, uint32_t color);
+
+
+// ------ other
+
+int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor **actors, RI_scene *scene);
+void RI_euler_rotation_to_quaternion(RI_vector_4f* quaternion, RI_vector_3f euler_rotation);
 RI_vector_2f v2_to_2f(RI_vector_2 v);
 RI_vector_2 v2f_to_2(RI_vector_2f v);
-void RI_clear_texture(RI_texture *target_texture);
-RI_texture* RI_request_empty_texture(RI_vector_2 resolution);
 
 #endif

+ 9 - 19
src/launch_program/main.c

@@ -18,35 +18,25 @@ int main(){
 
     RI_init(700, 700, "This is RasterIver 2.0!!");
 
-    // data for loading files
-    char *filenames[] = {"objects/unit_plane.obj"};
-
-    // requesting assets
-    RI_mesh* meshes = RI_request_meshes(1, filenames, 0);
-    RI_material* materials = RI_request_materials(2);
-    RI_actor* actors = RI_request_actors(2);
-    RI_scene* scenes = RI_request_scenes(1);
-
-    RI_scene* scene = &scenes[0];
+    RI_scene* scene = RI_request_scene();
 
     // meshes
-    RI_mesh* plane_mesh = &meshes[0];
+    RI_mesh* plane_mesh = RI_request_mesh("objects/unit_plane.obj");
 
     // materials
-    RI_material* text_plane_material = &materials[0];
+    RI_material* text_plane_material = RI_request_material();
     text_plane_material->flags = RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_DOUBLE_SIDED;
     text_plane_material->texture_reference = RI_request_empty_texture((RI_vector_2){400, 400});
     text_plane_material->albedo = 0xFFFFFFFF;
     text_plane_material->fragment_shader = shader_function;
 
-    RI_material* bill_material = &materials[1];
+    RI_material* bill_material = RI_request_material();
     bill_material->flags = RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_DOUBLE_SIDED;
-    RI_texture_creation_data tex_data[1] = {(RI_texture_creation_data){"textures/THIS IS THE WALL.png", {0, 0}}};
-    bill_material->texture_reference = RI_request_textures(1, tex_data);
+    bill_material->texture_reference = RI_request_texture("textures/THIS IS THE WALL.png");
     bill_material->albedo = 0xFFFFFFFF;
 
     // actors
-    RI_actor* text_plane = &actors[0];
+    RI_actor* text_plane = RI_request_actor();
     text_plane->material_reference = text_plane_material;
     text_plane->mesh_reference = plane_mesh;
     text_plane->transform.scale = (RI_vector_3f){300, 300, 300};
@@ -54,7 +44,7 @@ int main(){
     text_plane->transform.rotation = (RI_vector_4f){0, 1, 0, 0};
     RI_euler_rotation_to_quaternion(&text_plane->transform.rotation, (RI_vector_3f){-3.1415926 / 2, 0, 0});
     
-    RI_actor* bill_plane = &actors[1];
+    RI_actor* bill_plane = RI_request_actor();
     bill_plane->material_reference = bill_material;
     bill_plane->mesh_reference = plane_mesh;
     bill_plane->transform.scale = (RI_vector_3f){300, 300, 300};
@@ -64,7 +54,7 @@ int main(){
 
     RI_vector_4f rotation_delta;
 
-    RI_add_actors_to_scene(2, actors, scene);
+    RI_add_actors_to_scene(2, (RI_actor*[]){text_plane, bill_plane}, scene);
 
     scene->FOV = 1.5; // 90 degrees in radians
     scene->minimum_clip_distance = 0.1;
@@ -78,7 +68,7 @@ int main(){
     scene->antialiasing_subsample_resolution = 8;
     scene->flags = RI_SCENE_DONT_USE_AA;
 
-    RI_clear_texture(text_plane_material->texture_reference);
+    RI_wipe_texture(text_plane_material->texture_reference, 0xFF000000);
 
     RI_render_text(comic_sans, text_plane_material->texture_reference, (RI_vector_2f){0, 0}, 0xFFFFFFFF, 2, 80, "WOWWWW!!!11!!");
     RI_render_text(cal_sans, text_plane_material->texture_reference, (RI_vector_2f){0, 200}, 0xFFFFFFFF, 2, 80, "Wow!!");

+ 180 - 230
src/library/rasteriver.c

@@ -174,9 +174,9 @@ RI_texture* RI_request_empty_texture(RI_vector_2 resolution){
     return &ri.loaded_textures[previous_loaded_texture_count];
 }
 
-void RI_clear_texture(RI_texture *target_texture){
+void RI_wipe_texture(RI_texture *target_texture, uint32_t color){
     for (int i = 0; i < target_texture->resolution.x * target_texture->resolution.y; ++i){
-        target_texture->image_buffer[i] = 0x00000000;
+        target_texture->image_buffer[i] = color;
     }
 }
 
@@ -375,7 +375,7 @@ void RI_render_text(SP_font *font, RI_texture *target_texture, RI_vector_2f posi
     }
 }
 
-int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor *actors, RI_scene *scene){
+int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor **actors, RI_scene *scene){
     int previous_actor_count = scene->actor_count;
 
     scene->actor_count += RI_number_of_actors_to_add_to_scene;
@@ -383,276 +383,227 @@ int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor *ac
     scene->actors = RI_realloc(scene->actors, sizeof(RI_actor *) * scene->actor_count);
 
     for (int i = 0; i < RI_number_of_actors_to_add_to_scene; ++i){
-        scene->actors[i + previous_actor_count] = &actors[i];
+        scene->actors[i + previous_actor_count] = actors[i];
     }
 
     return 0;
 }
 
-RI_scene* RI_request_scenes(int RI_number_of_requested_scenes){
-    int previous_scene_count = ri.scene_count;
-    ri.scene_count += RI_number_of_requested_scenes;
-    
-    ri.scenes = RI_realloc(ri.scenes, sizeof(RI_scene) * ri.scene_count);
-
-    for (int i = 0; i < RI_number_of_requested_scenes; ++i){
-        RI_scene new_scene = {0};
-
-        new_scene.actor_count = 0;
-        new_scene.actors = NULL;
-        new_scene.faces_to_render = NULL;
-        new_scene.antialiasing_subsample_resolution = 4;
-
-        ri.scenes[i + previous_scene_count] = new_scene;
-    }
-
-    return ri.scenes;
+RI_scene* RI_request_scene(int RI_number_of_requested_scenes){
+    RI_scene *new_scene = RI_malloc(sizeof(RI_scene));
+
+    new_scene->actor_count = 0;
+    new_scene->actors = NULL;
+    new_scene->faces_to_render = NULL;
+    new_scene->antialiasing_subsample_resolution = 4;
+    new_scene->camera_position = (RI_vector_3f){0, 0, 0};
+    new_scene->camera_rotation = (RI_vector_4f){1, 0, 0, 0};
+    new_scene->face_count = 0;
+    new_scene->faces_to_render = NULL;
+    new_scene->flags = 0;
+    new_scene->FOV = 3.14159 / 2;
+    new_scene->min_clip = 0.01;
+    new_scene->minimum_clip_distance = 0.01;
+
+    return new_scene;
 }
 
-RI_actor* RI_request_actors(int RI_number_of_requested_actors){
-    int previous_actor_count = ri.actor_count;
-    ri.actor_count += RI_number_of_requested_actors;
-    
-    ri.actors = RI_realloc(ri.actors, sizeof(RI_actor) * ri.actor_count);
-
-    for (int i = 0; i < RI_number_of_requested_actors; ++i){
-        RI_actor new_actor = {0};
-
-        new_actor.mesh_reference = NULL;
-        new_actor.material_reference = NULL;
+RI_actor* RI_request_actor(int RI_number_of_requested_actors){
+    RI_actor *new_actor = RI_malloc(sizeof(RI_scene));
 
-        ri.actors[i + previous_actor_count] = new_actor;
-    }
+    new_actor->mesh_reference = NULL;
+    new_actor->material_reference = NULL;
+    new_actor->transform.position = (RI_vector_3f){0, 0, 0};
+    new_actor->transform.scale = (RI_vector_3f){1, 1, 1};
+    new_actor->transform.rotation = (RI_vector_4f){1, 0, 0, 0};
 
-    return ri.actors;
+    return new_actor;
 }
 
-RI_material* RI_request_materials(int RI_number_of_requested_materials){
-    int previous_material_count = ri.material_count;
-    ri.material_count += RI_number_of_requested_materials;
-
-    ri.materials = RI_realloc(ri.materials, sizeof(RI_material) * ri.material_count);
+RI_material* RI_request_material(){
+    RI_material *new_material = RI_malloc(sizeof(RI_actor));
 
-    for (int i = previous_material_count; i < ri.material_count; ++i){
-        ri.materials[i] = ri.error_material;
-    }
-
-    return ri.materials;
+    *new_material = ri.error_material;
+    
+    return new_material;
 }
 
-RI_texture* RI_request_textures(int RI_number_of_requested_textures, RI_texture_creation_data *texture_creation_data){
-    int previous_loaded_texture_count = ri.loaded_texture_count;
-
-    ri.loaded_texture_count += RI_number_of_requested_textures;
+RI_texture* RI_request_texture(char *filename){
+    RI_texture *new_texture = RI_malloc(sizeof(RI_texture));
 
-    ri.loaded_textures = RI_realloc(ri.loaded_textures, sizeof(RI_texture) * ri.loaded_texture_count);
+    unsigned char* temp_texture = stbi_load(filename, &new_texture->resolution.x, &new_texture->resolution.y, NULL, 4);
     
-    for (int i = 0; i < RI_number_of_requested_textures; i++){
-        RI_texture new_texture = {0};
-        
-        char *current_texture_filename = texture_creation_data[i].filename;
+    if(stbi_failure_reason()){
+        *new_texture = ri.error_texture;
+    }
+    else {
+        new_texture->image_buffer = RI_malloc(sizeof(uint32_t) * new_texture->resolution.x * new_texture->resolution.y);
 
-        unsigned char* temp_texture = stbi_load(current_texture_filename, &new_texture.resolution.x, &new_texture.resolution.y, NULL, 4);
-        
-        if(stbi_failure_reason()){
-            new_texture = ri.error_texture;
+        for (int i = 0; i < new_texture->resolution.x * new_texture->resolution.y; ++i){
+            unsigned char r = temp_texture[i * 4];
+            unsigned char g = temp_texture[i * 4 + 1];
+            unsigned char b = temp_texture[i * 4 + 2];
+            unsigned char a = temp_texture[i * 4 + 3];
+            
+            new_texture->image_buffer[i] = (a << 24 | r << 16 | g << 8 | b);
         }
-        else {
-            new_texture.image_buffer = RI_malloc(sizeof(uint32_t) * new_texture.resolution.x * new_texture.resolution.y);
+    }
 
-            for (int i = 0; i < new_texture.resolution.x * new_texture.resolution.y; ++i){
-                unsigned char r = temp_texture[i * 4];
-                unsigned char g = temp_texture[i * 4 + 1];
-                unsigned char b = temp_texture[i * 4 + 2];
-                unsigned char a = temp_texture[i * 4 + 3];
-                
-                new_texture.image_buffer[i] = (a << 24 | r << 16 | g << 8 | b);
-            }
-        }
+    stbi_image_free(temp_texture);
 
-        ri.loaded_textures[previous_loaded_texture_count + i] = new_texture;
+    return new_texture;
+}
 
-        stbi_image_free(temp_texture);
-    }
+RI_mesh* RI_request_mesh(char *filename){
+    RI_mesh *new_mesh = RI_calloc(1, sizeof(RI_mesh));
 
-    return ri.loaded_textures;
-}
+    FILE *file = fopen(filename, "r");
 
-RI_mesh* RI_request_meshes(int RI_number_of_requested_meshes, char **filenames, int RI_return_just_mesh){
-    int meshes_already_loaded_count = ri.loaded_mesh_count;
+    if (!file){
+        debug("[Mesh Loader] Error! File \"%s\" not found", filename);
+        RI_stop(1);
+    }
     
-    RI_mesh* mesh;
+    char line[512];
     
-    if (!RI_return_just_mesh) {
-        ri.loaded_mesh_count += RI_number_of_requested_meshes;
-
-        ri.loaded_meshes = RI_realloc(ri.loaded_meshes, sizeof(RI_mesh) * ri.loaded_mesh_count);
-    }
-    else {
-        mesh = RI_malloc(sizeof(RI_mesh));
-    }
-
-    for (int i = 0; i < RI_number_of_requested_meshes; i++){
-        RI_mesh new_mesh_data_struct = {0};
-
-        FILE *file = fopen(filenames[i], "r");
-
-        if (!file){
-            debug("[Mesh Loader] Error! File \"%s\" not found", filenames[i]);
-            RI_stop(1);
+    while (fgets(line, sizeof(line), file)) {
+        if (line[0] == 'f' && line[1] == ' ') { // face
+            new_mesh->face_count++;
         }
-        
-        char line[512];
-        
-        while (fgets(line, sizeof(line), file)) {
-            if (line[0] == 'f' && line[1] == ' ') { // face
-                new_mesh_data_struct.face_count++;
-            }
-            else if (line[0] == 'v' && line[1] == ' ') { // vertex
-                new_mesh_data_struct.vertex_count++;
-            }
-            else if (line[0] == 'v' && line[1] == 'n') { // normal
-                new_mesh_data_struct.normal_count++;
-            }
-            else if (line[0] == 'v' && line[1] == 't') { // UV
-                new_mesh_data_struct.uv_count++;
-            }
+        else if (line[0] == 'v' && line[1] == ' ') { // vertex
+            new_mesh->vertex_count++;
         }
-        
-        fclose(file);
-        
-        new_mesh_data_struct.faces = RI_malloc(sizeof(RI_face) * new_mesh_data_struct.face_count);
-        new_mesh_data_struct.vertex_positions = RI_malloc(sizeof(RI_vector_3f) * new_mesh_data_struct.vertex_count);
-        new_mesh_data_struct.normals = RI_malloc(sizeof(RI_vector_3f) * new_mesh_data_struct.normal_count);
-        new_mesh_data_struct.uvs = RI_malloc(sizeof(RI_vector_2f) * new_mesh_data_struct.uv_count);
-
-        FILE *file_again = fopen(filenames[i], "r");
-
-        int current_face_index = 0;
-        int current_vertex_index = 0;
-        int current_normal_index = 0;
-        int current_uv_index = 0;
-
-        int has_normals, has_uvs;
-        has_normals = has_uvs = 0;
-
-        while (fgets(line, sizeof(line), file_again)) {
-            if (line[0] == 'f' && line[1] == ' ') {
-                int vertex_0_index, vertex_1_index, vertex_2_index, normal_0_index, normal_1_index, normal_2_index, uv_0_index, uv_1_index, uv_2_index;
+        else if (line[0] == 'v' && line[1] == 'n') { // normal
+            new_mesh->normal_count++;
+        }
+        else if (line[0] == 'v' && line[1] == 't') { // UV
+            new_mesh->uv_count++;
+        }
+    }
 
-                int matches = sscanf(line, "f %d/%d/%d %d/%d/%d %d/%d/%d/", 
-                    &vertex_0_index, &uv_0_index, &normal_0_index, 
-                    &vertex_1_index, &uv_1_index, &normal_1_index, 
-                    &vertex_2_index, &uv_2_index, &normal_2_index);
-    
-                if (matches != 9){
-                    vertex_0_index = -1;
-                    vertex_1_index = -1;
-                    vertex_2_index = -1;
-                    
-                    normal_0_index = -1;
-                    normal_1_index = -1;
-                    normal_2_index = -1;
-                    
-                    uv_0_index = -1;
-                    uv_1_index = -1;
-                    uv_2_index = -1;
-    
-                    if (strchr(line, '/')){
-                        sscanf(line, "f %d//%d %d//%d %d//%d", 
-                            &vertex_0_index, &normal_0_index, 
-                            &vertex_1_index, &normal_1_index, 
-                            &vertex_2_index, &normal_2_index);
-                    
-                        has_normals = 1;
-                    }
-                    else {
-                        sscanf(line, "f %d %d %d", 
-                            &vertex_0_index, 
-                            &vertex_1_index, 
-                            &vertex_2_index);
-                    }
+    rewind(file);
+        
+    new_mesh->faces = RI_malloc(sizeof(RI_face) * new_mesh->face_count);
+    new_mesh->vertex_positions = RI_malloc(sizeof(RI_vector_3f) * new_mesh->vertex_count);
+    new_mesh->normals = RI_malloc(sizeof(RI_vector_3f) * new_mesh->normal_count);
+    new_mesh->uvs = RI_malloc(sizeof(RI_vector_2f) * new_mesh->uv_count);
+
+    int current_face_index = 0;
+    int current_vertex_index = 0;
+    int current_normal_index = 0;
+    int current_uv_index = 0;
+
+    int has_normals, has_uvs;
+    has_normals = has_uvs = 0;
+
+    while (fgets(line, sizeof(line), file)) {
+        if (line[0] == 'f' && line[1] == ' ') {
+            int vertex_0_index, vertex_1_index, vertex_2_index, normal_0_index, normal_1_index, normal_2_index, uv_0_index, uv_1_index, uv_2_index;
+
+            int matches = sscanf(line, "f %d/%d/%d %d/%d/%d %d/%d/%d/", 
+                &vertex_0_index, &uv_0_index, &normal_0_index, 
+                &vertex_1_index, &uv_1_index, &normal_1_index, 
+                &vertex_2_index, &uv_2_index, &normal_2_index);
+
+            if (matches != 9){
+                vertex_0_index = -1;
+                vertex_1_index = -1;
+                vertex_2_index = -1;
+                
+                normal_0_index = -1;
+                normal_1_index = -1;
+                normal_2_index = -1;
+                
+                uv_0_index = -1;
+                uv_1_index = -1;
+                uv_2_index = -1;
+
+                if (strchr(line, '/')){
+                    sscanf(line, "f %d//%d %d//%d %d//%d", 
+                        &vertex_0_index, &normal_0_index, 
+                        &vertex_1_index, &normal_1_index, 
+                        &vertex_2_index, &normal_2_index);
+                
+                    has_normals = 1;
                 }
                 else {
-                    has_normals = has_uvs = 1;
+                    sscanf(line, "f %d %d %d", 
+                        &vertex_0_index, 
+                        &vertex_1_index, 
+                        &vertex_2_index);
                 }
+            }
+            else {
+                has_normals = has_uvs = 1;
+            }
 
-                new_mesh_data_struct.faces[current_face_index].position_0_index = vertex_0_index - 1;
-                new_mesh_data_struct.faces[current_face_index].position_1_index = vertex_1_index - 1;
-                new_mesh_data_struct.faces[current_face_index].position_2_index = vertex_2_index - 1;
+            new_mesh->faces[current_face_index].position_0_index = vertex_0_index - 1;
+            new_mesh->faces[current_face_index].position_1_index = vertex_1_index - 1;
+            new_mesh->faces[current_face_index].position_2_index = vertex_2_index - 1;
 
-                new_mesh_data_struct.faces[current_face_index].normal_0_index = normal_0_index - 1;
-                new_mesh_data_struct.faces[current_face_index].normal_1_index = normal_1_index - 1;
-                new_mesh_data_struct.faces[current_face_index].normal_2_index = normal_2_index - 1;
-                
-                new_mesh_data_struct.faces[current_face_index].uv_0_index = uv_0_index - 1;
-                new_mesh_data_struct.faces[current_face_index].uv_1_index = uv_1_index - 1;
-                new_mesh_data_struct.faces[current_face_index].uv_2_index = uv_2_index - 1;
+            new_mesh->faces[current_face_index].normal_0_index = normal_0_index - 1;
+            new_mesh->faces[current_face_index].normal_1_index = normal_1_index - 1;
+            new_mesh->faces[current_face_index].normal_2_index = normal_2_index - 1;
+            
+            new_mesh->faces[current_face_index].uv_0_index = uv_0_index - 1;
+            new_mesh->faces[current_face_index].uv_1_index = uv_1_index - 1;
+            new_mesh->faces[current_face_index].uv_2_index = uv_2_index - 1;
 
-                new_mesh_data_struct.faces[current_face_index].should_render = 1;
+            new_mesh->faces[current_face_index].should_render = 1;
 
-                ++current_face_index;
-            }
-            else if (line[0] == 'v' && line[1] == ' ') {
-                double x, y, z;
-                
-                sscanf(line, "v %lf %lf %lf", &x, &y, &z);
+            ++current_face_index;
+        }
+        else if (line[0] == 'v' && line[1] == ' ') {
+            double x, y, z;
+            
+            sscanf(line, "v %lf %lf %lf", &x, &y, &z);
 
-                new_mesh_data_struct.vertex_positions[current_vertex_index].x = x;
-                new_mesh_data_struct.vertex_positions[current_vertex_index].y = y;
-                new_mesh_data_struct.vertex_positions[current_vertex_index].z = z;
+            new_mesh->vertex_positions[current_vertex_index].x = x;
+            new_mesh->vertex_positions[current_vertex_index].y = y;
+            new_mesh->vertex_positions[current_vertex_index].z = z;
 
-                ++current_vertex_index;
-            } 
-            else if (line[0] == 'v' && line[1] == 'n') {
-                double x, y, z;
-                
-                sscanf(line, "vn %lf %lf %lf", &x, &y, &z);
-
-                new_mesh_data_struct.normals[current_normal_index].x = x;
-                new_mesh_data_struct.normals[current_normal_index].y = y;
-                new_mesh_data_struct.normals[current_normal_index].z = z;
+            ++current_vertex_index;
+        } 
+        else if (line[0] == 'v' && line[1] == 'n') {
+            double x, y, z;
+            
+            sscanf(line, "vn %lf %lf %lf", &x, &y, &z);
 
-                ++current_normal_index;
-            }
-            else if (line[0] == 'v' && line[1] == 't') {
-                double x, y, z;
+            new_mesh->normals[current_normal_index].x = x;
+            new_mesh->normals[current_normal_index].y = y;
+            new_mesh->normals[current_normal_index].z = z;
 
-                sscanf(line, "vt %lf %lf %lf", &x, &y, &z);
+            ++current_normal_index;
+        }
+        else if (line[0] == 'v' && line[1] == 't') {
+            double x, y, z;
 
-                new_mesh_data_struct.uvs[current_uv_index].x = x;
-                new_mesh_data_struct.uvs[current_uv_index].y = y;
-                // UVS are almost always 2D so we don't need Z (the type itself is a vector 2f, not 3f) 
+            sscanf(line, "vt %lf %lf %lf", &x, &y, &z);
 
-                ++current_uv_index;
-            } 
-        }
+            new_mesh->uvs[current_uv_index].x = x;
+            new_mesh->uvs[current_uv_index].y = y;
+            // UVS are almost always 2D so we don't need Z (the type itself is a vector 2f, not 3f) 
 
-        char* loading_mesh_notice_string;
+            ++current_uv_index;
+        } 
+    }
 
-        if (has_normals && !has_uvs) loading_mesh_notice_string = "normals";
-        else if (!has_normals && has_uvs) loading_mesh_notice_string = "UVs";
-        else if (!has_normals && !has_uvs) loading_mesh_notice_string = "normals and UVs";
-        
-        if (!has_normals || !has_uvs) debug("[Mesh Loader] Notice! Mesh \"%s\" is missing %s", filenames[i], loading_mesh_notice_string);
-        
-        new_mesh_data_struct.has_normals = has_normals;
-        new_mesh_data_struct.has_uvs = has_uvs;
+    char* loading_mesh_notice_string;
 
-        // fclose(file_again);
+    if (has_normals && !has_uvs) loading_mesh_notice_string = "normals";
+    else if (!has_normals && has_uvs) loading_mesh_notice_string = "UVs";
+    else if (!has_normals && !has_uvs) loading_mesh_notice_string = "normals and UVs";
+    
+    if (!has_normals || !has_uvs) debug("[Mesh Loader] Notice! Mesh \"%s\" is missing %s", filename, loading_mesh_notice_string);
+    
+    new_mesh->has_normals = has_normals;
+    new_mesh->has_uvs = has_uvs;
 
-        if (!RI_return_just_mesh) {
-            ri.loaded_meshes[meshes_already_loaded_count + i] = new_mesh_data_struct;   
+    debug("[Mesh Loader] Loaded mesh \"%s\"! %d faces, %d verticies, %d normals, %d uvs", filename, current_face_index, current_vertex_index, current_normal_index, current_uv_index); 
 
-            debug("[Mesh Loader] Loaded mesh \"%s\"! %d faces, %d verticies, %d normals, %d uvs", filenames[i], current_face_index, current_vertex_index, current_normal_index, current_uv_index); 
-        }
-        else {
-            *mesh = new_mesh_data_struct;
-        }
-    }
+    fclose(file);
 
-    if (!RI_return_just_mesh) return ri.loaded_meshes;
-    else return mesh;
+    return new_mesh;
 }
 
 double mod(double a, double b){
@@ -1215,7 +1166,7 @@ void RI_tick(int clear_window_texture_after_rendering){
     }
 
     if (clear_window_texture_after_rendering){
-        RI_clear_texture(ri.frame_buffer);
+        RI_wipe_texture(ri.frame_buffer, 0xFF000000);
     }
 
     ++ri.frame;
@@ -1404,9 +1355,8 @@ int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title){
     ri.actor_count = 0;
 
     char **error_cube_file = RI_malloc(sizeof(char *));
-    error_cube_file[0] = "objects/unit_cube.obj";
-
-    RI_mesh* error_mesh = RI_request_meshes(1, error_cube_file, 1);
+    
+    RI_mesh* error_mesh = RI_request_mesh("objects/unit_cube.obj");
 
     ri.error_mesh = *error_mesh;