Browse Source

made font point viewer example scene

Iver 5 months ago
parent
commit
e28cf8e751

+ 4 - 2
Makefile

@@ -1,9 +1,11 @@
 COMPILER=gcc
 FLAGS_ALL=-fsanitize=address -g -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-sequence-point
 FLAGS_EXAMPLE=-Lcompiled_libs/ -lrasteriver -lsourparse -Wl,-rpath=build/ -lm -lSDL2
-FLAGS_LIB=-D CL_TARGET_OPENCL_VERSION=120 -fPIC -shared -lc -lSDL2 -lm -lOpenCL
+FLAGS_LIB=-D CL_TARGET_OPENCL_VERSION=120 -fPIC -shared -lc -lSDL2 -lm # -lOpenCL
 
-main.bin: rasteriver.so
+main.bin: clean rasteriver.so
+	cp compiled_libs/librasteriver.so build/librasteriver.so
+	cp compiled_libs/libsourparse.so build/libsourparse.so
 	$(COMPILER) $(FLAGS_ALL) src/launch_program/main.c -o build/main.bin $(FLAGS_EXAMPLE) 
 
 rasteriver.so:

BIN
build/librasteriver.so


BIN
build/libsourparse.so


BIN
build/main.bin


+ 0 - 8
build/sourparse.h

@@ -1,8 +0,0 @@
-#ifndef SOURPARSE_H
-#define SOURPARSE_H
-
-#include "functions.h"
-#include "values.h"
-#include "custom_types.h"
-
-#endif

BIN
compiled_libs/librasteriver.so


BIN
compiled_libs/libsourparse.so


+ 13 - 2
src/headers/sourparse.h

@@ -4,8 +4,19 @@
 #include "stdint.h"
 
 typedef struct {
-    int *x_coords, *y_coords, *contour_end_indicies, number_of_points, number_of_contours;
+    int scale_x, scale01, scale10, scale_y;
+    int glyph_index;
+    int16_t arg1, arg2;
+    uint16_t flags;
+} SP_component;
+
+typedef struct {
+    int *x_coords, *y_coords, *contour_end_indicies; 
+    int number_of_points, number_of_contours, number_of_components;
     uint8_t *flags;
+    int16_t x_min, y_min, x_max, y_max;
+    SP_component *components;
+    int is_composite;
 } SP_glyph;
 
 typedef struct {
@@ -16,7 +27,7 @@ typedef struct {
     int16_t index_to_loca_format;
 } SP_font;
 
-SP_font SP_load_font(char *filename);
+SP_font* SP_load_font(char *filename);
 void SP_free_font(SP_font* font);
 
 #endif

+ 48 - 10
src/launch_program/main.c

@@ -1,15 +1,15 @@
 #include "../headers/rasteriver.h"
 
 int main(){
+    SP_font *font = SP_load_font("fonts/CalSans-Regular.ttf");
+    
     // get RasterIver context
     RasterIver *ri = RI_get_ri();
     ri->prefix = "--------------------------";
 
-    SP_font font = SP_load_font("fonts/CalSans-Regular.ttf");
-    
     ri->debug_memory = 0;
 
-    RI_init(1000, 1000, "This is RasterIver 2.0!!");
+    RI_init(700, 700, "This is RasterIver 2.0!!");
 
     int running = 1;
 
@@ -100,9 +100,20 @@ int main(){
     scene->antialiasing_subsample_resolution = 8;
     scene->flags = RI_SCENE_DONT_USE_AA;
 
-    int glyph = 536;
+    int glyph = 0;
+
 
+    
     while (running){
+               
+        if (ri->frame % 1 == 0){
+            glyph++;
+
+                test_object->transform.position = (RI_vector_3f){-10000, -1000,-100000};
+                RI_render(scene, ri->frame_buffer, 1);
+
+        }
+
         // test_object->transform.position = (RI_vector_3f){0, 0, 200};
 
         // RI_euler_rotation_to_quaternion(&screen->transform.rotation, (RI_vector_3f){-3.14159 / 2, 0, ri->frame * 0.03});
@@ -123,15 +134,42 @@ int main(){
         
         float scale = 0.3;
 
-        for (int i = 0; i < font.glyphs[glyph].number_of_contours; ++i){
-            for (int j = i > 0 ? font.glyphs[1].contour_end_indicies[i - 1] : 0; j < font.glyphs[glyph].contour_end_indicies[i]; ++j){
-                if (!(font.glyphs[glyph].flags[j] & 1)) test_object->material_reference->texture_reference = &ri->error_texture;
-                else test_object->material_reference->texture_reference = test_object_texture;
-                test_object->transform.position = (RI_vector_3f){font.glyphs[glyph].x_coords[j] * scale - 100, font.glyphs[glyph].y_coords[j] * scale - 100, 500};
+if (font->glyphs[glyph].number_of_contours > 0){
+    for (int i = 0; i < font->glyphs[glyph].number_of_contours; ++i){
+            for (int j = i > 0 ? font->glyphs[glyph].contour_end_indicies[i - 1] : 0; j < font->glyphs[glyph].contour_end_indicies[i]; ++j){
+                // if (!(font->glyphs[glyph].flags[j] & 1)) test_object->material_reference->texture_reference = &ri->error_texture;
+                // test_object->material_reference->texture_reference = test_object_texture;
+                test_object->transform.position = (RI_vector_3f){font->glyphs[glyph].x_coords[j] * scale - 100, font->glyphs[glyph].y_coords[j] * scale - 100, 500};
             
                 RI_render(scene, ri->frame_buffer, 0);
-                RI_tick();
             }
         }
+
+}
+else {
+    for (int k = 0; k < font->glyphs[glyph].number_of_components; k++){
+        int c_glyph = font->glyphs[glyph].components[k].glyph_index;
+
+        if (k == 1) c_glyph = 599;
+
+        int offset_x = (int)font->glyphs[glyph].components[k].arg1;
+        int offset_y = (int)font->glyphs[glyph].components[k].arg2;
+        
+        for (int i = 0; i < font->glyphs[c_glyph].number_of_contours; ++i){
+            for (int j = i > 0 ? font->glyphs[c_glyph].contour_end_indicies[i - 1] : 0; j < font->glyphs[c_glyph].contour_end_indicies[i]; ++j){
+                // if (!(font->glyphs[glyph].flags[j] & 1)) test_object->material_reference->texture_reference = &ri->error_texture;
+                // test_object->material_reference->texture_reference = test_object_texture;
+                test_object->transform.position = (RI_vector_3f){(font->glyphs[c_glyph].x_coords[j] + offset_x) * scale - 100, (font->glyphs[c_glyph].y_coords[j] + offset_y) * scale - 100, 500};
+            
+                RI_render(scene, ri->frame_buffer, 0);
+            }
+        }
+    }
+}
+RI_tick();
+    ++ri->frame;
+
     }
+
+    SP_free_font(font);
 }

+ 68 - 59
src/library/rasteriver.c

@@ -1,11 +1,12 @@
 #include <stdio.h>
-#include <CL/cl.h>
+// #include <CL/cl.h>
 #include <SDL2/SDL.h>
 #include "../headers/rasteriver.h"
 #define STB_IMAGE_IMPLEMENTATION
 #include "../headers/stb_image.h"
 #include "stdint.h"
 #include <math.h>
+#include <signal.h>
 
 RasterIver ri = {NULL};
 
@@ -1005,7 +1006,7 @@ void RI_tick(){
         }
     }
 
-    ++ri.frame;
+    // ++ri.frame;
 }
 
 int opencl_init(){
@@ -1036,62 +1037,6 @@ int sdl_init(int RI_window_width, int RI_window_height, char *RI_window_title){
     return 0;
 }
 
-int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title){
-    ri.running = 1;
-
-    ri.prefix = "[RasterIver] ";
-
-    if (ri.debug_memory){
-        ri.current_allocation_index = 0;
-        ri.allocation_search_limit = 100;
-        ri.allocation_table_length = 100;
-        
-        size_t __size = sizeof(RI_memory_allocation) * ri.allocation_table_length;
-
-        ri.allocation_table = malloc(__size);
-    
-        debug("[Memory Manager] Allocated (malloc) %zu bytes", __size);
-
-        ri.allocation_table[ri.current_allocation_index].allocated = 1;
-        ri.allocation_table[ri.current_allocation_index].freed = 0;
-        ri.allocation_table[ri.current_allocation_index].reallocated_alloc = 0;
-        ri.allocation_table[ri.current_allocation_index].reallocated_free = 0;
-        ri.allocation_table[ri.current_allocation_index].pointer = ri.allocation_table;        
-        ri.allocation_table[ri.current_allocation_index].size = __size;
-
-        ri.current_allocation_index++;
-    }
-
-    opencl_init();
-
-    sdl_init(RI_window_width, RI_window_height, RI_window_title);
-
-    ri.loaded_mesh_count = 0;
-    ri.loaded_texture_count = 0;
-    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.error_mesh = *error_mesh;
-
-    RI_free(error_mesh);
-    RI_free(error_cube_file);
-
-    ri.error_texture.image_buffer = RI_malloc(sizeof(uint32_t));
-
-    ri.error_texture.image_buffer[0] = 0xFFFF00FF;
-    ri.error_texture.resolution = (RI_vector_2){1, 1};
-
-    ri.error_material.texture_reference = &ri.error_texture;
-    ri.error_material.albedo = 0xFF5522CC;
-    ri.error_material.flags = RI_MATERIAL_UNLIT | RI_MATERIAL_DONT_DEPTH_TEST | RI_MATERIAL_DONT_RECEIVE_SHADOW | RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_DOUBLE_SIDED;
-
-    return 0;
-}
-
 int RI_stop(int result){
     debug("[Notice] Stopping...");
     
@@ -1167,4 +1112,68 @@ int RI_stop(int result){
     exit(result);
 
     return 0;
-}
+}
+
+void signal_interupt_handler(int signal) {
+    debug("Recieved SIGINT");
+        
+    RI_stop(1);
+}
+
+int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title){
+    signal(SIGINT, signal_interupt_handler);
+    
+    ri.running = 1;
+
+    ri.prefix = "[RasterIver] ";
+
+    if (ri.debug_memory){
+        ri.current_allocation_index = 0;
+        ri.allocation_search_limit = 100;
+        ri.allocation_table_length = 100;
+        
+        size_t __size = sizeof(RI_memory_allocation) * ri.allocation_table_length;
+
+        ri.allocation_table = malloc(__size);
+    
+        debug("[Memory Manager] Allocated (malloc) %zu bytes", __size);
+
+        ri.allocation_table[ri.current_allocation_index].allocated = 1;
+        ri.allocation_table[ri.current_allocation_index].freed = 0;
+        ri.allocation_table[ri.current_allocation_index].reallocated_alloc = 0;
+        ri.allocation_table[ri.current_allocation_index].reallocated_free = 0;
+        ri.allocation_table[ri.current_allocation_index].pointer = ri.allocation_table;        
+        ri.allocation_table[ri.current_allocation_index].size = __size;
+
+        ri.current_allocation_index++;
+    }
+
+    opencl_init();
+
+    sdl_init(RI_window_width, RI_window_height, RI_window_title);
+
+    ri.loaded_mesh_count = 0;
+    ri.loaded_texture_count = 0;
+    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.error_mesh = *error_mesh;
+
+    RI_free(error_mesh);
+    RI_free(error_cube_file);
+
+    ri.error_texture.image_buffer = RI_malloc(sizeof(uint32_t));
+
+    ri.error_texture.image_buffer[0] = 0xFFFF00FF;
+    ri.error_texture.resolution = (RI_vector_2){1, 1};
+
+    ri.error_material.texture_reference = &ri.error_texture;
+    ri.error_material.albedo = 0xFF5522CC;
+    ri.error_material.flags = RI_MATERIAL_UNLIT | RI_MATERIAL_DONT_DEPTH_TEST | RI_MATERIAL_DONT_RECEIVE_SHADOW | RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_DOUBLE_SIDED;
+
+    return 0;
+}