Browse Source

quick update

Iver 5 months ago
parent
commit
f84485bf18
5 changed files with 35 additions and 61 deletions
  1. BIN
      build/librasteriver.so
  2. BIN
      build/main.bin
  3. BIN
      compiled_libs/librasteriver.so
  4. 1 38
      src/launch_program/main.c
  5. 34 23
      src/library/rasteriver.c

BIN
build/librasteriver.so


BIN
build/main.bin


BIN
compiled_libs/librasteriver.so


+ 1 - 38
src/launch_program/main.c

@@ -103,45 +103,8 @@ int main(){
     while (running){
         RI_render(scene, ri->frame_buffer, 1);
         
-        // RI_render_text(font, ri->frame_buffer, (RI_vector_2f){50, 200}, 0xFFFFFFFF, 10, 300, "A");
+        RI_render_text(font, ri->frame_buffer, (RI_vector_2f){50, 200}, 0xFFFFFFFF, 10, 300, "A");
         
-        RI_vector_2f a = {300, 200};
-        RI_vector_2f b = {500, 200};
-        RI_vector_2f c = {400, 500};
-        
-        b.y = sin((double)ri->frame / 100.0) * 700;
-        b.x = cos((double)ri->frame / 100.0) * 700;
-        
-        RI_vector_2f prev = a;
-
-        for (int i = 0; i < ceil(sqrt(ri->frame / 10)); ++i){
-            RI_vector_2f temp; vector_2f_bezier_interpolate(a, b, c, &temp, (double)(i + 1) / (double)(ceil(sqrt(ri->frame / 10))));
-            
-            RI_draw_line(ri->frame_buffer, v2f_to_2(prev), v2f_to_2(temp), 0xFFFFFFFF);
-        
-            prev = temp;
-        }
-        printf("%d\n", ri->frame);
-
-        // 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});
-
-        // // scene->camera_position = (RI_vector_3f){cos(ri->frame * 0.07) * 10 * sin(ri->frame * 0.2), sin(ri->frame * 0.07) * 10 * sin(ri->frame * 0.2), -300};
-        // scene->camera_position = (RI_vector_3f){0, 0, -300};
-        
-        // wall->transform.scale.x = fabs(sin(y_rotation)) * 100 + 70;
-
-        // RI_euler_rotation_to_quaternion(&scene->camera_rotation, (RI_vector_3f){0, y_rotation * .01 + 1.5, 0});
-
-        // RI_euler_rotation_to_quaternion(&floor->transform.rotation, (RI_vector_3f){0, y_rotation, 0});
-        
-        // RI_euler_rotation_to_quaternion(&test_object->transform.rotation, (RI_vector_3f){y_rotation, y_rotation, y_rotation});
-        // RI_euler_rotation_to_quaternion(&test_object->transform.rotation, (RI_vector_3f){0, y_rotation, 0});
-
-        // y_rotation += 0.1;
-        
-
         RI_tick();
 
         ++ri->frame;

+ 34 - 23
src/library/rasteriver.c

@@ -192,6 +192,8 @@ void render_glyph(RI_texture *target_texture, RI_vector_2f position, float size,
     int allocated_new_points = glyph->number_of_points * 3;
     RI_vector_2f *new_points = RI_malloc(sizeof(RI_vector_2f) * allocated_new_points);
     
+    int *contour_ends = RI_malloc(sizeof(int) * glyph->number_of_contours);
+    
     for (int contour = 0; contour < glyph->number_of_contours; ++contour){
         // if we are at contour 0, point_start is 0.
         // if contour is > 0 but != 0, point_start is equal to the previous index
@@ -214,22 +216,21 @@ void render_glyph(RI_texture *target_texture, RI_vector_2f position, float size,
             int cur = (point + point_offset) % glyph->contour_end_indicies[contour];
             int next = (point + point_offset + 1) % glyph->contour_end_indicies[contour];
             
-            new_points[new_point_count].x = (float)glyph->x_coords[cur] / units_per_em * size;
-            new_points[new_point_count].y = (float)glyph->y_coords[cur] / units_per_em * size;
-
-            target_texture->image_buffer[(int)((new_points[new_point_count].y + position.y) * target_texture->resolution.x + (new_points[new_point_count].x + position.x))] = 0xFF00FF00;
+            new_points[new_point_count].x = (float)glyph->x_coords[cur] / units_per_em * size + position.x;
+            new_points[new_point_count].y = (float)glyph->y_coords[cur] / units_per_em * size + position.y;
 
             new_point_count++;
 
             // if current and next glyph are both on or off the curve, add a point between them-
             if ((glyph->flags[cur] & 1) == (glyph->flags[next] & 1)){
-                vector_2f_lerp((RI_vector_2f){(float)glyph->x_coords[cur] / units_per_em * size, (float)glyph->y_coords[cur] / units_per_em * size}, (RI_vector_2f){(float)glyph->x_coords[next] / units_per_em * size, (float)glyph->y_coords[next] / units_per_em * size}, &new_points[new_point_count], 0.5);
-
-                target_texture->image_buffer[(int)((new_points[new_point_count].y + position.y) * target_texture->resolution.x + (new_points[new_point_count].x + position.x))] = 0xFF00FF00;
+                vector_2f_lerp((RI_vector_2f){(float)glyph->x_coords[cur] / units_per_em * size + position.x, (float)glyph->y_coords[cur] / units_per_em * size + position.y}, (RI_vector_2f){(float)glyph->x_coords[next] / units_per_em * size + position.x, (float)glyph->y_coords[next] / units_per_em * size + position.y}, &new_points[new_point_count], 0.5);
 
                 new_point_count++;
             }
         }
+
+        contour_ends[contour] = new_point_count;
+        debug("%d", new_point_count);
     }
     
     allocated_new_points = new_point_count;
@@ -238,33 +239,43 @@ void render_glyph(RI_texture *target_texture, RI_vector_2f position, float size,
         for (int x = (int)((float)glyph->x_min / (float)units_per_em * size) + position.x; x < (int)((float)glyph->x_max / (float)units_per_em * size) + position.x; ++x){
             int intersections = 0;
             
-            for (int point = 0; point < new_point_count; point += 2){
-                RI_vector_2f point_a = new_points[point % new_point_count];
-                RI_vector_2f point_b = new_points[(point + 1) % new_point_count];
-                RI_vector_2f point_c = new_points[(point + 2) % new_point_count];
+            for (int contour = 0; contour < glyph->number_of_contours; ++contour){
+                int p_start = contour_ends[contour > 0 ? contour - 1 : 0];
+                int p_end = contour_ends[contour];
 
-                RI_vector_2f prev_point = new_points[point % new_point_count];
+                for (int point = 0; point < p_end - p_start; point += 2){
+                    RI_vector_2f point_a = new_points[p_start + point % (p_end - p_start)];
+                    RI_vector_2f point_b = new_points[p_start + (point + 1) % (p_end - p_start)];
+                    RI_vector_2f point_c = new_points[p_start + (point + 2) % (p_end - p_start)];
 
-                for (int i = 0; i < bezier_resolution; ++i){
-                    float w = (float)(i + 1) / (float)bezier_resolution;
-                    
-                    RI_vector_2f bez_point; vector_2f_bezier_interpolate(point_a, point_b, point_c, &bez_point, w);
+                    RI_vector_2f prev_point = new_points[p_start + point % p_end];
 
-                    if (bez_point.y >= 0 && bez_point.x >= 0)
-                    target_texture->image_buffer[(int)((bez_point.y + position.y) * target_texture->resolution.x + (bez_point.x + position.x))] = 0xFFFF5555;
+                    for (int i = 0; i < bezier_resolution; ++i){
+                        float w = (float)(i + 1) / (float)bezier_resolution;
 
+                        RI_draw_line(target_texture, v2f_to_2(point_a), v2f_to_2(point_c), 0xFF77FF77);
 
-                    if(intersects(prev_point, bez_point, (RI_vector_2f){x, y})) intersections++; 
-            
-                    prev_point = bez_point;
+                        RI_vector_2f bez_point; vector_2f_bezier_interpolate(point_a, point_b, point_c, &bez_point, w);
+
+                        if(intersects(prev_point, bez_point, (RI_vector_2f){x, y})) intersections++; 
+                
+                        RI_tick();
+
+                        int x;
+
+                        for (int _ = 0; _ < 10000000; _++)x = 10000*10000*_*_*_*_*_;
+                        
+                        prev_point = bez_point;
+                    }
                 }
             }
-
-            if (intersections % 2 != 0) target_texture->image_buffer[y * target_texture->resolution.x + x] = color;
+            
+            // if (intersections % 2 != 0) target_texture->image_buffer[y * target_texture->resolution.x + x] = color;
         }
     }
 
     RI_free(new_points);
+    RI_free(contour_ends);
 }
 
 void RI_render_text(SP_font *font, RI_texture *target_texture, RI_vector_2f position, uint32_t color, int bezier_resolution, float size, char *text){