2023-02-27 14:43:41 +00:00
|
|
|
/************************************************************//**
|
|
|
|
*
|
|
|
|
* @file: main.cpp
|
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 30/07/2022
|
|
|
|
* @revision:
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
2023-07-04 13:59:45 +00:00
|
|
|
#include<stdio.h>
|
2023-02-27 14:43:41 +00:00
|
|
|
#include<stdlib.h>
|
|
|
|
#include<string.h>
|
|
|
|
#include<errno.h>
|
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
|
|
|
#include<math.h>
|
|
|
|
|
|
|
|
#include"milepost.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
mp_init();
|
|
|
|
mp_clock_init(); //TODO put that in mp_init()?
|
|
|
|
|
|
|
|
mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610};
|
|
|
|
mp_window window = mp_window_create(windowRect, "test", 0);
|
|
|
|
|
|
|
|
mp_rect contentRect = mp_window_get_content_rect(window);
|
|
|
|
|
|
|
|
//NOTE: create surface
|
2023-05-08 11:01:45 +00:00
|
|
|
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS);
|
2023-07-04 13:59:45 +00:00
|
|
|
if(mg_surface_is_nil(surface))
|
|
|
|
{
|
|
|
|
log_error("couldn't create surface\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
2023-02-27 14:43:41 +00:00
|
|
|
mg_surface_swap_interval(surface, 0);
|
|
|
|
|
|
|
|
//NOTE: create canvas
|
2023-05-08 11:01:45 +00:00
|
|
|
mg_canvas canvas = mg_canvas_create();
|
2023-02-27 14:43:41 +00:00
|
|
|
if(mg_canvas_is_nil(canvas))
|
|
|
|
{
|
|
|
|
printf("Error: couldn't create canvas\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:54:39 +00:00
|
|
|
//NOTE: create image
|
2023-08-09 17:04:59 +00:00
|
|
|
str8 imagePath = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/triceratops.png"));
|
2023-05-08 11:01:45 +00:00
|
|
|
mg_image image = mg_image_create_from_file(surface, imagePath, false);
|
2023-02-28 15:54:39 +00:00
|
|
|
vec2 imageSize = mg_image_size(image);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-08-09 17:04:59 +00:00
|
|
|
str8 imagePath2 = path_executable_relative(mem_scratch(), STR8("../../sketches/resources/Top512.png"));
|
2023-05-08 11:01:45 +00:00
|
|
|
mg_image image2 = mg_image_create_from_file(surface, imagePath2, false);
|
2023-02-28 15:54:39 +00:00
|
|
|
vec2 imageSize2 = mg_image_size(image2);
|
2023-02-27 14:43:41 +00:00
|
|
|
|
|
|
|
// start app
|
|
|
|
mp_window_bring_to_front(window);
|
|
|
|
mp_window_focus(window);
|
|
|
|
|
|
|
|
while(!mp_should_quit())
|
|
|
|
{
|
|
|
|
mp_pump_events(0);
|
2023-05-08 11:01:45 +00:00
|
|
|
mp_event* event = 0;
|
|
|
|
while((event = mp_next_event(mem_scratch())) != 0)
|
2023-02-27 14:43:41 +00:00
|
|
|
{
|
2023-05-08 11:01:45 +00:00
|
|
|
switch(event->type)
|
2023-02-27 14:43:41 +00:00
|
|
|
{
|
|
|
|
case MP_EVENT_WINDOW_CLOSE:
|
|
|
|
{
|
|
|
|
mp_request_quit();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mg_surface_prepare(surface);
|
|
|
|
|
|
|
|
mg_set_color_rgba(0, 1, 1, 1);
|
|
|
|
mg_clear();
|
|
|
|
|
|
|
|
mg_set_color_rgba(1, 1, 1, 1);
|
2023-07-04 15:24:41 +00:00
|
|
|
/*
|
2023-02-27 14:43:41 +00:00
|
|
|
mg_matrix_push((mg_mat2x3){0.707, -0.707, 200,
|
|
|
|
0.707, 0.707, 100});
|
2023-02-28 15:54:39 +00:00
|
|
|
mg_set_image(image);
|
|
|
|
mg_set_image_source_region((mp_rect){500, 500, 2000, 1400});
|
2023-02-27 14:43:41 +00:00
|
|
|
|
|
|
|
mg_move_to(0, 0);
|
|
|
|
mg_line_to(200, 0);
|
|
|
|
mg_line_to(300, 100);
|
|
|
|
mg_line_to(200, 200);
|
|
|
|
mg_line_to(0, 200);
|
|
|
|
mg_line_to(100, 100);
|
2023-04-09 17:24:32 +00:00
|
|
|
mg_close_path();
|
2023-02-27 14:43:41 +00:00
|
|
|
mg_fill();
|
|
|
|
|
|
|
|
mg_matrix_pop();
|
|
|
|
|
2023-02-28 15:54:39 +00:00
|
|
|
mg_image_draw(image2, (mp_rect){300, 200, 300, 300});
|
2023-07-04 15:24:41 +00:00
|
|
|
*/
|
|
|
|
mg_image_draw(image, (mp_rect){100, 100, 300, 300});
|
|
|
|
mg_image_draw(image2, (mp_rect){300, 200, 300, 300});
|
2023-02-27 14:43:41 +00:00
|
|
|
|
2023-07-02 10:49:45 +00:00
|
|
|
|
|
|
|
|
2023-05-08 11:01:45 +00:00
|
|
|
mg_render(surface, canvas);
|
2023-02-27 14:43:41 +00:00
|
|
|
mg_surface_present(surface);
|
|
|
|
|
|
|
|
mem_arena_clear(mem_scratch());
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:54:39 +00:00
|
|
|
mg_image_destroy(image);
|
2023-02-27 14:43:41 +00:00
|
|
|
mg_canvas_destroy(canvas);
|
|
|
|
mg_surface_destroy(surface);
|
|
|
|
mp_window_destroy(window);
|
|
|
|
|
|
|
|
mp_terminate();
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|