2023-08-19 12:49:23 +00:00
|
|
|
/************************************************************/ /**
|
2023-02-27 14:43:41 +00:00
|
|
|
*
|
|
|
|
* @file: main.cpp
|
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 30/07/2022
|
|
|
|
* @revision:
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
2023-08-19 12:49:23 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2023-02-27 14:43:41 +00:00
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
2023-08-19 12:49:23 +00:00
|
|
|
#include <math.h>
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
#include "milepost.h"
|
2023-02-27 14:43:41 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2023-08-19 12:49:23 +00:00
|
|
|
mp_init();
|
|
|
|
mp_clock_init(); //TODO put that in mp_init()?
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mp_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
|
|
|
|
mp_window window = mp_window_create(windowRect, "test", 0);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mp_rect contentRect = mp_window_get_content_rect(window);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
//NOTE: create surface
|
|
|
|
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS);
|
|
|
|
if(mg_surface_is_nil(surface))
|
|
|
|
{
|
|
|
|
log_error("couldn't create surface\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
mg_surface_swap_interval(surface, 0);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
//NOTE: create canvas
|
|
|
|
mg_canvas canvas = mg_canvas_create();
|
|
|
|
if(mg_canvas_is_nil(canvas))
|
|
|
|
{
|
|
|
|
log_error("Error: couldn't create canvas\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
//NOTE: create atlas
|
|
|
|
mem_arena permanentArena = { 0 };
|
|
|
|
mem_arena_init(&permanentArena);
|
2023-02-28 15:54:39 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_rect_atlas* atlas = mg_rect_atlas_create(&permanentArena, 16000, 16000);
|
|
|
|
mg_image atlasImage = mg_image_create(surface, 16000, 16000);
|
2023-02-28 15:54:39 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
str8 path1 = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/triceratops.png"));
|
|
|
|
str8 path2 = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/Top512.png"));
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_image_region image1 = mg_image_atlas_alloc_from_file(atlas, atlasImage, path1, false);
|
|
|
|
mg_image_region image2 = mg_image_atlas_alloc_from_file(atlas, atlasImage, path2, false);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
// start app
|
|
|
|
mp_window_bring_to_front(window);
|
|
|
|
mp_window_focus(window);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
while(!mp_should_quit())
|
|
|
|
{
|
|
|
|
mp_pump_events(0);
|
|
|
|
mp_event* event = 0;
|
|
|
|
while((event = mp_next_event(mem_scratch())) != 0)
|
|
|
|
{
|
|
|
|
switch(event->type)
|
|
|
|
{
|
|
|
|
case MP_EVENT_WINDOW_CLOSE:
|
|
|
|
{
|
|
|
|
mp_request_quit();
|
|
|
|
}
|
|
|
|
break;
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_surface_prepare(surface);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_set_color_rgba(0, 1, 1, 1);
|
|
|
|
mg_clear();
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_set_color_rgba(1, 1, 1, 1);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_image_draw_region(image1.image, image1.rect, (mp_rect){ 100, 100, 300, 300 });
|
|
|
|
mg_image_draw_region(image2.image, image2.rect, (mp_rect){ 300, 200, 300, 300 });
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_render(surface, canvas);
|
|
|
|
mg_surface_present(surface);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mem_arena_clear(mem_scratch());
|
|
|
|
}
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_image_atlas_recycle(atlas, image1);
|
|
|
|
mg_image_atlas_recycle(atlas, image2);
|
2023-02-28 15:54:39 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mg_canvas_destroy(canvas);
|
|
|
|
mg_surface_destroy(surface);
|
|
|
|
mp_window_destroy(window);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
mp_terminate();
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
return (0);
|
2023-02-27 14:43:41 +00:00
|
|
|
}
|