// Black background
for y: 0 .. height do for x: 0 .. width do data[x + y * width] = cast(u8) 0;
- scale := cast(f32) height / ~~cast(i32) units_per_em;
+ // scale := ~~cast(i32) units_per_em / cast(f32) height;
state := 0;
count := 0;
}
case 1 do if p.on_curve {
- // draw_line(data, width, height, scale,
- // curr_x, curr_y,
- // ~~p.x, ~~p.y);
-
curr_x = cast(i32) p.x;
curr_y = cast(i32) p.y;
count += 1;
state = 0;
- // for p: poly_points {
- // print_vec(p);
+ for p: poly_points {
+ print_vec(p);
- // tx := cast(i32) (~~p.x * scale);
- // ty := cast(i32) (~~p.y * scale);
+ tx := cast(i32) (~~p.x * height / ~~units_per_em);
+ ty := cast(i32) (~~p.y * height / ~~units_per_em);
- // if tx >= 0 && ty >= 0 && tx < width && ty < height {
- // data[tx + (height - 1 - ty) * width] = cast(u8) 255;
- // }
- // }
-
- for y: 0 .. height do for x: 0 .. width {
- if is_inside_polygon(array_to_slice(^poly_points), V2i.{ ~~(~~x / scale), ~~(~~y / scale) }) {
- curr := data[x + (height - 1 - y) * width];
- if curr == ~~0 do data[x + (height - 1 - y) * width] = cast(u8) 255;
- else do data[x + (height - 1 - y) * width] = cast(u8) 0;
+ if tx >= 0 && ty >= 0 && tx < width && ty < height {
+ data[tx + (height - 1 - ty) * width] += cast(u8) 100;
}
}
+ // for y: 0 .. height do for x: 0 .. width {
+ // sx := x * ~~units_per_em / width;
+ // sy := y * ~~units_per_em / height;
+
+ // if is_inside_polygon(array_to_slice(^poly_points), V2i.{ sx, sy }) {
+ // curr := data[x + (height - 1 - y) * width];
+ // if curr == ~~0 do data[x + (height - 1 - y) * width] = cast(u8) 255;
+ // else do data[x + (height - 1 - y) * width] = cast(u8) 0;
+ // }
+ // }
+
array_clear(^poly_points);
}
}
+
+ println(cast(i32) glyph.contour_count);
}
#private_file
use package gl as gl
use package gl_utils as gl_utils
-Color3 :: struct { r: u8; g: u8; b: u8; }
-
-#private_file current_tex_id := 0;
-
Texture :: struct {
// NOTE: After a texture is loaded, we may not want to keep the
// raw texture data in memory any longer. This would not be possible
if data_mode == TextureDataMode.BRIGHTNESS do format = gl.LUMINANCE;
texture_id = gl.createTexture();
- // gl.activeTexture(gl.TEXTURE0);
+ gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture_id);
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.UNSIGNED_BYTE, data);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
- // gl.bindTexture(gl.TEXTURE_2D, -1);
+ gl.bindTexture(gl.TEXTURE_2D, -1);
}
texture_use :: proc (use tex: ^Texture) {
if input.key_down(^input_state, Key.ArrowRight) do player.x += player_speed;
}
-glyph_size :: 128
+glyph_size :: 64
glyph_data : [glyph_size * glyph_size] u8
draw :: proc () {
// renderer.color = Color4f32.{ 1f, 0f, 0f, 1f };
- points : [6] V2f;
- points[0] = V2f.{ 500.0f, 700.0f };
- points[1] = V2f.{ 600.0f, 200.0f };
- points[2] = V2f.{ 700.0f, 400.0f };
- points[3] = V2f.{ 1700.0f, 800.0f };
- points[4] = V2f.{ 1800.0f, 400.0f };
- points[5] = V2f.{ 1000.0f, 200.0f };
+ // points : [6] V2f;
+ // points[0] = V2f.{ 500.0f, 700.0f };
+ // points[1] = V2f.{ 600.0f, 200.0f };
+ // points[2] = V2f.{ 700.0f, 400.0f };
+ // points[3] = V2f.{ 1700.0f, 800.0f };
+ // points[4] = V2f.{ 1800.0f, 400.0f };
+ // points[5] = V2f.{ 1000.0f, 200.0f };
- for i: 0 .. 200 {
- pos := bezier_curve(~~i / 200.0f, points[0 .. 6]);
- draw_rect(^renderer, pos.x, pos.y, 16f, 16f);
- }
+ // for i: 0 .. 200 {
+ // pos := bezier_curve(~~i / 200.0f, points[0 .. 6]);
+ // draw_rect(^renderer, pos.x, pos.y, 16f, 16f);
+ // }
// for y: 0 .. glyph_size do for x: 0 .. glyph_size {
// if glyph_data[x + y * glyph_size] != ~~0 {
// draw_rect(^renderer, ~~ cast(i32) p.x * rx + 100f, ~~ cast(i32) p.y * ry + 100f, 10f, 10f);
// }
+ texture_use(^font_tex);
+ draw_rect(^renderer, 100f, 100f, 256f, 256f);
+ render_context_flush(^renderer);
texture_use(^smile);
- draw_rect(^renderer, ~~input_state.mouse.x, ~~input_state.mouse.y, 100f, 100f);
+ draw_rect(^renderer, ~~input_state.mouse.x, ~~input_state.mouse.y, 10f, 10f);
draw_rect(^renderer, player.pos.x, player.pos.y, 100f, 100f);
render_context_flush(^renderer);
-
- texture_use(^font_tex);
- draw_rect(^renderer, 100f, 100f, 512f, 512f);
- render_context_flush(^renderer);
}
// This procedure is called asynchronously from JS every frame.
ttf = ttf_create(ttf_data);
glyph : ^TTGlyph = null;
- glyph_index := ttf_lookup_glyph_by_char(^ttf, ~~ #char "S");
+ glyph_index := ttf_lookup_glyph_by_char(^ttf, ~~ #char "~");
glyph = ttf_read_glyph(^ttf, glyph_index);
if glyph == null do return;
defer ttf_glyph_destroy(glyph);
if polygon.count < 3 do return false;
extreme : V2(T);
- extreme.x = cast(T) 10000; // Needs be infinity... close enough
+ extreme.x = p.x + ~~1000000; // Needs be infinity... close enough
extreme.y = p.y;
count := 0;
for i: 0 .. polygon.count {
next := (i + 1) % polygon.count;
- // if v2_square_dist(polygon[i], polygon[next]) < ~~1000 do continue;
+ // if v2_square_dist(polygon[i], polygon[next]) < ~~(20 * 20) do continue;
+ if v2_equal(polygon[i], polygon[next]) do continue;
if lines_intersect(polygon[i], polygon[next], p, extreme) {
if v2_orientation(polygon[i], p, polygon[next]) == 0 {
CURRENT_QUERY /usr/share/onyx/core/js/webgl.onyx /^CURRENT_QUERY :: 0x8865$/
CURRENT_VERTEX_ATTRIB /usr/share/onyx/core/js/webgl.onyx /^CURRENT_VERTEX_ATTRIB :: 0x8626$/
CW /usr/share/onyx/core/js/webgl.onyx /^CW :: 0x0900$/
-Color3 src/gfx/texture.onyx /^Color3 :: struct { r: u8; g: u8; b: u8; }$/
Color4f32 src/gfx/quad_renderer.onyx /^Color4f32 :: struct { r: f32; g: f32; b: f32; a: f32; }$/
DECR /usr/share/onyx/core/js/webgl.onyx /^DECR :: 0x1E03$/
DECR_WRAP /usr/share/onyx/core/js/webgl.onyx /^DECR_WRAP :: 0x8508$/
getUniformLocation /usr/share/onyx/core/js/webgl.onyx /^getUniformLocation :: proc (program: GLProgram, name: string) -> GLUniformLocation #foreign "gl" "getUniformLocation" ---$/
getVertexAttribOffset /usr/share/onyx/core/js/webgl.onyx /^getVertexAttribOffset :: proc (index: GLuint, pname: GLenum) #foreign "gl" "getVertexAttribOffset" ---$/
glyph_data src/main.onyx /^glyph_data : [glyph_size * glyph_size] u8$/
-glyph_size src/main.onyx /^glyph_size :: 128$/
+glyph_size src/main.onyx /^glyph_size :: 64$/
heap_alloc /usr/share/onyx/core/alloc.onyx /^heap_alloc :: proc (size_: u32, align: u32) -> rawptr {$/
heap_alloc_proc /usr/share/onyx/core/alloc.onyx /^heap_alloc_proc :: proc (data: rawptr, aa: AllocAction, size: u32, align: u32, oldptr: rawptr) -> rawptr {$/
heap_allocator /usr/share/onyx/core/alloc.onyx /^heap_allocator : Allocator;$/