Makes sketches compile and run with changes introduced by renaming pass.

This is a combination of 19 commits:

- fix atlas
- fix canvas
- fix image
- add OpenSansLatinSubset to resources
- fix multi_surface
- fix perf_text
- fix polygon
- fix render_thread
- fix simpleWindow
- fix smooth_resize
- fix surface_sharing
- fixed tiger
- fix triangleGL
- fix triangleGLES (note rendering doesn't work)
- fix ui
- fix all on osx
- Fix sketch triangleGLES
- Make transparent rectangle clearer in sketches polygon
- Add proper error message in sketch/triangleGL on macOS
This commit is contained in:
Reuben Dunnington 2023-08-24 15:30:20 -07:00 committed by Martin Fouilleul
parent ceb4a3a95d
commit 416044ea76
48 changed files with 5008 additions and 4890 deletions

2
.gitignore vendored
View File

@ -36,3 +36,5 @@ __pycache__
scripts/files scripts/files
ext/angle ext/angle
sketches/*/bin

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_atlas.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_atlas.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_atlas main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_atlas main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_atlas install_name_tool -add_rpath "@executable_path" $BINDIR/example_atlas

View File

@ -13,63 +13,62 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
log_error("couldn't create surface\n"); oc_log_error("couldn't create surface\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
//NOTE: create canvas //NOTE: create canvas
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
log_error("Error: couldn't create canvas\n"); oc_log_error("Error: couldn't create canvas\n");
return (-1); return (-1);
} }
//NOTE: create atlas //NOTE: create atlas
mem_arena permanentArena = { 0 }; oc_arena permanentArena = { 0 };
mem_arena_init(&permanentArena); oc_arena_init(&permanentArena);
mg_rect_atlas* atlas = mg_rect_atlas_create(&permanentArena, 16000, 16000); oc_rect_atlas* atlas = oc_rect_atlas_create(&permanentArena, 16000, 16000);
mg_image atlasImage = mg_image_create(surface, 16000, 16000); oc_image atlasImage = oc_image_create(surface, 16000, 16000);
str8 path1 = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/triceratops.png")); oc_str8 path1 = oc_path_executable_relative(oc_scratch(), OC_STR8("../../../sketches/resources/triceratops.png"));
str8 path2 = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/Top512.png")); oc_str8 path2 = oc_path_executable_relative(oc_scratch(), OC_STR8("../../../sketches/resources/Top512.png"));
mg_image_region image1 = mg_image_atlas_alloc_from_file(atlas, atlasImage, path1, false); oc_image_region image1 = oc_image_atlas_alloc_from_file(atlas, atlasImage, path1, false);
mg_image_region image2 = mg_image_atlas_alloc_from_file(atlas, atlasImage, path2, false); oc_image_region image2 = oc_image_atlas_alloc_from_file(atlas, atlasImage, path2, false);
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -78,30 +77,30 @@ int main()
} }
} }
mg_surface_prepare(surface); oc_surface_select(surface);
mg_set_color_rgba(0, 1, 1, 1); oc_set_color_rgba(0, 1, 1, 1);
mg_clear(); oc_clear();
mg_set_color_rgba(1, 1, 1, 1); oc_set_color_rgba(1, 1, 1, 1);
mg_image_draw_region(image1.image, image1.rect, (mp_rect){ 100, 100, 300, 300 }); oc_image_draw_region(image1.image, image1.rect, (oc_rect){ 100, 100, 300, 300 });
mg_image_draw_region(image2.image, image2.rect, (mp_rect){ 300, 200, 300, 300 }); oc_image_draw_region(image2.image, image2.rect, (oc_rect){ 300, 200, 300, 300 });
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
mg_image_atlas_recycle(atlas, image1); oc_image_atlas_recycle(atlas, image1);
mg_image_atlas_recycle(atlas, image2); oc_image_atlas_recycle(atlas, image2);
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,5 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_canvas.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_canvas.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../build/bin BINDIR=bin
LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_canvas main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_canvas main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_canvas install_name_tool -add_rpath "@executable_path" $BINDIR/example_canvas

View File

@ -14,21 +14,19 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
#define LOG_SUBSYSTEM "Main" oc_font create_font()
mg_font create_font()
{ {
//NOTE(martin): create font //NOTE(martin): create font
str8 fontPath = path_executable_relative(mem_scratch(), STR8("../resources/OpenSansLatinSubset.ttf")); oc_str8 fontPath = oc_path_executable_relative(oc_scratch(), OC_STR8("../../resources/OpenSansLatinSubset.ttf"));
char* fontPathCString = str8_to_cstring(mem_scratch(), fontPath); char* fontPathCString = oc_str8_to_cstring(oc_scratch(), fontPath);
FILE* fontFile = fopen(fontPathCString, "r"); FILE* fontFile = fopen(fontPathCString, "r");
if(!fontFile) if(!fontFile)
{ {
log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno)); oc_log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno));
return (mg_font_nil()); return (oc_font_nil());
} }
unsigned char* fontData = 0; unsigned char* fontData = 0;
fseek(fontFile, 0, SEEK_END); fseek(fontFile, 0, SEEK_END);
@ -38,13 +36,13 @@ mg_font create_font()
fread(fontData, 1, fontDataSize, fontFile); fread(fontData, 1, fontDataSize, fontFile);
fclose(fontFile); fclose(fontFile);
unicode_range ranges[5] = { UNICODE_RANGE_BASIC_LATIN, oc_unicode_range ranges[5] = { OC_UNICODE_BASIC_LATIN,
UNICODE_RANGE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT, OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
UNICODE_RANGE_LATIN_EXTENDED_A, OC_UNICODE_LATIN_EXTENDED_A,
UNICODE_RANGE_LATIN_EXTENDED_B, OC_UNICODE_LATIN_EXTENDED_B,
UNICODE_RANGE_SPECIALS }; OC_UNICODE_SPECIALS };
mg_font font = mg_font_create_from_memory(fontDataSize, fontData, 5, ranges); oc_font font = oc_font_create_from_memory(oc_str8_from_buffer(fontDataSize, (char*)fontData), 5, ranges);
free(fontData); free(fontData);
return (font); return (font);
@ -52,77 +50,76 @@ mg_font create_font()
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
printf("Error: couldn't create surface\n"); oc_log_error("Error: couldn't create surface\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
printf("Error: couldn't create canvas\n"); printf("Error: couldn't create canvas\n");
return (-1); return (-1);
} }
mg_font font = create_font(); oc_font font = create_font();
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
f32 x = 400, y = 300; f32 x = 400, y = 300;
f32 speed = 0; f32 speed = 0;
f32 dx = speed, dy = speed; f32 dx = speed, dy = speed;
f64 frameTime = 0; f64 frameTime = 0;
while(!mp_should_quit()) while(!oc_should_quit())
{ {
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
if(event->key.action == MP_KEY_PRESS || event->key.action == MP_KEY_REPEAT) if(event->key.action == OC_KEY_PRESS || event->key.action == OC_KEY_REPEAT)
{ {
f32 factor = (event->key.mods & MP_KEYMOD_SHIFT) ? 10 : 1; f32 factor = (event->key.mods & OC_KEYMOD_SHIFT) ? 10 : 1;
if(event->key.code == MP_KEY_LEFT) if(event->key.code == OC_KEY_LEFT)
{ {
x -= 0.3 * factor; x -= 0.3 * factor;
} }
else if(event->key.code == MP_KEY_RIGHT) else if(event->key.code == OC_KEY_RIGHT)
{ {
x += 0.3 * factor; x += 0.3 * factor;
} }
else if(event->key.code == MP_KEY_UP) else if(event->key.code == OC_KEY_UP)
{ {
y -= 0.3 * factor; y -= 0.3 * factor;
} }
else if(event->key.code == MP_KEY_DOWN) else if(event->key.code == OC_KEY_DOWN)
{ {
y += 0.3 * factor; y += 0.3 * factor;
} }
@ -159,61 +156,61 @@ int main()
y += dy; y += dy;
// background // background
mg_set_color_rgba(0, 1, 1, 1); oc_set_color_rgba(0, 1, 1, 1);
mg_clear(); oc_clear();
mg_set_color_rgba(1, 0, 1, 1); oc_set_color_rgba(1, 0, 1, 1);
mg_rectangle_fill(0, 0, 100, 100); oc_rectangle_fill(0, 0, 100, 100);
// head // head
mg_set_color_rgba(1, 1, 0, 1); oc_set_color_rgba(1, 1, 0, 1);
mg_circle_fill(x, y, 200); oc_circle_fill(x, y, 200);
// smile // smile
f32 frown = frameTime > 0.033 ? -100 : 0; f32 frown = frameTime > 0.033 ? -100 : 0;
mg_set_color_rgba(0, 0, 0, 1); oc_set_color_rgba(0, 0, 0, 1);
mg_set_width(20); oc_set_width(20);
mg_move_to(x - 100, y + 100); oc_move_to(x - 100, y + 100);
mg_cubic_to(x - 50, y + 150 + frown, x + 50, y + 150 + frown, x + 100, y + 100); oc_cubic_to(x - 50, y + 150 + frown, x + 50, y + 150 + frown, x + 100, y + 100);
mg_stroke(); oc_stroke();
// eyes // eyes
mg_ellipse_fill(x - 70, y - 50, 30, 50); oc_ellipse_fill(x - 70, y - 50, 30, 50);
mg_ellipse_fill(x + 70, y - 50, 30, 50); oc_ellipse_fill(x + 70, y - 50, 30, 50);
// text // text
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_set_font(font); oc_set_font(font);
mg_set_font_size(12); oc_set_font_size(12);
mg_move_to(50, 600 - 50); oc_move_to(50, 600 - 50);
str8 text = str8_pushf(mem_scratch(), oc_str8 text = oc_str8_pushf(oc_scratch(),
"Milepost vector graphics test program (frame time = %fs, fps = %f)...", "Orca vector graphics test program (frame time = %fs, fps = %f)...",
frameTime, frameTime,
1. / frameTime); 1. / frameTime);
mg_text_outlines(text); oc_text_outlines(text);
mg_fill(); oc_fill();
printf("Milepost vector graphics test program (frame time = %fs, fps = %f)...\n", oc_log_info("Orca vector graphics test program (frame time = %fs, fps = %f)...\n",
frameTime, frameTime,
1. / frameTime); 1. / frameTime);
mg_surface_prepare(surface); oc_surface_select(surface);
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
frameTime = mp_get_time(MP_CLOCK_MONOTONIC) - startTime; frameTime = oc_clock_time(OC_CLOCK_MONOTONIC) - startTime;
} }
mg_font_destroy(font); oc_font_destroy(font);
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_image.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_image.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_image main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_image main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_image install_name_tool -add_rpath "@executable_path" $BINDIR/example_image

View File

@ -14,59 +14,58 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
log_error("couldn't create surface\n"); oc_log_error("couldn't create surface\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
//NOTE: create canvas //NOTE: create canvas
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
printf("Error: couldn't create canvas\n"); oc_log_error("Error: couldn't create canvas\n");
return (-1); return (-1);
} }
//NOTE: create image //NOTE: create image
str8 imagePath = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/triceratops.png")); oc_str8 imagePath = oc_path_executable_relative(oc_scratch(), OC_STR8("../../resources/triceratops.png"));
mg_image image = mg_image_create_from_file(surface, imagePath, false); oc_image image = oc_image_create_from_file(surface, imagePath, false);
vec2 imageSize = mg_image_size(image); oc_vec2 imageSize = oc_image_size(image);
str8 imagePath2 = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/Top512.png")); oc_str8 imagePath2 = oc_path_executable_relative(oc_scratch(), OC_STR8("../../resources/Top512.png"));
mg_image image2 = mg_image_create_from_file(surface, imagePath2, false); oc_image image2 = oc_image_create_from_file(surface, imagePath2, false);
vec2 imageSize2 = mg_image_size(image2); oc_vec2 imageSize2 = oc_image_size(image2);
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -75,46 +74,46 @@ int main()
} }
} }
mg_surface_prepare(surface); oc_surface_select(surface);
mg_set_color_rgba(0, 1, 1, 1); oc_set_color_rgba(0, 1, 1, 1);
mg_clear(); oc_clear();
mg_set_color_rgba(1, 1, 1, 1); oc_set_color_rgba(1, 1, 1, 1);
/* /*
mg_matrix_push((mg_mat2x3){0.707, -0.707, 200, oc_matrix_push((oc_mat2x3){0.707, -0.707, 200,
0.707, 0.707, 100}); 0.707, 0.707, 100});
mg_set_image(image); oc_set_image(image);
mg_set_image_source_region((mp_rect){500, 500, 2000, 1400}); oc_set_image_source_region((oc_rect){500, 500, 2000, 1400});
mg_move_to(0, 0); oc_move_to(0, 0);
mg_line_to(200, 0); oc_line_to(200, 0);
mg_line_to(300, 100); oc_line_to(300, 100);
mg_line_to(200, 200); oc_line_to(200, 200);
mg_line_to(0, 200); oc_line_to(0, 200);
mg_line_to(100, 100); oc_line_to(100, 100);
mg_close_path(); oc_close_path();
mg_fill(); oc_fill();
mg_matrix_pop(); oc_matrix_pop();
mg_image_draw(image2, (mp_rect){300, 200, 300, 300}); oc_image_draw(image2, (oc_rect){300, 200, 300, 300});
*/ */
mg_image_draw(image, (mp_rect){ 100, 100, 300, 300 }); oc_image_draw(image, (oc_rect){ 100, 100, 300, 300 });
mg_image_draw(image2, (mp_rect){ 300, 200, 300, 300 }); oc_image_draw(image2, (oc_rect){ 300, 200, 300, 300 });
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
mg_image_destroy(image); oc_image_destroy(image);
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /MANIFEST:EMBED /MANIFESTINPUT:../../src/win32_manifest.xml /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_multi_surface.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_multi_surface.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,14 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_multi_surface main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_multi_surface main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_multi_surface install_name_tool -add_rpath "@executable_path" $BINDIR/example_multi_surface

View File

@ -2,68 +2,66 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define MG_INCLUDE_GL_API 1 #include "orca.h"
#include "milepost.h"
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface1 = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface1 = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface1)) if(oc_surface_is_nil(surface1))
{ {
printf("Error: couldn't create surface 1\n"); printf("Error: couldn't create surface 1\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface1, 0); oc_surface_swap_interval(surface1, 0);
//* //*
mg_surface surface2 = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface2 = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface2)) if(oc_surface_is_nil(surface2))
{ {
printf("Error: couldn't create surface 2\n"); printf("Error: couldn't create surface 2\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface2, 0); oc_surface_swap_interval(surface2, 0);
//*/ //*/
mg_canvas canvas1 = mg_canvas_create(); oc_canvas canvas1 = oc_canvas_create();
if(mg_canvas_is_nil(canvas1)) if(oc_canvas_is_nil(canvas1))
{ {
printf("Error: couldn't create canvas 1\n"); printf("Error: couldn't create canvas 1\n");
return (-1); return (-1);
} }
//* //*
mg_canvas canvas2 = mg_canvas_create(); oc_canvas canvas2 = oc_canvas_create();
if(mg_canvas_is_nil(canvas2)) if(oc_canvas_is_nil(canvas2))
{ {
printf("Error: couldn't create canvas 2\n"); printf("Error: couldn't create canvas 2\n");
return (-1); return (-1);
} }
//*/ //*/
// start app // start app
mp_window_center(window); oc_window_center(window);
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -72,44 +70,44 @@ int main()
} }
} }
mg_surface_prepare(surface1); oc_surface_select(surface1);
mg_canvas_set_current(canvas1); oc_canvas_set_current(canvas1);
mg_set_color_rgba(0, 0, 0.5, 0.5); oc_set_color_rgba(0, 0, 0.5, 0.5);
mg_clear(); oc_clear();
mg_set_color_rgba(1, 0, 0, 1); oc_set_color_rgba(1, 0, 0, 1);
mg_rectangle_fill(100, 100, 300, 150); oc_rectangle_fill(100, 100, 300, 150);
mg_render(surface1, canvas1); oc_render(surface1, canvas1);
//* //*
mg_surface_prepare(surface2); oc_surface_select(surface2);
mg_canvas_set_current(canvas2); oc_canvas_set_current(canvas2);
mg_set_color_rgba(0, 0, 0, 0); oc_set_color_rgba(0, 0, 0, 0);
mg_clear(); oc_clear();
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_rectangle_fill(300, 300, 300, 200); oc_rectangle_fill(300, 300, 300, 200);
mg_render(surface2, canvas2); oc_render(surface2, canvas2);
//*/ //*/
mg_surface_present(surface1); oc_surface_present(surface1);
mg_surface_present(surface2); oc_surface_present(surface2);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
mg_canvas_destroy(canvas1); oc_canvas_destroy(canvas1);
mg_surface_destroy(surface1); oc_surface_destroy(surface1);
mg_canvas_destroy(canvas2); oc_canvas_destroy(canvas2);
mg_surface_destroy(surface2); oc_surface_destroy(surface2);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/perf_text.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_perf_text.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../build/bin BINDIR=bin
LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-O2 -mmacos-version-min=10.15.4" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/perf_text main.c mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_perf_text main.c
install_name_tool -add_rpath "@executable_path" $BINDIR/perf_text cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_perf_text

View File

@ -2,12 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define LOG_DEFAULT_LEVEL LOG_LEVEL_MESSAGE #include "orca.h"
#define LOG_COMPILE_DEBUG
#include "milepost.h"
#define LOG_SUBSYSTEM "Main"
static const char* TEST_STRING = static const char* TEST_STRING =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quam enim, aliquam in placerat luctus, rutrum in quam. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quam enim, aliquam in placerat luctus, rutrum in quam. "
@ -59,17 +54,17 @@ static const char* TEST_STRING =
"faucibus eros, vel luctus justo leo vitae ante. Curabitur aliquam condimentum ipsum sit amet ultrices. Nullam ac velit semper, dapibus urna " "faucibus eros, vel luctus justo leo vitae ante. Curabitur aliquam condimentum ipsum sit amet ultrices. Nullam ac velit semper, dapibus urna "
"sit amet, malesuada enim. Mauris ultricies nibh orci."; "sit amet, malesuada enim. Mauris ultricies nibh orci.";
mg_font create_font(const char* path) oc_font create_font(const char* path)
{ {
//NOTE(martin): create font //NOTE(martin): create font
str8 fontPath = path_executable_relative(mem_scratch(), STR8(path)); oc_str8 fontPath = oc_path_executable_relative(oc_scratch(), OC_STR8(path));
char* fontPathCString = str8_to_cstring(mem_scratch(), fontPath); char* fontPathCString = oc_str8_to_cstring(oc_scratch(), fontPath);
FILE* fontFile = fopen(fontPathCString, "r"); FILE* fontFile = fopen(fontPathCString, "r");
if(!fontFile) if(!fontFile)
{ {
log_error("Could not load font file '%s'\n", fontPathCString); oc_log_error("Could not load font file '%s'\n", fontPathCString);
return (mg_font_nil()); return (oc_font_nil());
} }
unsigned char* fontData = 0; unsigned char* fontData = 0;
fseek(fontFile, 0, SEEK_END); fseek(fontFile, 0, SEEK_END);
@ -79,13 +74,13 @@ mg_font create_font(const char* path)
fread(fontData, 1, fontDataSize, fontFile); fread(fontData, 1, fontDataSize, fontFile);
fclose(fontFile); fclose(fontFile);
unicode_range ranges[5] = { UNICODE_RANGE_BASIC_LATIN, oc_unicode_range ranges[5] = { OC_UNICODE_BASIC_LATIN,
UNICODE_RANGE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT, OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
UNICODE_RANGE_LATIN_EXTENDED_A, OC_UNICODE_LATIN_EXTENDED_A,
UNICODE_RANGE_LATIN_EXTENDED_B, OC_UNICODE_LATIN_EXTENDED_B,
UNICODE_RANGE_SPECIALS }; OC_UNICODE_SPECIALS };
mg_font font = mg_font_create_from_memory(fontDataSize, fontData, 5, ranges); oc_font font = oc_font_create_from_memory(oc_str8_from_buffer(fontDataSize, (char*)fontData), 5, ranges);
free(fontData); free(fontData);
return (font); return (font);
@ -98,45 +93,45 @@ enum
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); oc_clock_init();
mp_rect rect = { .x = 100, .y = 100, .w = 980, .h = 600 }; oc_rect rect = { .x = 100, .y = 100, .w = 980, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0); oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface, canvas and font //NOTE: create surface, canvas and font
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
log_error("couldn't create surface\n"); oc_log_error("couldn't create surface\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
int fontIndex = 0; int fontIndex = 0;
mg_font fonts[FONT_COUNT] = { create_font("../../resources/OpenSansLatinSubset.ttf"), oc_font fonts[FONT_COUNT] = { create_font("../../resources/OpenSansLatinSubset.ttf"),
create_font("../../sketches/resources/CMUSerif-Roman.ttf"), create_font("../../resources/CMUSerif-Roman.ttf"),
create_font("../../sketches/resources/Courier.ttf") }; create_font("../../resources/Courier.ttf") };
mg_font_extents extents[FONT_COUNT]; oc_font_extents extents[FONT_COUNT];
f32 fontScales[FONT_COUNT]; f32 fontScales[FONT_COUNT];
f32 lineHeights[FONT_COUNT]; f32 lineHeights[FONT_COUNT];
for(int i = 0; i < FONT_COUNT; i++) for(int i = 0; i < FONT_COUNT; i++)
{ {
extents[i] = mg_font_get_extents(fonts[i]); extents[i] = oc_font_get_extents(fonts[i]);
fontScales[i] = mg_font_get_scale_for_em_pixels(fonts[i], 14); fontScales[i] = oc_font_get_scale_for_em_pixels(fonts[i], 14);
lineHeights[i] = fontScales[i] * (extents[i].ascent + extents[i].descent + extents[i].leading); lineHeights[i] = fontScales[i] * (extents[i].ascent + extents[i].descent + extents[i].leading);
} }
int codePointCount = utf8_codepoint_count_for_string(STR8((char*)TEST_STRING)); int codePointCount = oc_utf8_codepoint_count_for_string(OC_STR8((char*)TEST_STRING));
u32* codePoints = malloc_array(utf32, codePointCount); u32* codePoints = oc_malloc_array(oc_utf32, codePointCount);
utf8_to_codepoints(codePointCount, codePoints, STR8((char*)TEST_STRING)); oc_utf8_to_codepoints(codePointCount, codePoints, OC_STR8((char*)TEST_STRING));
u32 glyphCount = 0; u32 glyphCount = 0;
for(int i = 0; i < codePointCount; i++) for(int i = 0; i < codePointCount; i++)
@ -148,46 +143,46 @@ int main()
} }
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
f64 frameTime = 0; f64 frameTime = 0;
bool tracked = false; bool tracked = false;
vec2 trackPoint = { 0 }; oc_vec2 trackPoint = { 0 };
f32 zoom = 1; f32 zoom = 1;
f32 startX = 10; f32 startX = 10;
f32 startY = 10 + lineHeights[fontIndex]; f32 startY = 10 + lineHeights[fontIndex];
mp_input_state inputState = { 0 }; oc_input_state inputState = { 0 };
while(!mp_should_quit()) while(!oc_should_quit())
{ {
f64 startFrameTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startFrameTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
mp_input_process_event(&inputState, event); oc_input_process_event(&inputState, event);
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_MOUSE_BUTTON: case OC_EVENT_MOUSE_BUTTON:
{ {
if(event->key.code == MP_MOUSE_LEFT) if(event->key.code == OC_MOUSE_LEFT)
{ {
if(event->key.action == MP_KEY_PRESS) if(event->key.action == OC_KEY_PRESS)
{ {
tracked = true; tracked = true;
vec2 mousePos = mp_mouse_position(&inputState); oc_vec2 mousePos = oc_mouse_position(&inputState);
trackPoint.x = mousePos.x / zoom - startX; trackPoint.x = mousePos.x / zoom - startX;
trackPoint.y = mousePos.y / zoom - startY; trackPoint.y = mousePos.y / zoom - startY;
} }
@ -199,23 +194,23 @@ int main()
} }
break; break;
case MP_EVENT_MOUSE_WHEEL: case OC_EVENT_MOUSE_WHEEL:
{ {
vec2 mousePos = mp_mouse_position(&inputState); oc_vec2 mousePos = oc_mouse_position(&inputState);
f32 trackX = mousePos.x / zoom - startX; f32 trackX = mousePos.x / zoom - startX;
f32 trackY = mousePos.y / zoom - startY; f32 trackY = mousePos.y / zoom - startY;
zoom *= 1 + event->mouse.deltaY * 0.01; zoom *= 1 + event->mouse.deltaY * 0.01;
zoom = Clamp(zoom, 0.2, 10); zoom = oc_clamp(zoom, 0.2, 10);
startX = mousePos.x / zoom - trackX; startX = mousePos.x / zoom - trackX;
startY = mousePos.y / zoom - trackY; startY = mousePos.y / zoom - trackY;
} }
break; break;
case MP_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
if(event->key.code == MP_KEY_SPACE && event->key.action == MP_KEY_PRESS) if(event->key.code == OC_KEY_SPACE && event->key.action == OC_KEY_PRESS)
{ {
fontIndex = (fontIndex + 1) % FONT_COUNT; fontIndex = (fontIndex + 1) % FONT_COUNT;
} }
@ -229,7 +224,7 @@ int main()
if(tracked) if(tracked)
{ {
vec2 mousePos = mp_mouse_position(&inputState); oc_vec2 mousePos = oc_mouse_position(&inputState);
startX = mousePos.x / zoom - trackPoint.x; startX = mousePos.x / zoom - trackPoint.x;
startY = mousePos.y / zoom - trackPoint.y; startY = mousePos.y / zoom - trackPoint.y;
} }
@ -238,26 +233,26 @@ int main()
f32 textY = startY; f32 textY = startY;
/* /*
mg_set_color_rgba(1, 1, 1, 1); oc_set_color_rgba(1, 1, 1, 1);
mg_clear(); oc_clear();
mg_set_color_rgba(1, 0, 0, 1); oc_set_color_rgba(1, 0, 0, 1);
for(int i=0; i<1000; i++) for(int i=0; i<1000; i++)
{ {
mg_rectangle_fill(0, 0, 100, 100); oc_rectangle_fill(0, 0, 100, 100);
} }
*/ */
mg_matrix_push((mg_mat2x3){ zoom, 0, 0, oc_matrix_push((oc_mat2x3){ zoom, 0, 0,
0, zoom, 0 }); 0, zoom, 0 });
mg_set_color_rgba(1, 1, 1, 1); oc_set_color_rgba(1, 1, 1, 1);
mg_clear(); oc_clear();
mg_set_font(fonts[fontIndex]); oc_set_font(fonts[fontIndex]);
mg_set_font_size(14); oc_set_font_size(14);
mg_set_color_rgba(0, 0, 0, 1); oc_set_color_rgba(0, 0, 0, 1);
mg_move_to(textX, textY); oc_move_to(textX, textY);
int startIndex = 0; int startIndex = 0;
while(startIndex < codePointCount) while(startIndex < codePointCount)
@ -273,42 +268,42 @@ int main()
} }
u32 glyphs[512]; u32 glyphs[512];
mg_font_get_glyph_indices(fonts[fontIndex], (str32){ subIndex, codePoints + startIndex }, (str32){ 512, glyphs }); oc_font_get_glyph_indices(fonts[fontIndex], oc_str32_from_buffer(subIndex, codePoints + startIndex), oc_str32_from_buffer(512, glyphs));
mg_glyph_outlines((str32){ subIndex, glyphs }); oc_glyph_outlines(oc_str32_from_buffer(subIndex, glyphs));
mg_fill(); oc_fill();
textY += lineHeights[fontIndex]; textY += lineHeights[fontIndex];
mg_move_to(textX, textY); oc_move_to(textX, textY);
startIndex++; startIndex++;
startIndex += subIndex; startIndex += subIndex;
} }
mg_matrix_pop(); oc_matrix_pop();
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_set_font(fonts[fontIndex]); oc_set_font(fonts[fontIndex]);
mg_set_font_size(14); oc_set_font_size(14);
mg_move_to(10, contentRect.h - 10 - lineHeights[fontIndex]); oc_move_to(10, contentRect.h - 10 - lineHeights[fontIndex]);
str8 text = str8_pushf(mem_scratch(), oc_str8 text = oc_str8_pushf(oc_scratch(),
"Test program: %i glyphs, frame time = %fs, fps = %f", "Test program: %i glyphs, frame time = %fs, fps = %f",
glyphCount, glyphCount,
frameTime, frameTime,
1. / frameTime); 1. / frameTime);
mg_text_outlines(text); oc_text_outlines(text);
mg_fill(); oc_fill();
f64 startFlushTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startFlushTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mg_surface_prepare(surface); oc_surface_select(surface);
mg_render(surface, canvas); oc_render(surface, canvas);
f64 startPresentTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startPresentTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mg_surface_present(surface); oc_surface_present(surface);
f64 endFrameTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 endFrameTime = oc_clock_time(OC_CLOCK_MONOTONIC);
frameTime = (endFrameTime - startFrameTime); frameTime = (endFrameTime - startFrameTime);
@ -319,18 +314,18 @@ int main()
(startPresentTime - startFlushTime) * 1000, (startPresentTime - startFlushTime) * 1000,
(endFrameTime - startPresentTime) * 1000); (endFrameTime - startPresentTime) * 1000);
mp_input_next_frame(&inputState); oc_input_next_frame(&inputState);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
for(int i = 0; i < FONT_COUNT; i++) for(int i = 0; i < FONT_COUNT; i++)
{ {
mg_font_destroy(fonts[i]); oc_font_destroy(fonts[i]);
} }
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_poly.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_poly.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_polygon main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_polygon main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_polygon install_name_tool -add_rpath "@executable_path" $BINDIR/example_polygon

View File

@ -10,81 +10,78 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
mg_surface_swap_interval(surface, 1); oc_surface_swap_interval(surface, 1);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
printf("Error: couldn't create surface\n"); oc_log_error("Error: couldn't create surface\n");
return (-1); return (-1);
} }
//TODO: create canvas //TODO: create canvas
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
printf("Error: couldn't create canvas\n"); oc_log_error("Error: couldn't create canvas\n");
return (-1); return (-1);
} }
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
f64 frameTime = 0; f64 frameTime = 0;
f32 x = 0, y = 0; f32 x = 0, y = 0;
while(!mp_should_quit()) while(!oc_should_quit())
{ {
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
if(event->key.action == MP_KEY_PRESS) if(event->key.action == OC_KEY_PRESS)
{ {
if(event->key.code == MP_KEY_LEFT) if(event->key.code == OC_KEY_LEFT)
{ {
x -= 1; x -= 1;
} }
if(event->key.code == MP_KEY_RIGHT) if(event->key.code == OC_KEY_RIGHT)
{ {
x += 1; x += 1;
} }
if(event->key.code == MP_KEY_UP) if(event->key.code == OC_KEY_UP)
{ {
y -= 1; y -= 1;
} }
if(event->key.code == MP_KEY_DOWN) if(event->key.code == OC_KEY_DOWN)
{ {
y += 1; y += 1;
} }
@ -97,99 +94,99 @@ int main()
} }
} }
mg_surface_prepare(surface); oc_surface_select(surface);
// background // background
mg_set_color_rgba(0, 1, 1, 1); oc_set_color_rgba(0, 1, 1, 1);
mg_clear(); oc_clear();
mg_move_to(100, 100); oc_move_to(100, 100);
mg_line_to(150, 150); oc_line_to(150, 150);
mg_line_to(100, 200); oc_line_to(100, 200);
mg_line_to(50, 150); oc_line_to(50, 150);
mg_close_path(); oc_close_path();
mg_set_color_rgba(1, 0, 0, 1); oc_set_color_rgba(1, 0, 0, 1);
mg_fill(); oc_fill();
mg_move_to(200, 100); oc_move_to(200, 100);
mg_line_to(410, 100); oc_line_to(410, 100);
mg_line_to(410, 200); oc_line_to(410, 200);
mg_line_to(200, 200); oc_line_to(200, 200);
mg_close_path(); oc_close_path();
mg_set_color_rgba(0, 1, 0, 1); oc_set_color_rgba(0, 1, 0, 1);
mg_fill(); oc_fill();
mg_set_color_rgba(0, 1, 1, 0.5); oc_set_color_rgba(0, 0.5, 1, 0.5);
mg_rectangle_fill(120, 120, 200, 200); oc_rectangle_fill(120, 120, 200, 200);
mg_set_color_rgba(1, 0, 0.5, 1); oc_set_color_rgba(1, 0, 0.5, 1);
mg_rectangle_fill(700, 500, 200, 200); oc_rectangle_fill(700, 500, 200, 200);
mg_move_to(300, 300); oc_move_to(300, 300);
mg_quadratic_to(400, 500, 500, 300); oc_quadratic_to(400, 500, 500, 300);
mg_close_path(); oc_close_path();
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_fill(); oc_fill();
mg_move_to(200, 450); oc_move_to(200, 450);
mg_cubic_to(200, 250, 400, 550, 400, 450); oc_cubic_to(200, 250, 400, 550, 400, 450);
mg_close_path(); oc_close_path();
mg_set_color_rgba(1, 0.5, 0, 1); oc_set_color_rgba(1, 0.5, 0, 1);
mg_fill(); oc_fill();
/* /*
mg_set_joint(MG_JOINT_NONE); oc_set_joint(OC_JOINT_NONE);
mg_set_max_joint_excursion(20); oc_set_max_joint_excursion(20);
mg_set_cap(MG_CAP_SQUARE); oc_set_cap(OC_CAP_SQUARE);
mg_move_to(x+200, y+200); oc_move_to(x+200, y+200);
mg_line_to(x+300, y+300); oc_line_to(x+300, y+300);
mg_line_to(x+200, y+400); oc_line_to(x+200, y+400);
mg_line_to(x+100, y+300); oc_line_to(x+100, y+300);
mg_close_path(); oc_close_path();
mg_set_color_rgba(1, 0, 0, 1); oc_set_color_rgba(1, 0, 0, 1);
// mg_set_width(2); // oc_set_width(2);
mg_stroke(); oc_stroke();
mg_move_to(400, 400); oc_move_to(400, 400);
mg_quadratic_to(600, 601, 800, 400); oc_quadratic_to(600, 601, 800, 400);
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_stroke(); oc_stroke();
mg_move_to(x+400, y+300); oc_move_to(x+400, y+300);
mg_cubic_to(x+400, y+100, x+600, y+400, x+600, y+300); oc_cubic_to(x+400, y+100, x+600, y+400, x+600, y+300);
mg_close_path(); oc_close_path();
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_stroke(); oc_stroke();
mg_set_color_rgba(1, 0, 0, 1); oc_set_color_rgba(1, 0, 0, 1);
mg_rounded_rectangle_fill(100, 100, 200, 300, 20); oc_rounded_rectangle_fill(100, 100, 200, 300, 20);
mg_move_to(x+8, y+8); oc_move_to(x+8, y+8);
mg_line_to(x+33, y+8); oc_line_to(x+33, y+8);
mg_line_to(x+33, y+19); oc_line_to(x+33, y+19);
mg_line_to(x+8, y+19); oc_line_to(x+8, y+19);
mg_close_path(); oc_close_path();
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_fill(); oc_fill();
*/ */
printf("Milepost vector graphics test program (frame time = %fs, fps = %f)...\n", oc_log_info("Orca vector graphics test program (frame time = %fs, fps = %f)...\n",
frameTime, frameTime,
1. / frameTime); 1. / frameTime);
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
frameTime = mp_get_time(MP_CLOCK_MONOTONIC) - startTime; frameTime = oc_clock_time(OC_CLOCK_MONOTONIC) - startTime;
} }
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,5 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /MANIFEST:EMBED /MANIFESTINPUT:../../src/win32_manifest.xml /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_render_thread.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /MANIFEST:EMBED /MANIFESTINPUT:../../src/app/win32_manifest.xml /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_poly.exe
cp ../../build/bin/orca.dll bin/

14
sketches/render_thread/build.sh Normal file → Executable file
View File

@ -1,14 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_render_thread main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_render_thread main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_render_thread install_name_tool -add_rpath "@executable_path" $BINDIR/example_render_thread

View File

@ -2,24 +2,23 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define MG_INCLUDE_GL_API 1 #include "orca.h"
#include "milepost.h"
mg_surface surface = { 0 }; oc_surface surface = { 0 };
mg_canvas canvas = { 0 }; oc_canvas canvas = { 0 };
i32 render_thread(void* user) i32 render_thread(void* user)
{ {
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -28,72 +27,71 @@ i32 render_thread(void* user)
} }
} }
mg_surface_prepare(surface); oc_surface_select(surface);
mg_canvas_set_current(canvas); oc_canvas_set_current(canvas);
mg_set_color_rgba(0, 0, 0.5, 0.5); oc_set_color_rgba(0, 0, 0.5, 0.5);
mg_clear(); oc_clear();
mg_set_color_rgba(1, 0, 0, 1); oc_set_color_rgba(1, 0, 0, 1);
mg_rectangle_fill(100, 100, 300, 150); oc_rectangle_fill(100, 100, 300, 150);
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
return (0); return (0);
} }
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
surface = mg_surface_create_for_window(window, MG_CANVAS); surface = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
printf("Error: couldn't create surface 1\n"); printf("Error: couldn't create surface 1\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
canvas = mg_canvas_create(); canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
printf("Error: couldn't create canvas 1\n"); printf("Error: couldn't create canvas 1\n");
return (-1); return (-1);
} }
mg_surface dummy = mg_surface_create_for_window(window, MG_CANVAS); oc_surface dummy = oc_surface_create_for_window(window, OC_CANVAS);
// start app // start app
mp_window_center(window); oc_window_center(window);
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
mp_thread* renderThread = mp_thread_create(render_thread, NULL); oc_thread* renderThread = oc_thread_create(render_thread, NULL);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
} }
mp_thread_join(renderThread, NULL); oc_thread_join(renderThread, NULL);
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

Binary file not shown.

View File

@ -1,2 +1,5 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib user32.lib /out:../../bin/example_simple_window.exe
if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib user32.lib /out:bin/example_simple_window.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,14 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore" LIBS="-L$LIBDIR -lorca -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
clang -g $FLAGS -Wl,-dead_strip $LIBS $INCLUDES -o $BINDIR/example_simple_window main.c mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_simple_window main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_simple_window install_name_tool -add_rpath "@executable_path" $BINDIR/example_simple_window

View File

@ -10,37 +10,37 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "milepost.h" #include "orca.h"
int main() int main()
{ {
mp_init(); oc_init();
mp_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 }; oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0); oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
mp_window_center(window); oc_window_center(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_WINDOW_RESIZE: case OC_EVENT_WINDOW_RESIZE:
{ {
printf("resized, frame = {%f, %f, %f, %f}, content = {%f, %f, %f, %f}\n", oc_log_info("resized, frame = {%f, %f, %f, %f}, content = {%f, %f, %f, %f}\n",
event->move.frame.x, event->move.frame.x,
event->move.frame.y, event->move.frame.y,
event->move.frame.w, event->move.frame.w,
@ -52,9 +52,9 @@ int main()
} }
break; break;
case MP_EVENT_WINDOW_MOVE: case OC_EVENT_WINDOW_MOVE:
{ {
printf("moved, frame = {%f, %f, %f, %f}, content = {%f, %f, %f, %f}\n", oc_log_info("moved, frame = {%f, %f, %f, %f}, content = {%f, %f, %f, %f}\n",
event->move.frame.x, event->move.frame.x,
event->move.frame.y, event->move.frame.y,
event->move.frame.w, event->move.frame.w,
@ -66,9 +66,9 @@ int main()
} }
break; break;
case MP_EVENT_MOUSE_MOVE: case OC_EVENT_MOUSE_MOVE:
{ {
printf("mouse moved, pos = {%f, %f}, delta = {%f, %f}\n", oc_log_info("mouse moved, pos = {%f, %f}, delta = {%f, %f}\n",
event->mouse.x, event->mouse.x,
event->mouse.y, event->mouse.y,
event->mouse.deltaX, event->mouse.deltaX,
@ -76,45 +76,45 @@ int main()
} }
break; break;
case MP_EVENT_MOUSE_WHEEL: case OC_EVENT_MOUSE_WHEEL:
{ {
printf("mouse wheel, delta = {%f, %f}\n", oc_log_info("mouse wheel, delta = {%f, %f}\n",
event->mouse.deltaX, event->mouse.deltaX,
event->mouse.deltaY); event->mouse.deltaY);
} }
break; break;
case MP_EVENT_MOUSE_ENTER: case OC_EVENT_MOUSE_ENTER:
{ {
printf("mouse enter\n"); oc_log_info("mouse enter\n");
} }
break; break;
case MP_EVENT_MOUSE_LEAVE: case OC_EVENT_MOUSE_LEAVE:
{ {
printf("mouse leave\n"); oc_log_info("mouse leave\n");
} }
break; break;
case MP_EVENT_MOUSE_BUTTON: case OC_EVENT_MOUSE_BUTTON:
{ {
printf("mouse button %i: %i\n", oc_log_info("mouse button %i: %i\n",
event->key.code, event->key.code,
event->key.action == MP_KEY_PRESS ? 1 : 0); event->key.action == OC_KEY_PRESS ? 1 : 0);
} }
break; break;
case MP_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
printf("key %i: %s\n", oc_log_info("key %i: %s\n",
event->key.code, event->key.code,
event->key.action == MP_KEY_PRESS ? "press" : (event->key.action == MP_KEY_RELEASE ? "release" : "repeat")); event->key.action == OC_KEY_PRESS ? "press" : (event->key.action == OC_KEY_RELEASE ? "release" : "repeat"));
} }
break; break;
case MP_EVENT_KEYBOARD_CHAR: case OC_EVENT_KEYBOARD_CHAR:
{ {
printf("entered char %s\n", event->character.sequence); oc_log_info("entered char %s\n", event->character.sequence);
} }
break; break;
@ -122,10 +122,10 @@ int main()
break; break;
} }
} }
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle/include
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_smooth_resize.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_smooth_resize.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,20 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
ANGLEDIR=../../ext/angle/include
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR/ -I$ANGLEDIR/"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_smooth_resize main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_smooth_resize main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_smooth_resize install_name_tool -add_rpath "@executable_path" $BINDIR/example_smooth_resize

View File

@ -14,14 +14,14 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#define MG_INCLUDE_GL_API #define OC_INCLUDE_GL_API
#include "milepost.h" #include "orca.h"
unsigned int program; unsigned int program;
const char* vshaderSource = const char* vshaderSource =
"#version 430\n" "#version 430\n"
"attribute vec4 vPosition;\n" "in vec4 vPosition;\n"
"uniform mat4 transform;\n" "uniform mat4 transform;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
@ -30,10 +30,11 @@ const char* vshaderSource =
const char* fshaderSource = const char* fshaderSource =
"#version 430\n" "#version 430\n"
"layout(location = 0) out vec4 diffuse;"
"precision mediump float;\n" "precision mediump float;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" " diffuse = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n"; "}\n";
void compile_shader(GLuint shader, const char* source) void compile_shader(GLuint shader, const char* source)
@ -44,7 +45,7 @@ void compile_shader(GLuint shader, const char* source)
int err = glGetError(); int err = glGetError();
if(err) if(err)
{ {
printf("gl error: %i\n", err); oc_log_error("gl error: %i\n", err);
} }
int status = 0; int status = 0;
@ -54,7 +55,7 @@ void compile_shader(GLuint shader, const char* source)
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetShaderInfoLog(shader, 256, &size, buffer); glGetShaderInfoLog(shader, 256, &size, buffer);
printf("shader error: %.*s\n", size, buffer); oc_log_error("shader error: %.*s\n", size, buffer);
} }
} }
@ -64,27 +65,27 @@ GLfloat vertices[] = {
typedef struct app_data typedef struct app_data
{ {
mp_window window; oc_window window;
mg_surface surface; oc_surface surface;
mg_canvas canvas; oc_canvas canvas;
mg_font font; oc_font font;
GLuint vertexBuffer; GLuint vertexBuffer;
} app_data; } app_data;
void process_event(app_data* app, mp_event event) void process_event(app_data* app, oc_event event)
{ {
switch(event.type) switch(event.type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_WINDOW_RESIZE: case OC_EVENT_WINDOW_RESIZE:
{ {
log_info("resizing window!\n"); oc_log_info("resizing window!\n");
} }
break; break;
@ -95,7 +96,7 @@ void process_event(app_data* app, mp_event event)
void update_and_render(app_data* app) void update_and_render(app_data* app)
{ {
mg_surface_prepare(app->surface); oc_surface_select(app->surface);
glClearColor(0.3, 0.3, 1, 1); glClearColor(0.3, 0.3, 1, 1);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -119,9 +120,9 @@ void update_and_render(app_data* app)
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
mg_surface_present(app->surface); oc_surface_present(app->surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
i32 render(void* user) i32 render(void* user)
@ -129,7 +130,7 @@ i32 render(void* user)
app_data* app = (app_data*)user; app_data* app = (app_data*)user;
//NOTE: init shader and gl state //NOTE: init shader and gl state
mg_surface_prepare(app->surface); oc_surface_select(app->surface);
GLuint vao; GLuint vao;
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
@ -162,21 +163,21 @@ i32 render(void* user)
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetProgramInfoLog(program, 256, &size, buffer); glGetProgramInfoLog(program, 256, &size, buffer);
printf("link error: %.*s\n", size, buffer); oc_log_error("link error: %.*s\n", size, buffer);
} }
glUseProgram(program); glUseProgram(program);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
process_event(app, *event); process_event(app, *event);
} }
update_and_render(app); update_and_render(app);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
return (0); return (0);
@ -184,44 +185,43 @@ i32 render(void* user)
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_GL); oc_surface surface = oc_surface_create_for_window(window, OC_GL);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
printf("Error: couldn't create surface\n"); oc_log_error("Error: couldn't create surface\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 1); oc_surface_swap_interval(surface, 1);
mg_surface_deselect(); oc_surface_deselect();
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
//TODO: start thread //TODO: start thread
app_data app = { .window = window, app_data app = { .window = window,
.surface = surface }; .surface = surface };
mp_thread* renderThread = mp_thread_create(render, &app); oc_thread* renderThread = oc_thread_create(render, &app);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
} }
mp_thread_join(renderThread, NULL); oc_thread_join(renderThread, NULL);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,8 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle/include
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_surface_sharing.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_surface_sharing.exe
cp ../../build/bin/orca.dll bin/
cp ../../ext/angle/bin/libEGL.dll bin/
cp ../../ext/angle/bin/libGLESv2.dll bin/

View File

@ -1,14 +1,22 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext EXTDIR=../../ext
ANGLEDIR=../../ext/angle/
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR/ -I$ANGLEDIR/include"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_surface_sharing main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_surface_sharing main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
cp $ANGLEDIR/bin/libEGL.dylib $BINDIR/
cp $ANGLEDIR/bin/libGLESv2.dylib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_surface_sharing install_name_tool -add_rpath "@executable_path" $BINDIR/example_surface_sharing

View File

@ -8,12 +8,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define MG_INCLUDE_GL_API 1 #define OC_INCLUDE_GL_API
#include "milepost.h" #include "orca.h"
#define LOG_SUBSYSTEM "Main" #ifdef OC_PLATFORM_WINDOWS
#ifdef OS_WIN64
#include <process.h> #include <process.h>
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
@ -35,7 +33,7 @@ void terminate_child(process_id child)
TerminateProcess(child, 0); TerminateProcess(child, 0);
} }
#elif OS_MACOS #elif OC_PLATFORM_MACOS
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
@ -48,7 +46,7 @@ process_id spawn_child(char* program, char** argv)
{ {
char* envp[] = { 0 }; char* envp[] = { 0 };
execve(program, argv, envp); execve(program, argv, envp);
assert(0); OC_ASSERT(0);
} }
return (pid); return (pid);
} }
@ -86,7 +84,7 @@ void compile_shader(GLuint shader, const char* source)
int err = glGetError(); int err = glGetError();
if(err) if(err)
{ {
printf("gl error: %i\n", err); oc_log_error("gl error: %i\n", err);
} }
int status = 0; int status = 0;
@ -96,25 +94,25 @@ void compile_shader(GLuint shader, const char* source)
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetShaderInfoLog(shader, 256, &size, buffer); glGetShaderInfoLog(shader, 256, &size, buffer);
printf("shader error: %.*s\n", size, buffer); oc_log_error("shader error: %.*s\n", size, buffer);
} }
} }
int child_main(int writeFd) int child_main(int writeFd)
{ {
mp_init(); oc_init();
mp_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 }; oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0); oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_remote(800, 600, MG_BACKEND_GLES); oc_surface surface = oc_surface_create_remote(800, 600, OC_GLES);
mg_surface_id connectionID = mg_surface_remote_id(surface); oc_surface_id connectionID = oc_surface_remote_id(surface);
mg_surface_prepare(surface); oc_surface_select(surface);
//NOTE: init shader and gl state //NOTE: init shader and gl state
mg_surface_prepare(surface); oc_surface_select(surface);
GLuint vao; GLuint vao;
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
@ -148,7 +146,7 @@ int child_main(int writeFd)
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetProgramInfoLog(program, 256, &size, buffer); glGetProgramInfoLog(program, 256, &size, buffer);
printf("link error: %.*s\n", size, buffer); oc_log_error("link error: %.*s\n", size, buffer);
} }
glUseProgram(program); glUseProgram(program);
@ -157,17 +155,17 @@ int child_main(int writeFd)
write(writeFd, &connectionID, sizeof(connectionID)); write(writeFd, &connectionID, sizeof(connectionID));
//NOTE: render loop //NOTE: render loop
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event event = { 0 }; oc_event* event = 0;
while(mp_next_event(&event)) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event.type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -176,12 +174,12 @@ int child_main(int writeFd)
} }
} }
mg_surface_prepare(surface); oc_surface_select(surface);
mp_rect rect = mg_surface_get_frame(surface); oc_vec2 size = oc_surface_get_size(surface);
vec2 scaling = mg_surface_contents_scaling(surface); oc_vec2 scaling = oc_surface_contents_scaling(surface);
glViewport(0, 0, rect.w * scaling.x, rect.h * scaling.y); glViewport(0, 0, size.x * scaling.x, size.y * scaling.y);
glClearColor(0.3, 0.3, 1, 1); glClearColor(0.3, 0.3, 1, 1);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -204,24 +202,22 @@ int child_main(int writeFd)
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
mg_surface_present(surface); oc_surface_present(surface);
} }
mp_terminate(); oc_terminate();
return (0); return (0);
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
LogLevel(LOG_LEVEL_DEBUG);
if(argc > 1) if(argc > 1)
{ {
if(!strcmp(argv[1], "--child")) if(!strcmp(argv[1], "--child"))
{ {
int writeFd = atoi(argv[2]); int writeFd = atoi(argv[2]);
printf("child process created with file desc %i\n", writeFd); oc_log_info("child process created with file desc %i\n", writeFd);
return (child_main(writeFd)); return (child_main(writeFd));
} }
else else
@ -230,20 +226,20 @@ int main(int argc, char** argv)
} }
} }
// setvbuf( stdout, NULL, _IONBF, 0 ); // setvbuf( stdout, NULL, _IONBF, 0 );
mp_init(); oc_init();
//NOTE: create main window //NOTE: create main window
mp_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 }; oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0); oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
//NOTE: create surface client //NOTE: create surface client
mg_surface surface = mg_surface_create_host(window); oc_surface surface = oc_surface_create_host(window);
//NOTE setup descriptors //NOTE setup descriptors
int fileDesc[2]; int fileDesc[2];
pipe(fileDesc); pipe(fileDesc);
printf("parent process created readFd %i and writeFd %i\n", fileDesc[0], fileDesc[1]); oc_log_info("parent process created readFd %i and writeFd %i\n", fileDesc[0], fileDesc[1]);
char writeDescStr[64]; char writeDescStr[64];
snprintf(writeDescStr, 64, "%i", fileDesc[1]); snprintf(writeDescStr, 64, "%i", fileDesc[1]);
@ -252,40 +248,42 @@ int main(int argc, char** argv)
process_id child = spawn_child(args[0], args); process_id child = spawn_child(args[0], args);
//NOTE: read the connection id //NOTE: read the connection id
mg_surface_id connectionID = 0; oc_surface_id connectionID = 0;
read(fileDesc[0], &connectionID, sizeof(connectionID)); read(fileDesc[0], &connectionID, sizeof(connectionID));
printf("received child connection id %llu\n", connectionID); oc_log_info("received child connection id %llu\n", connectionID);
//NOTE: connect the client //NOTE: connect the client
mg_surface_host_connect(surface, connectionID); oc_surface_host_connect(surface, connectionID);
//NOTE: show the window //NOTE: show the window
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event event = { 0 }; oc_event* event = 0;
while(mp_next_event(&event)) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event.type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
default: default:
break; break;
} }
oc_arena_clear(oc_scratch());
} }
mg_surface_prepare(surface); oc_surface_select(surface);
mg_surface_present(surface); oc_surface_present(surface);
} }
terminate_child(child); terminate_child(child);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle/include
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_tiger.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_tiger.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../build/bin BINDIR=bin
LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_tiger main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_tiger main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_tiger install_name_tool -add_rpath "@executable_path" $BINDIR/example_tiger

View File

@ -14,21 +14,21 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
#include "tiger.c" #include "tiger.c"
mg_font create_font() oc_font create_font()
{ {
//NOTE(martin): create font //NOTE(martin): create font
str8 fontPath = path_executable_relative(mem_scratch(), STR8("../resources/OpenSansLatinSubset.ttf")); oc_str8 fontPath = oc_path_executable_relative(oc_scratch(), OC_STR8("../../resources/OpenSansLatinSubset.ttf"));
char* fontPathCString = str8_to_cstring(mem_scratch(), fontPath); char* fontPathCString = oc_str8_to_cstring(oc_scratch(), fontPath);
FILE* fontFile = fopen(fontPathCString, "r"); FILE* fontFile = fopen(fontPathCString, "r");
if(!fontFile) if(!fontFile)
{ {
log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno)); oc_log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno));
return (mg_font_nil()); return (oc_font_nil());
} }
unsigned char* fontData = 0; unsigned char* fontData = 0;
fseek(fontFile, 0, SEEK_END); fseek(fontFile, 0, SEEK_END);
@ -38,13 +38,13 @@ mg_font create_font()
fread(fontData, 1, fontDataSize, fontFile); fread(fontData, 1, fontDataSize, fontFile);
fclose(fontFile); fclose(fontFile);
unicode_range ranges[5] = { UNICODE_RANGE_BASIC_LATIN, oc_unicode_range ranges[5] = { OC_UNICODE_BASIC_LATIN,
UNICODE_RANGE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT, OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
UNICODE_RANGE_LATIN_EXTENDED_A, OC_UNICODE_LATIN_EXTENDED_A,
UNICODE_RANGE_LATIN_EXTENDED_B, OC_UNICODE_LATIN_EXTENDED_B,
UNICODE_RANGE_SPECIALS }; OC_UNICODE_SPECIALS };
mg_font font = mg_font_create_from_memory(fontDataSize, fontData, 5, ranges); oc_font font = oc_font_create_from_memory(oc_str8_from_buffer(fontDataSize, (char*)fontData), 5, ranges);
free(fontData); free(fontData);
return (font); return (font);
@ -52,40 +52,39 @@ mg_font create_font()
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()?
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
if(mg_surface_is_nil(surface)) if(oc_surface_is_nil(surface))
{ {
log_error("Couln't create surface\n"); oc_log_error("Couldn't create surface\n");
return (-1); return (-1);
} }
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
//TODO: create canvas //TODO: create canvas
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
printf("Error: couldn't create canvas\n"); oc_log_error("Error: couldn't create canvas\n");
return (-1); return (-1);
} }
mg_font font = create_font(); oc_font font = create_font();
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
bool tracked = false; bool tracked = false;
vec2 trackPoint = { 0 }; oc_vec2 trackPoint = { 0 };
f32 zoom = 1; f32 zoom = 1;
f32 startX = 300, startY = 200; f32 startX = 300, startY = 200;
@ -94,34 +93,34 @@ int main()
f64 frameTime = 0; f64 frameTime = 0;
mp_input_state inputState = { 0 }; oc_input_state inputState = { 0 };
while(!mp_should_quit()) while(!oc_should_quit())
{ {
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
mp_input_process_event(&inputState, event); oc_input_process_event(&inputState, event);
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_MOUSE_BUTTON: case OC_EVENT_MOUSE_BUTTON:
{ {
if(event->key.code == MP_MOUSE_LEFT) if(event->key.code == OC_MOUSE_LEFT)
{ {
if(event->key.action == MP_KEY_PRESS) if(event->key.action == OC_KEY_PRESS)
{ {
tracked = true; tracked = true;
vec2 mousePos = mp_mouse_position(&inputState); oc_vec2 mousePos = oc_mouse_position(&inputState);
trackPoint.x = (mousePos.x - startX) / zoom; trackPoint.x = (mousePos.x - startX) / zoom;
trackPoint.y = (mousePos.y - startY) / zoom; trackPoint.y = (mousePos.y - startY) / zoom;
} }
@ -133,33 +132,33 @@ int main()
} }
break; break;
case MP_EVENT_MOUSE_WHEEL: case OC_EVENT_MOUSE_WHEEL:
{ {
vec2 mousePos = mp_mouse_position(&inputState); oc_vec2 mousePos = oc_mouse_position(&inputState);
f32 pinX = (mousePos.x - startX) / zoom; f32 pinX = (mousePos.x - startX) / zoom;
f32 pinY = (mousePos.y - startY) / zoom; f32 pinY = (mousePos.y - startY) / zoom;
zoom *= 1 + event->mouse.deltaY * 0.01; zoom *= 1 + event->mouse.deltaY * 0.01;
zoom = Clamp(zoom, 0.5, 5); zoom = oc_clamp(zoom, 0.5, 5);
startX = mousePos.x - pinX * zoom; startX = mousePos.x - pinX * zoom;
startY = mousePos.y - pinY * zoom; startY = mousePos.y - pinY * zoom;
} }
break; break;
case MP_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
if(event->key.action == MP_KEY_PRESS || event->key.action == MP_KEY_REPEAT) if(event->key.action == OC_KEY_PRESS || event->key.action == OC_KEY_REPEAT)
{ {
switch(event->key.code) switch(event->key.code)
{ {
case MP_KEY_SPACE: case OC_KEY_SPACE:
singlePath = !singlePath; singlePath = !singlePath;
break; break;
case MP_KEY_UP: case OC_KEY_UP:
{ {
if(event->key.mods & MP_KEYMOD_SHIFT) if(event->key.mods & OC_KEYMOD_SHIFT)
{ {
singlePathIndex++; singlePathIndex++;
} }
@ -170,9 +169,9 @@ int main()
} }
break; break;
case MP_KEY_DOWN: case OC_KEY_DOWN:
{ {
if(event->key.mods & MP_KEYMOD_SHIFT) if(event->key.mods & OC_KEYMOD_SHIFT)
{ {
singlePathIndex--; singlePathIndex--;
} }
@ -194,60 +193,60 @@ int main()
if(tracked) if(tracked)
{ {
vec2 mousePos = mp_mouse_position(&inputState); oc_vec2 mousePos = oc_mouse_position(&inputState);
startX = mousePos.x - trackPoint.x * zoom; startX = mousePos.x - trackPoint.x * zoom;
startY = mousePos.y - trackPoint.y * zoom; startY = mousePos.y - trackPoint.y * zoom;
} }
mg_surface_prepare(surface); oc_surface_select(surface);
mg_set_color_rgba(1, 0, 1, 1); oc_set_color_rgba(1, 0, 1, 1);
mg_clear(); oc_clear();
mg_matrix_push((mg_mat2x3){ zoom, 0, startX, oc_matrix_push((oc_mat2x3){ zoom, 0, startX,
0, zoom, startY }); 0, zoom, startY });
draw_tiger(singlePath, singlePathIndex); draw_tiger(singlePath, singlePathIndex);
if(singlePath) if(singlePath)
{ {
printf("display single path %i\n", singlePathIndex); oc_log_info("display single path %i\n", singlePathIndex);
printf("viewpos = (%f, %f), zoom = %f\n", startX, startY, zoom); oc_log_info("viewpos = (%f, %f), zoom = %f\n", startX, startY, zoom);
} }
mg_matrix_pop(); oc_matrix_pop();
// text // text
mg_set_color_rgba(0, 0, 1, 1); oc_set_color_rgba(0, 0, 1, 1);
mg_set_font(font); oc_set_font(font);
mg_set_font_size(12); oc_set_font_size(12);
mg_move_to(50, 600 - 50); oc_move_to(50, 600 - 50);
str8 text = str8_pushf(mem_scratch(), oc_str8 text = oc_str8_pushf(oc_scratch(),
"Milepost vector graphics test program (frame time = %fs, fps = %f)...", "Orca vector graphics test program (frame time = %fs, fps = %f)...",
frameTime, frameTime,
1. / frameTime); 1. / frameTime);
mg_text_outlines(text); oc_text_outlines(text);
mg_fill(); oc_fill();
printf("Milepost vector graphics test program (frame time = %fs, fps = %f)...\n", oc_log_info("Orca vector graphics test program (frame time = %fs, fps = %f)...\n",
frameTime, frameTime,
1. / frameTime); 1. / frameTime);
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mp_input_next_frame(&inputState); oc_input_next_frame(&inputState);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
frameTime = mp_get_time(MP_CLOCK_MONOTONIC) - startTime; frameTime = oc_clock_time(OC_CLOCK_MONOTONIC) - startTime;
} }
mg_font_destroy(font); oc_font_destroy(font);
mg_canvas_destroy(canvas); oc_canvas_destroy(canvas);
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -54,7 +54,7 @@ class svgContext:
if rel: if rel:
x += self.cp[0] x += self.cp[0]
y += self.cp[1] y += self.cp[1]
print("\t\tmg_move_to(" + f2s(x) + ", " + f2s(y) + ");") print("\t\toc_move_to(" + f2s(x) + ", " + f2s(y) + ");")
self.sp = (x, y) self.sp = (x, y)
self.cp = (x, y) self.cp = (x, y)
self.rp = self.cp self.rp = self.cp
@ -67,7 +67,7 @@ class svgContext:
y2 += self.cp[1] y2 += self.cp[1]
x3 += self.cp[0] x3 += self.cp[0]
y3 += self.cp[1] y3 += self.cp[1]
print("\t\tmg_cubic_to(" + f2s(x1) + ", " + f2s(y1) + ", " + f2s(x2) + ", " + f2s(y2) + ", " + f2s(x3) + ", " + f2s(y3) + ");") print("\t\toc_cubic_to(" + f2s(x1) + ", " + f2s(y1) + ", " + f2s(x2) + ", " + f2s(y2) + ", " + f2s(x3) + ", " + f2s(y3) + ");")
self.rp = (x2, y2) self.rp = (x2, y2)
self.cp = (x3, y3) self.cp = (x3, y3)
@ -79,7 +79,7 @@ class svgContext:
y3 += self.cp[1] y3 += self.cp[1]
x1 = 2*self.cp[0] - self.rp[0] x1 = 2*self.cp[0] - self.rp[0]
y1 = 2*self.cp[1] - self.rp[1] y1 = 2*self.cp[1] - self.rp[1]
print("\t\tmg_cubic_to(" + f2s(x1) + ", " + f2s(y1) + ", " + f2s(x2) + ", " + f2s(y2) + ", " + f2s(x3) + ", " + f2s(y3) + ");") print("\t\toc_cubic_to(" + f2s(x1) + ", " + f2s(y1) + ", " + f2s(x2) + ", " + f2s(y2) + ", " + f2s(x3) + ", " + f2s(y3) + ");")
self.rp = (x2, y2) self.rp = (x2, y2)
self.cp = (x3, y3) self.cp = (x3, y3)
@ -87,7 +87,7 @@ class svgContext:
if rel: if rel:
x1 += self.cp[0] x1 += self.cp[0]
y1 += self.cp[1] y1 += self.cp[1]
print("\t\tmg_line_to(" + f2s(x1) + ", " + f2s(y1) + ");") print("\t\toc_line_to(" + f2s(x1) + ", " + f2s(y1) + ");")
self.cp = (x1, y1) self.cp = (x1, y1)
self.rp = self.cp self.rp = self.cp
@ -95,12 +95,12 @@ class svgContext:
if rel: if rel:
y1 += self.cp[1] y1 += self.cp[1]
x1 = self.cp[0] x1 = self.cp[0]
print("\t\tmg_line_to(" + f2s(x1) + ", " + f2s(y1) + ");") print("\t\toc_line_to(" + f2s(x1) + ", " + f2s(y1) + ");")
self.cp = (x1, y1) self.cp = (x1, y1)
self.rp = self.cp self.rp = self.cp
def close_path(self): def close_path(self):
print("\t\tmg_close_path();"); print("\t\toc_close_path();");
self.cp = self.rp = self.sp self.cp = self.rp = self.sp
def print_path(path, ctx): def print_path(path, ctx):
@ -209,8 +209,8 @@ for g in tree.iter('{http://www.w3.org/2000/svg}g'):
if fill != None and fill != "none": if fill != None and fill != "none":
(r, g, b) = parse_color(fill) (r, g, b) = parse_color(fill)
print("\t\tmg_set_color_rgba(" + f2s(r) + ", " + f2s(g) + ", " + f2s(b) + ", 1);") print("\t\toc_set_color_rgba(" + f2s(r) + ", " + f2s(g) + ", " + f2s(b) + ", 1);")
print("\t\tmg_fill();") print("\t\toc_fill();")
print("\t}") print("\t}")
pathIndex += 1 pathIndex += 1
@ -220,16 +220,16 @@ for g in tree.iter('{http://www.w3.org/2000/svg}g'):
print("\t{") print("\t{")
if stroke_width != None: if stroke_width != None:
print("\t\tmg_set_width(" + stroke_width + ");"); print("\t\toc_set_width(" + stroke_width + ");");
else: else:
print("\t\tmg_set_width(1);"); print("\t\toc_set_width(1);");
(r, g, b) = parse_color(stroke) (r, g, b) = parse_color(stroke)
if fill != None: if fill != None:
ctx.reset() ctx.reset()
print_path(path, ctx) print_path(path, ctx)
print("\t\tmg_set_color_rgba(" + f2s(r) + ", " + f2s(g) + ", " + f2s(b) + ", 1);") print("\t\toc_set_color_rgba(" + f2s(r) + ", " + f2s(g) + ", " + f2s(b) + ", 1);")
print("\t\tmg_stroke();") print("\t\toc_stroke();")
print("\t}") print("\t}")
pathIndex += 1 pathIndex += 1

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_gl_triangle.exe set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle/include
if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_gl_triangle.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,11 +1,20 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
ANGLEDIR=../../ext/angle/
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR/ -I$ANGLEDIR/include"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
clang -g $FLAGS $LIBS $INCLUDES -o test main.c mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_triangle main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_triangle

View File

@ -12,14 +12,14 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#define MG_INCLUDE_GL_API #define OC_INCLUDE_GL_API
#include "milepost.h" #include "orca.h"
unsigned int program; unsigned int program;
const char* vshaderSource = const char* vshaderSource =
"#version 430\n" "#version 430\n"
"attribute vec4 vPosition;\n" "in vec4 vPosition;\n"
"uniform mat4 transform;\n" "uniform mat4 transform;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
@ -29,9 +29,10 @@ const char* vshaderSource =
const char* fshaderSource = const char* fshaderSource =
"#version 430\n" "#version 430\n"
"precision mediump float;\n" "precision mediump float;\n"
"layout(location = 0) out vec4 diffuse;"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" " diffuse = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n"; "}\n";
void compile_shader(GLuint shader, const char* source) void compile_shader(GLuint shader, const char* source)
@ -42,7 +43,7 @@ void compile_shader(GLuint shader, const char* source)
int err = glGetError(); int err = glGetError();
if(err) if(err)
{ {
printf("gl error: %i\n", err); oc_log_error("gl error: %i\n", err);
} }
int status = 0; int status = 0;
@ -52,22 +53,31 @@ void compile_shader(GLuint shader, const char* source)
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetShaderInfoLog(shader, 256, &size, buffer); glGetShaderInfoLog(shader, 256, &size, buffer);
printf("shader error: %.*s\n", size, buffer); oc_log_error("shader error: %.*s\n", size, buffer);
} }
} }
int main() int main()
{ {
mp_init(); oc_init();
mp_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 }; oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0); oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_GL); oc_surface surface = oc_surface_create_for_window(window, OC_GL);
if(oc_surface_is_nil(surface))
{
#if OC_PLATFORM_MACOS
OC_ABORT("Desktop OpenGL surface is not implemented yet on macOS\n");
#else
OC_ABORT("Couldn't create GL surface\n");
#endif
}
//NOTE: init shader and gl state //NOTE: init shader and gl state
mg_surface_prepare(surface); oc_surface_select(surface);
GLuint vao; GLuint vao;
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
@ -101,25 +111,25 @@ int main()
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetProgramInfoLog(program, 256, &size, buffer); glGetProgramInfoLog(program, 256, &size, buffer);
printf("link error: %.*s\n", size, buffer); oc_log_error("link error: %.*s\n", size, buffer);
} }
glUseProgram(program); glUseProgram(program);
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
// mp_window_focus(window); // oc_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -128,7 +138,7 @@ int main()
} }
} }
mg_surface_prepare(surface); oc_surface_select(surface);
glClearColor(0.3, 0.3, 1, 1); glClearColor(0.3, 0.3, 1, 1);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -152,12 +162,12 @@ int main()
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,3 +1,8 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_gles_triangle.exe set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle/include
if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_gles_triangle.exe
cp ../../build/bin/orca.dll bin/
cp ../../ext/angle/bin/libEGL.dll bin/
cp ../../ext/angle/bin/libGLESv2.dll bin/

View File

@ -1,14 +1,22 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext EXTDIR=../../ext
ANGLEDIR=../../ext/angle/
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR/ -I$ANGLEDIR/include"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_gles_triangle main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_gles_triangle main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
cp $ANGLEDIR/bin/libEGL.dylib $BINDIR/
cp $ANGLEDIR/bin/libGLESv2.dylib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_gles_triangle install_name_tool -add_rpath "@executable_path" $BINDIR/example_gles_triangle

View File

@ -13,8 +13,8 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#define MG_INCLUDE_GL_API 1 #define OC_INCLUDE_GL_API 1
#include "milepost.h" #include "orca.h"
unsigned int program; unsigned int program;
@ -43,7 +43,7 @@ void compile_shader(GLuint shader, const char* source)
int err = glGetError(); int err = glGetError();
if(err) if(err)
{ {
printf("gl error: %i\n", err); oc_log_error("gl error: %i\n", err);
} }
int status = 0; int status = 0;
@ -53,20 +53,20 @@ void compile_shader(GLuint shader, const char* source)
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetShaderInfoLog(shader, 256, &size, buffer); glGetShaderInfoLog(shader, 256, &size, buffer);
printf("shader error: %.*s\n", size, buffer); oc_log_error("shader error: %.*s\n", size, buffer);
} }
} }
int main() int main()
{ {
mp_init(); oc_init();
mp_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 }; oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0); oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_GLES); oc_surface surface = oc_surface_create_for_window(window, OC_GLES);
mg_surface_prepare(surface); oc_surface_select(surface);
//NOTE: init shader and gl state //NOTE: init shader and gl state
GLuint vao; GLuint vao;
@ -101,25 +101,24 @@ int main()
char buffer[256]; char buffer[256];
int size = 0; int size = 0;
glGetProgramInfoLog(program, 256, &size, buffer); glGetProgramInfoLog(program, 256, &size, buffer);
printf("link error: %.*s\n", size, buffer); oc_log_error("link error: %.*s\n", size, buffer);
} }
glUseProgram(program); glUseProgram(program);
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
// mp_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
@ -128,8 +127,6 @@ int main()
} }
} }
// mg_surface_prepare(surface);
glClearColor(0.3, 0.3, 1, 1); glClearColor(0.3, 0.3, 1, 1);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -152,14 +149,14 @@ int main()
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(oc_scratch());
} }
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_window_destroy(window); oc_window_destroy(window);
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,17 +1,23 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost -framework Foundation -framework Metal" LIBS="-L$LIBDIR -lorca -framework Foundation -framework Metal"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_metal_triangle main.m
xcrun -sdk macosx metal -c -o shader.air shader.metal xcrun -sdk macosx metal -c -o shader.air shader.metal
xcrun -sdk macosx metallib -o shader.metallib shader.air xcrun -sdk macosx metallib -o shader.metallib shader.air
mv shader.air $BINDIR/
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
cp shader.metallib $BINDIR/triangle_shader.metallib cp shader.metallib $BINDIR/triangle_shader.metallib
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_metal_triangle main.m
install_name_tool -add_rpath "@executable_path" $BINDIR/example_metal_triangle install_name_tool -add_rpath "@executable_path" $BINDIR/example_metal_triangle

View File

@ -12,10 +12,8 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
#include "mtl_surface.h" #include "graphics/mtl_surface.h"
#define LOG_SUBSYSTEM "Main"
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
@ -28,21 +26,19 @@ static const my_vertex triangle[3] = { { { 250, -250 }, { 1, 0, 0, 1 } },
int main() int main()
{ {
LogLevel(LOG_LEVEL_DEBUG); oc_init();
mp_init(); oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
mp_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
mp_window window = mp_window_create(rect, "test", 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_METAL); oc_surface surface = oc_surface_create_for_window(window, OC_METAL);
//NOTE(martin): load the library //NOTE(martin): load the library
id<MTLDevice> device = MTLCreateSystemDefaultDevice(); id<MTLDevice> device = MTLCreateSystemDefaultDevice();
str8 shaderPath = path_executable_relative(mem_scratch(), STR8("triangle_shader.metallib")); oc_str8 shaderPath = oc_path_executable_relative(oc_scratch(), OC_STR8("triangle_shader.metallib"));
const char* shaderPathCString = str8_to_cstring(mem_scratch(), shaderPath); const char* shaderPathCString = oc_str8_to_cstring(oc_scratch(), shaderPath);
NSString* metalFileName = [[NSString alloc] initWithCString:shaderPathCString encoding:NSUTF8StringEncoding]; NSString* metalFileName = [[NSString alloc] initWithCString:shaderPathCString encoding:NSUTF8StringEncoding];
NSError* err = 0; NSError* err = 0;
id<MTLLibrary> library = [device newLibraryWithFile:metalFileName error:&err]; id<MTLLibrary> library = [device newLibraryWithFile:metalFileName error:&err];
@ -61,7 +57,7 @@ int main()
pipelineStateDescriptor.vertexFunction = vertexFunction; pipelineStateDescriptor.vertexFunction = vertexFunction;
pipelineStateDescriptor.fragmentFunction = fragmentFunction; pipelineStateDescriptor.fragmentFunction = fragmentFunction;
CAMetalLayer* layer = mg_mtl_surface_layer(surface); CAMetalLayer* layer = oc_mtl_surface_layer(surface);
pipelineStateDescriptor.colorAttachments[0].pixelFormat = layer.pixelFormat; pipelineStateDescriptor.colorAttachments[0].pixelFormat = layer.pixelFormat;
id<MTLRenderPipelineState> pipelineState = [device newRenderPipelineStateWithDescriptor:pipelineStateDescriptor error:&err]; id<MTLRenderPipelineState> pipelineState = [device newRenderPipelineStateWithDescriptor:pipelineStateDescriptor error:&err];
@ -74,35 +70,37 @@ int main()
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
mp_pump_events(0); oc_pump_events(0);
mp_event event = { 0 }; oc_event* event = 0;
while(mp_next_event(&event)) while((event = oc_next_event(oc_scratch())) != 0)
{ {
switch(event.type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
default: default:
break; break;
} }
oc_arena_clear(oc_scratch());
} }
vector_uint2 viewportSize; vector_uint2 viewportSize;
viewportSize.x = 800; viewportSize.x = 800;
viewportSize.y = 600; viewportSize.y = 600;
mg_surface_prepare(surface); oc_surface_select(surface);
id<CAMetalDrawable> drawable = mg_mtl_surface_drawable(surface); id<CAMetalDrawable> drawable = oc_mtl_surface_drawable(surface);
id<MTLCommandBuffer> commandBuffer = mg_mtl_surface_command_buffer(surface); id<MTLCommandBuffer> commandBuffer = oc_mtl_surface_command_buffer(surface);
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor]; MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
renderPassDescriptor.colorAttachments[0].texture = drawable.texture; renderPassDescriptor.colorAttachments[0].texture = drawable.texture;
@ -118,10 +116,10 @@ int main()
[encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3]; [encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3];
[encoder endEncoding]; [encoder endEncoding];
mg_surface_present(surface); oc_surface_present(surface);
} }
mp_terminate(); oc_terminate();
return (0); return (0);
} }

View File

@ -1,4 +1,6 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_ui.exe if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_ui.exe
cp ../../build/bin/orca.dll bin/

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
BINDIR=../../bin BINDIR=bin
RESDIR=../../resources LIBDIR=../../build/bin
RESDIR=../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost" LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
mkdir -p $BINDIR
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_ui main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_ui main.c
cp $LIBDIR/liborca.dylib $BINDIR/
cp $LIBDIR/mtl_renderer.metallib $BINDIR/
install_name_tool -add_rpath "@executable_path" $BINDIR/example_ui install_name_tool -add_rpath "@executable_path" $BINDIR/example_ui

View File

@ -14,153 +14,153 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h> #include <math.h>
#include "milepost.h" #include "orca.h"
void debug_print_indent(int indent) void debug_print_indent(int indent)
{ {
for(int i = 0; i < indent; i++) for(int i = 0; i < indent; i++)
{ {
printf(" "); oc_log_info(" ");
} }
} }
void debug_print_rule(ui_style_rule* rule) void debug_print_rule(oc_ui_style_rule* rule)
{ {
for_list(&rule->pattern.l, selector, ui_selector, listElt) oc_list_for(&rule->pattern.l, selector, oc_ui_selector, listElt)
{ {
switch(selector->kind) switch(selector->kind)
{ {
case UI_SEL_ANY: case OC_UI_SEL_ANY:
printf("any: "); oc_log_info("any: ");
break; break;
case UI_SEL_OWNER: case OC_UI_SEL_OWNER:
printf("owner: "); oc_log_info("owner: ");
break; break;
case UI_SEL_TEXT: case OC_UI_SEL_TEXT:
printf("text='%.*s': ", (int)selector->text.len, selector->text.ptr); oc_log_info("text='%.*s': ", (int)selector->text.len, selector->text.ptr);
break; break;
case UI_SEL_TAG: case OC_UI_SEL_TAG:
printf("tag=0x%llx: ", selector->tag.hash); oc_log_info("tag=0x%llx: ", selector->tag.hash);
break; break;
case UI_SEL_STATUS: case OC_UI_SEL_STATUS:
{ {
if(selector->status & UI_HOVER) if(selector->status & OC_UI_HOVER)
{ {
printf("hover: "); oc_log_info("hover: ");
} }
if(selector->status & UI_ACTIVE) if(selector->status & OC_UI_ACTIVE)
{ {
printf("active: "); oc_log_info("active: ");
} }
if(selector->status & UI_DRAGGING) if(selector->status & OC_UI_DRAGGING)
{ {
printf("dragging: "); oc_log_info("dragging: ");
} }
} }
break; break;
case UI_SEL_KEY: case OC_UI_SEL_KEY:
printf("key=0x%llx: ", selector->key.hash); oc_log_info("key=0x%llx: ", selector->key.hash);
break; break;
default: default:
printf("unknown: "); oc_log_info("unknown: ");
break; break;
} }
} }
printf("=> font size = %f\n", rule->style->fontSize); oc_log_info("=> font size = %f\n", rule->style->fontSize);
} }
void debug_print_size(ui_box* box, ui_axis axis, int indent) void debug_print_size(oc_ui_box* box, oc_ui_axis axis, int indent)
{ {
debug_print_indent(indent); debug_print_indent(indent);
printf("size %s: ", axis == UI_AXIS_X ? "x" : "y"); oc_log_info("size %s: ", axis == OC_UI_AXIS_X ? "x" : "y");
f32 value = box->targetStyle->size.c[axis].value; f32 value = box->targetStyle->size.c[axis].value;
switch(box->targetStyle->size.c[axis].kind) switch(box->targetStyle->size.c[axis].kind)
{ {
case UI_SIZE_TEXT: case OC_UI_SIZE_TEXT:
printf("text\n"); oc_log_info("text\n");
break; break;
case UI_SIZE_CHILDREN: case OC_UI_SIZE_CHILDREN:
printf("children\n"); oc_log_info("children\n");
break; break;
case UI_SIZE_PARENT: case OC_UI_SIZE_PARENT:
printf("parent: %f\n", value); oc_log_info("parent: %f\n", value);
break; break;
case UI_SIZE_PARENT_MINUS_PIXELS: case OC_UI_SIZE_PARENT_MINUS_PIXELS:
printf("parent minus pixels: %f\n", value); oc_log_info("parent minus pixels: %f\n", value);
break; break;
case UI_SIZE_PIXELS: case OC_UI_SIZE_PIXELS:
printf("pixels: %f\n", value); oc_log_info("pixels: %f\n", value);
break; break;
} }
} }
void debug_print_styles(ui_box* box, int indent) void debug_print_styles(oc_ui_box* box, int indent)
{ {
debug_print_indent(indent); debug_print_indent(indent);
printf("### box '%.*s'\n", (int)box->string.len, box->string.ptr); oc_log_info("### box '%.*s'\n", (int)box->string.len, box->string.ptr);
indent++; indent++;
debug_print_indent(indent); debug_print_indent(indent);
printf("font size: %f\n", box->targetStyle->fontSize); oc_log_info("font size: %f\n", box->targetStyle->fontSize);
debug_print_size(box, UI_AXIS_X, indent); debug_print_size(box, OC_UI_AXIS_X, indent);
debug_print_size(box, UI_AXIS_Y, indent); debug_print_size(box, OC_UI_AXIS_Y, indent);
if(!list_empty(&box->beforeRules)) if(!oc_list_empty(&box->beforeRules))
{ {
debug_print_indent(indent); debug_print_indent(indent);
printf("before rules:\n"); oc_log_info("before rules:\n");
for_list(&box->beforeRules, rule, ui_style_rule, boxElt) oc_list_for(&box->beforeRules, rule, oc_ui_style_rule, boxElt)
{ {
debug_print_indent(indent + 1); debug_print_indent(indent + 1);
debug_print_rule(rule); debug_print_rule(rule);
} }
} }
if(!list_empty(&box->afterRules)) if(!oc_list_empty(&box->afterRules))
{ {
debug_print_indent(indent); debug_print_indent(indent);
printf("after rules:\n"); oc_log_info("after rules:\n");
for_list(&box->afterRules, rule, ui_style_rule, boxElt) oc_list_for(&box->afterRules, rule, oc_ui_style_rule, boxElt)
{ {
debug_print_indent(indent + 1); debug_print_indent(indent + 1);
debug_print_rule(rule); debug_print_rule(rule);
} }
} }
if(!list_empty(&box->children)) if(!oc_list_empty(&box->children))
{ {
debug_print_indent(indent); debug_print_indent(indent);
printf("children:\n"); oc_log_info("children:\n");
indent++; indent++;
for_list(&box->children, child, ui_box, listElt) oc_list_for(&box->children, child, oc_ui_box, listElt)
{ {
debug_print_styles(child, indent); debug_print_styles(child, indent);
} }
} }
} }
mg_font create_font() oc_font create_font()
{ {
//NOTE(martin): create font //NOTE(martin): create font
str8 fontPath = path_executable_relative(mem_scratch(), STR8("../resources/OpenSansLatinSubset.ttf")); oc_str8 fontPath = oc_path_executable_relative(oc_scratch(), OC_STR8("../../resources/OpenSansLatinSubset.ttf"));
char* fontPathCString = str8_to_cstring(mem_scratch(), fontPath); char* fontPathCString = oc_str8_to_cstring(oc_scratch(), fontPath);
FILE* fontFile = fopen(fontPathCString, "r"); FILE* fontFile = fopen(fontPathCString, "r");
if(!fontFile) if(!fontFile)
{ {
log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno)); oc_log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno));
return (mg_font_nil()); return (oc_font_nil());
} }
unsigned char* fontData = 0; unsigned char* fontData = 0;
fseek(fontFile, 0, SEEK_END); fseek(fontFile, 0, SEEK_END);
@ -170,13 +170,13 @@ mg_font create_font()
fread(fontData, 1, fontDataSize, fontFile); fread(fontData, 1, fontDataSize, fontFile);
fclose(fontFile); fclose(fontFile);
unicode_range ranges[5] = { UNICODE_RANGE_BASIC_LATIN, oc_unicode_range ranges[5] = { OC_UNICODE_BASIC_LATIN,
UNICODE_RANGE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT, OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
UNICODE_RANGE_LATIN_EXTENDED_A, OC_UNICODE_LATIN_EXTENDED_A,
UNICODE_RANGE_LATIN_EXTENDED_B, OC_UNICODE_LATIN_EXTENDED_B,
UNICODE_RANGE_SPECIALS }; OC_UNICODE_SPECIALS };
mg_font font = mg_font_create_from_memory(fontDataSize, fontData, 5, ranges); oc_font font = oc_font_create_from_memory(oc_str8_from_buffer(fontDataSize, (char*)fontData), 5, ranges);
free(fontData); free(fontData);
return (font); return (font);
@ -184,84 +184,86 @@ mg_font create_font()
void widget_begin_view(char* str) void widget_begin_view(char* str)
{ {
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_Y, oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_Y,
.layout.spacing = 10, .layout.spacing = 10,
.layout.margin.x = 10, .layout.margin.x = 10,
.layout.margin.y = 10, .layout.margin.y = 10,
.layout.align.x = UI_ALIGN_CENTER, .layout.align.x = OC_UI_ALIGN_CENTER,
.layout.align.y = UI_ALIGN_START }, .layout.align.y = OC_UI_ALIGN_START },
UI_STYLE_LAYOUT); OC_UI_STYLE_LAYOUT);
ui_box_begin(str, UI_FLAG_DRAW_BORDER); oc_ui_box_begin(str, OC_UI_FLAG_DRAW_BORDER);
ui_label(str); oc_ui_label(str);
} }
void widget_end_view(void) void widget_end_view(void)
{ {
ui_box_end(); oc_ui_box_end();
} }
#define widget_view(s) defer_loop(widget_begin_view(s), widget_end_view()) #define widget_view(s) oc_defer_loop(widget_begin_view(s), widget_end_view())
int main() int main()
{ {
mp_init(); oc_init();
mp_clock_init(); //TODO put that in mp_init()? oc_clock_init(); //TODO put that in oc_init()?
ui_context context; oc_ui_context context;
ui_init(&context); oc_ui_init(&context);
ui_set_context(&context); oc_ui_set_context(&context);
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 }; oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
mp_window window = mp_window_create(windowRect, "test", 0); oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
mp_rect contentRect = mp_window_get_content_rect(window); oc_rect contentRect = oc_window_get_content_rect(window);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS); oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
mg_surface_swap_interval(surface, 0); oc_surface_swap_interval(surface, 0);
//TODO: create canvas //TODO: create canvas
mg_canvas canvas = mg_canvas_create(); oc_canvas canvas = oc_canvas_create();
if(mg_canvas_is_nil(canvas)) if(oc_canvas_is_nil(canvas))
{ {
printf("Error: couldn't create canvas\n"); oc_log_error("Error: couldn't create canvas\n");
return (-1); return (-1);
} }
mg_font font = create_font(); oc_font font = create_font();
mem_arena textArena = { 0 }; oc_arena textArena = { 0 };
mem_arena_init(&textArena); oc_arena_init(&textArena);
// start app // start app
mp_window_bring_to_front(window); oc_window_bring_to_front(window);
mp_window_focus(window); oc_window_focus(window);
while(!mp_should_quit()) while(!oc_should_quit())
{ {
oc_arena* scratch = oc_scratch();
bool printDebugStyle = false; bool printDebugStyle = false;
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
mp_pump_events(0); oc_pump_events(0);
mp_event* event = 0; oc_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0) while((event = oc_next_event(scratch)) != 0)
{ {
ui_process_event(event); oc_ui_process_event(event);
switch(event->type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case OC_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); oc_request_quit();
} }
break; break;
case MP_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
if(event->key.action == MP_KEY_PRESS && event->key.code == MP_KEY_P) if(event->key.action == OC_KEY_PRESS && event->key.code == OC_KEY_P)
{ {
printDebugStyle = true; printDebugStyle = true;
} }
@ -274,177 +276,188 @@ int main()
} }
//TEST UI //TEST UI
ui_style defaultStyle = { .bgColor = { 0 }, oc_ui_style defaultStyle = { .bgColor = { 0 },
.color = { 1, 1, 1, 1 }, .color = { 1, 1, 1, 1 },
.font = font, .font = font,
.fontSize = 16, .fontSize = 16,
.borderColor = { 1, 0, 0, 1 }, .borderColor = { 1, 0, 0, 1 },
.borderSize = 2 }; .borderSize = 2 };
ui_style_mask defaultMask = UI_STYLE_BG_COLOR oc_ui_style_mask defaultMask = OC_UI_STYLE_BG_COLOR
| UI_STYLE_COLOR | OC_UI_STYLE_COLOR
| UI_STYLE_BORDER_COLOR | OC_UI_STYLE_BORDER_COLOR
| UI_STYLE_BORDER_SIZE | OC_UI_STYLE_BORDER_SIZE
| UI_STYLE_FONT | OC_UI_STYLE_FONT
| UI_STYLE_FONT_SIZE; | OC_UI_STYLE_FONT_SIZE;
ui_flags debugFlags = UI_FLAG_DRAW_BORDER; oc_ui_flags debugFlags = OC_UI_FLAG_DRAW_BORDER;
ui_box* root = 0; oc_ui_box* root = 0;
mp_rect frameRect = mg_surface_get_frame(surface); oc_vec2 frameSize = oc_surface_get_size(surface);
vec2 frameSize = { frameRect.w, frameRect.h };
ui_frame(frameSize, &defaultStyle, defaultMask) oc_ui_frame(frameSize, &defaultStyle, defaultMask)
{ {
root = ui_box_top(); root = oc_ui_box_top();
ui_style_match_before(ui_pattern_all(), &defaultStyle, defaultMask); oc_ui_style_match_before(oc_ui_pattern_all(), &defaultStyle, defaultMask);
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 1 }, .size.height = { OC_UI_SIZE_PARENT, 1 },
.layout.axis = UI_AXIS_Y, .layout.axis = OC_UI_AXIS_Y,
.layout.align.x = UI_ALIGN_CENTER, .layout.align.x = OC_UI_ALIGN_CENTER,
.layout.align.y = UI_ALIGN_START, .layout.align.y = OC_UI_ALIGN_START,
.layout.spacing = 10, .layout.spacing = 10,
.layout.margin.x = 10, .layout.margin.x = 10,
.layout.margin.y = 10, .layout.margin.y = 10,
.bgColor = { 0.11, 0.11, 0.11, 1 } }, .bgColor = { 0.11, 0.11, 0.11, 1 } },
UI_STYLE_SIZE OC_UI_STYLE_SIZE
| UI_STYLE_LAYOUT | OC_UI_STYLE_LAYOUT
| UI_STYLE_BG_COLOR); | OC_UI_STYLE_BG_COLOR);
ui_container("background", UI_FLAG_DRAW_BACKGROUND) oc_ui_container("background", OC_UI_FLAG_DRAW_BACKGROUND)
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_CHILDREN }, .size.height = { OC_UI_SIZE_CHILDREN },
.layout.align.x = UI_ALIGN_CENTER }, .layout.align.x = OC_UI_ALIGN_CENTER },
UI_STYLE_SIZE OC_UI_STYLE_SIZE
| UI_STYLE_LAYOUT_ALIGN_X); | OC_UI_STYLE_LAYOUT_ALIGN_X);
ui_container("title", debugFlags) oc_ui_container("title", debugFlags)
{ {
ui_style_next(&(ui_style){ .fontSize = 26 }, UI_STYLE_FONT_SIZE); oc_ui_style_next(&(oc_ui_style){ .fontSize = 26 }, OC_UI_STYLE_FONT_SIZE);
ui_label("Milepost UI Demo"); oc_ui_label("Orca UI Demo");
if(ui_box_sig(ui_box_top()).hovering) if(oc_ui_box_sig(oc_ui_box_top()).hovering)
{ {
ui_tooltip("tooltip") oc_ui_tooltip("tooltip")
{ {
ui_style_next(&(ui_style){ .bgColor = { 1, 0.99, 0.82, 1 } }, oc_ui_style_next(&(oc_ui_style){ .bgColor = { 1, 0.99, 0.82, 1 } },
UI_STYLE_BG_COLOR); OC_UI_STYLE_BG_COLOR);
ui_container("background", UI_FLAG_DRAW_BACKGROUND) oc_ui_container("background", OC_UI_FLAG_DRAW_BACKGROUND)
{ {
ui_style_next(&(ui_style){ .color = { 0, 0, 0, 1 } }, oc_ui_style_next(&(oc_ui_style){ .color = { 0, 0, 0, 1 } },
UI_STYLE_COLOR); OC_UI_STYLE_COLOR);
ui_label("That is a tooltip!"); oc_ui_label("That is a tooltip!");
} }
} }
} }
} }
ui_menu_bar("Menu bar") oc_ui_menu_bar("Menu bar")
{ {
ui_menu("Menu 1") oc_ui_menu("Menu 1")
{ {
if(ui_menu_button("Option 1.1").pressed) if(oc_ui_menu_button("Option 1.1").pressed)
{ {
printf("Pressed option 1.1\n"); oc_log_info("Pressed option 1.1\n");
} }
ui_menu_button("Option 1.2"); oc_ui_menu_button("Option 1.2");
ui_menu_button("Option 1.3"); oc_ui_menu_button("Option 1.3");
ui_menu_button("Option 1.4"); oc_ui_menu_button("Option 1.4");
} }
ui_menu("Menu 2") oc_ui_menu("Menu 2")
{ {
ui_menu_button("Option 2.1"); oc_ui_menu_button("Option 2.1");
ui_menu_button("Option 2.2"); oc_ui_menu_button("Option 2.2");
ui_menu_button("Option 2.3"); oc_ui_menu_button("Option 2.3");
ui_menu_button("Option 2.4"); oc_ui_menu_button("Option 2.4");
} }
ui_menu("Menu 3") oc_ui_menu("Menu 3")
{ {
ui_menu_button("Option 3.1"); oc_ui_menu_button("Option 3.1");
ui_menu_button("Option 3.2"); oc_ui_menu_button("Option 3.2");
ui_menu_button("Option 3.3"); oc_ui_menu_button("Option 3.3");
ui_menu_button("Option 3.4"); oc_ui_menu_button("Option 3.4");
} }
} }
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 1, 1 } }, .size.height = { OC_UI_SIZE_PARENT, 1, 1 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_X }, UI_STYLE_LAYOUT_AXIS); oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X }, OC_UI_STYLE_LAYOUT_AXIS);
ui_container("contents", debugFlags) oc_ui_container("contents", debugFlags)
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 0.5 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
.size.height = { UI_SIZE_PARENT, 1 }, .size.height = { OC_UI_SIZE_PARENT, 1 },
.borderColor = { 0, 0, 1, 1 } }, .borderColor = { 0, 0, 1, 1 } },
UI_STYLE_SIZE OC_UI_STYLE_SIZE
| UI_STYLE_BORDER_COLOR); | OC_UI_STYLE_BORDER_COLOR);
ui_container("left", debugFlags) oc_ui_container("left", debugFlags)
{ {
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_X, oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
.layout.spacing = 10, .layout.spacing = 10,
.layout.margin.x = 10, .layout.margin.x = 10,
.layout.margin.y = 10, .layout.margin.y = 10,
.size.width = { UI_SIZE_PARENT, 1 }, .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 0.5 } }, .size.height = { OC_UI_SIZE_PARENT, 0.5 } },
UI_STYLE_LAYOUT_AXIS OC_UI_STYLE_LAYOUT_AXIS
| UI_STYLE_LAYOUT_SPACING | OC_UI_STYLE_LAYOUT_SPACING
| UI_STYLE_LAYOUT_MARGIN_X | OC_UI_STYLE_LAYOUT_MARGIN_X
| UI_STYLE_LAYOUT_MARGIN_Y | OC_UI_STYLE_LAYOUT_MARGIN_Y
| UI_STYLE_SIZE); | OC_UI_STYLE_SIZE);
ui_container("up", debugFlags) oc_ui_container("up", debugFlags)
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 0.5 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
.size.height = { UI_SIZE_PARENT, 1 } }, .size.height = { OC_UI_SIZE_PARENT, 1 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
widget_view("Buttons") widget_view("Buttons")
{ {
if(ui_button("Test Dialog").clicked) if(oc_ui_button("Test Dialog").clicked)
{ {
char* options[] = { "Accept", "Reject" }; static oc_str8 options_strings[] = {
int res = mp_alert_popup("test dialog", "dialog message", 2, options); OC_STR8_LIT("Accept"),
OC_STR8_LIT("Reject"),
};
oc_str8_list options = { 0 };
oc_str8_list_push(scratch, &options, options_strings[0]);
oc_str8_list_push(scratch, &options, options_strings[1]);
int res = oc_alert_popup(OC_STR8("test dialog"), OC_STR8("dialog message"), options);
if(res >= 0) if(res >= 0)
{ {
printf("selected options %i: %s\n", res, options[res]); oc_log_info("selected options %i: %s\n", res, options_strings[res].ptr);
} }
else else
{ {
printf("no options selected\n"); oc_log_info("no options selected\n");
} }
} }
if(ui_button("Open").clicked) if(oc_ui_button("Open").clicked)
{ {
char* filters[] = { "md" }; oc_str8_list filters = { 0 };
str8 file = mp_open_dialog(mem_scratch(), "Open File", "C:\\Users", 1, filters, false); oc_str8_list_push(scratch, &filters, OC_STR8("md"));
printf("selected file %.*s\n", (int)file.len, file.ptr);
oc_str8 file = oc_open_dialog(scratch, OC_STR8("Open File"), OC_STR8("C:\\Users"), filters, false);
oc_log_info("selected file %.*s\n", (int)file.len, file.ptr);
} }
if(ui_button("Save").clicked) if(oc_ui_button("Save").clicked)
{ {
str8 file = mp_save_dialog(mem_scratch(), "Save File", "C:\\Users", 0, 0); oc_str8_list filters = { 0 };
printf("selected file %.*s\n", (int)file.len, file.ptr);
oc_str8 file = oc_save_dialog(scratch, OC_STR8("Save File"), OC_STR8("C:\\Users"), filters);
oc_log_info("selected file %.*s\n", (int)file.len, file.ptr);
} }
} }
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 0.5 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
.size.height = { UI_SIZE_PARENT, 1 } }, .size.height = { OC_UI_SIZE_PARENT, 1 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
ui_pattern pattern = { 0 }; oc_ui_pattern pattern = { 0 };
ui_pattern_push(mem_scratch(), &pattern, (ui_selector){ .kind = UI_SEL_TAG, .tag = ui_tag_make("checkbox") }); oc_ui_pattern_push(scratch, &pattern, (oc_ui_selector){ .kind = OC_UI_SEL_TAG, .tag = oc_ui_tag_make("checkbox") });
ui_style_match_after(pattern, oc_ui_style_match_after(pattern,
&(ui_style){ .bgColor = { 0, 1, 0, 1 }, &(oc_ui_style){ .bgColor = { 0, 1, 0, 1 },
.color = { 1, 1, 1, 1 } }, .color = { 1, 1, 1, 1 } },
UI_STYLE_COLOR | UI_STYLE_BG_COLOR); OC_UI_STYLE_COLOR | OC_UI_STYLE_BG_COLOR);
widget_view("checkboxes") widget_view("checkboxes")
{ {
@ -452,156 +465,156 @@ int main()
static bool check2 = false; static bool check2 = false;
static bool check3 = false; static bool check3 = false;
ui_checkbox("check1", &check1); oc_ui_checkbox("check1", &check1);
ui_checkbox("check2", &check2); oc_ui_checkbox("check2", &check2);
ui_checkbox("check3", &check3); oc_ui_checkbox("check3", &check3);
} }
} }
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_X, oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
.size.width = { UI_SIZE_PARENT, 1 }, .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 0.5 } }, .size.height = { OC_UI_SIZE_PARENT, 0.5 } },
UI_STYLE_LAYOUT_AXIS OC_UI_STYLE_LAYOUT_AXIS
| UI_STYLE_SIZE); | OC_UI_STYLE_SIZE);
ui_container("down", debugFlags) oc_ui_container("down", debugFlags)
{ {
widget_view("Vertical Sliders") widget_view("Vertical Sliders")
{ {
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_X, oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
.layout.spacing = 10 }, .layout.spacing = 10 },
UI_STYLE_LAYOUT_AXIS OC_UI_STYLE_LAYOUT_AXIS
| UI_STYLE_LAYOUT_SPACING); | OC_UI_STYLE_LAYOUT_SPACING);
ui_container("contents", 0) oc_ui_container("contents", 0)
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 20 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 20 },
.size.height = { UI_SIZE_PIXELS, 200 } }, .size.height = { OC_UI_SIZE_PIXELS, 200 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static f32 slider1 = 0; static f32 slider1 = 0;
ui_slider("slider1", 0.2, &slider1); oc_ui_slider("slider1", 0.2, &slider1);
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 20 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 20 },
.size.height = { UI_SIZE_PIXELS, 200 } }, .size.height = { OC_UI_SIZE_PIXELS, 200 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static f32 slider2 = 0; static f32 slider2 = 0;
ui_slider("slider2", 0.2, &slider2); oc_ui_slider("slider2", 0.2, &slider2);
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 20 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 20 },
.size.height = { UI_SIZE_PIXELS, 200 } }, .size.height = { OC_UI_SIZE_PIXELS, 200 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static f32 slider3 = 0; static f32 slider3 = 0;
ui_slider("slider3", 0.2, &slider3); oc_ui_slider("slider3", 0.2, &slider3);
} }
} }
widget_view("Horizontal Sliders") widget_view("Horizontal Sliders")
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 200 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 200 },
.size.height = { UI_SIZE_PIXELS, 20 } }, .size.height = { OC_UI_SIZE_PIXELS, 20 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static f32 slider1 = 0; static f32 slider1 = 0;
ui_slider("slider1", 0.2, &slider1); oc_ui_slider("slider1", 0.2, &slider1);
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 200 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 200 },
.size.height = { UI_SIZE_PIXELS, 20 } }, .size.height = { OC_UI_SIZE_PIXELS, 20 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static f32 slider2 = 0; static f32 slider2 = 0;
ui_slider("slider2", 0.2, &slider2); oc_ui_slider("slider2", 0.2, &slider2);
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 200 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 200 },
.size.height = { UI_SIZE_PIXELS, 20 } }, .size.height = { OC_UI_SIZE_PIXELS, 20 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static f32 slider3 = 0; static f32 slider3 = 0;
ui_slider("slider3", 0.2, &slider3); oc_ui_slider("slider3", 0.2, &slider3);
} }
} }
} }
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 0.5 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
.size.height = { UI_SIZE_PARENT, 1 } }, .size.height = { OC_UI_SIZE_PARENT, 1 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
ui_container("right", debugFlags) oc_ui_container("right", debugFlags)
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 0.33 } }, .size.height = { OC_UI_SIZE_PARENT, 0.33 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
widget_view("Text box") widget_view("Text box")
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PIXELS, 300 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 300 },
.size.height = { UI_SIZE_TEXT } }, .size.height = { OC_UI_SIZE_TEXT } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
static str8 text = { 0 }; static oc_str8 text = { 0 };
ui_text_box_result res = ui_text_box("textbox", mem_scratch(), text); oc_ui_text_box_result res = oc_ui_text_box("textbox", oc_scratch(), text);
if(res.changed) if(res.changed)
{ {
mem_arena_clear(&textArena); oc_arena_clear(&textArena);
text = str8_push_copy(&textArena, res.text); text = oc_str8_push_copy(&textArena, res.text);
} }
} }
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 0.33 } }, .size.height = { OC_UI_SIZE_PARENT, 0.33 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
widget_view("Test") widget_view("Test")
{ {
ui_pattern pattern = { 0 }; oc_ui_pattern pattern = { 0 };
ui_pattern_push(mem_scratch(), &pattern, (ui_selector){ .kind = UI_SEL_TEXT, .text = STR8("panel") }); oc_ui_pattern_push(oc_scratch(), &pattern, (oc_ui_selector){ .kind = OC_UI_SEL_TEXT, .text = OC_STR8("panel") });
ui_style_match_after(pattern, &(ui_style){ .bgColor = { 0.3, 0.3, 1, 1 } }, UI_STYLE_BG_COLOR); oc_ui_style_match_after(pattern, &(oc_ui_style){ .bgColor = { 0.3, 0.3, 1, 1 } }, OC_UI_STYLE_BG_COLOR);
static int selected = 0; static int selected = 0;
str8 options[] = { STR8("option 1"), oc_str8 options[] = { OC_STR8("option 1"),
STR8("option 2"), OC_STR8("option 2"),
STR8("long option 3"), OC_STR8("long option 3"),
STR8("option 4"), OC_STR8("option 4"),
STR8("option 5") }; OC_STR8("option 5") };
ui_select_popup_info info = { .selectedIndex = selected, oc_ui_select_popup_info info = { .selectedIndex = selected,
.optionCount = 5, .optionCount = 5,
.options = options }; .options = options };
ui_select_popup_info result = ui_select_popup("popup", &info); oc_ui_select_popup_info result = oc_ui_select_popup("popup", &info);
selected = result.selectedIndex; selected = result.selectedIndex;
} }
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 0.33 } }, .size.height = { OC_UI_SIZE_PARENT, 0.33 } },
UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
widget_view("Color") widget_view("Color")
{ {
ui_style_next(&(ui_style){ .size.width = { UI_SIZE_PARENT, 1 }, oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
.size.height = { UI_SIZE_PARENT, 0.7 }, .size.height = { OC_UI_SIZE_PARENT, 0.7 },
.layout.axis = UI_AXIS_X }, .layout.axis = OC_UI_AXIS_X },
UI_STYLE_SIZE OC_UI_STYLE_SIZE
| UI_STYLE_LAYOUT_AXIS); | OC_UI_STYLE_LAYOUT_AXIS);
ui_panel("Panel", UI_FLAG_DRAW_BORDER) oc_ui_panel("Panel", OC_UI_FLAG_DRAW_BORDER)
{ {
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_X }, oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X },
UI_STYLE_LAYOUT_AXIS); OC_UI_STYLE_LAYOUT_AXIS);
ui_container("contents", 0) oc_ui_container("contents", 0)
{ {
ui_style_next(&(ui_style){ .layout.spacing = 20 }, oc_ui_style_next(&(oc_ui_style){ .layout.spacing = 20 },
UI_STYLE_LAYOUT_SPACING); OC_UI_STYLE_LAYOUT_SPACING);
ui_container("buttons", 0) oc_ui_container("buttons", 0)
{ {
ui_button("Button A"); oc_ui_button("Button A");
ui_button("Button B"); oc_ui_button("Button B");
ui_button("Button C"); oc_ui_button("Button C");
ui_button("Button D"); oc_ui_button("Button D");
} }
ui_style_next(&(ui_style){ .layout.axis = UI_AXIS_X, oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
.layout.spacing = 20 }, .layout.spacing = 20 },
UI_STYLE_LAYOUT_SPACING OC_UI_STYLE_LAYOUT_SPACING
| UI_STYLE_LAYOUT_AXIS); | OC_UI_STYLE_LAYOUT_AXIS);
ui_container("buttons2", 0) oc_ui_container("buttons2", 0)
{ {
ui_button("Button A"); oc_ui_button("Button A");
ui_button("Button B"); oc_ui_button("Button B");
ui_button("Button C"); oc_ui_button("Button C");
ui_button("Button D"); oc_ui_button("Button D");
} }
} }
} }
@ -615,18 +628,18 @@ int main()
debug_print_styles(root, 0); debug_print_styles(root, 0);
} }
mg_surface_prepare(surface); oc_surface_select(surface);
ui_draw(); oc_ui_draw();
mg_render(surface, canvas); oc_render(surface, canvas);
mg_surface_present(surface); oc_surface_present(surface);
mem_arena_clear(mem_scratch()); oc_arena_clear(scratch);
} }
mg_surface_destroy(surface); oc_surface_destroy(surface);
mp_terminate(); oc_terminate();
return (0); return (0);
} }