merge io into image
This commit is contained in:
parent
bfc81fd062
commit
33dd2214a8
|
@ -33,6 +33,12 @@ bool rightDown = false;
|
|||
mg_canvas canvas;
|
||||
mg_surface surface;
|
||||
|
||||
#define TEST_IMAGE 1
|
||||
|
||||
#ifdef TEST_IMAGE
|
||||
mg_image image;
|
||||
#endif
|
||||
|
||||
mg_surface mg_surface_main(void);
|
||||
|
||||
void OnInit(void)
|
||||
|
@ -41,13 +47,44 @@ void OnInit(void)
|
|||
surface = mg_surface_main();
|
||||
canvas = mg_canvas_create();
|
||||
|
||||
file_handle file = file_open(STR8("/test_write.txt") , IO_OPEN_CREATE | IO_OPEN_WRITE);
|
||||
#ifdef TEST_IMAGE
|
||||
// create an image with a checkerboard pattern
|
||||
u8 pixels[11*11*4];
|
||||
for(int i=0; i<11*11/2; i++)
|
||||
{
|
||||
pixels[8*i] = 0;
|
||||
pixels[8*i+1] = 0;
|
||||
pixels[8*i+2] = 0;
|
||||
pixels[8*i+3] = 255;
|
||||
pixels[8*i+4] = 255;
|
||||
pixels[8*i+5] = 255;
|
||||
pixels[8*i+6] = 255;
|
||||
pixels[8*i+7] = 255;
|
||||
}
|
||||
image = mg_image_create_from_rgba8(surface, 11, 11, pixels);
|
||||
|
||||
/*TODO Once we have file io and stb_image:
|
||||
|
||||
file_handle file = file_open(STR8("test.png"), FILE_OPEN_READ);
|
||||
u64 size = file_size(file);
|
||||
u8* data = mem_arena_alloc_array(mem_scratch(), u8, size);
|
||||
file_read(file, size, data);
|
||||
file_close(file);
|
||||
|
||||
image = mg_image_create_from_data(surface, size, data); // --> that will call stbi_load_from_memory(), see milepost/src/graphics_common.c
|
||||
|
||||
mem_arena_clear(mem_scratch());
|
||||
*/
|
||||
#endif // TEST_IMAGE
|
||||
|
||||
//NOTE: testing file io
|
||||
file_handle file = file_open(STR8("/test_write.txt"), IO_OPEN_CREATE | IO_OPEN_WRITE);
|
||||
|
||||
str8 string = STR8("Hello, file!\n");
|
||||
file_write(file, string.len, string.ptr);
|
||||
file_close(file);
|
||||
|
||||
file = file_open(STR8("/dir1/test_read.txt") , IO_OPEN_READ);
|
||||
file = file_open(STR8("/dir1/test_read.txt"), IO_OPEN_READ);
|
||||
u64 size = file_size(file);
|
||||
char* buffer = mem_arena_alloc(mem_scratch(), size);
|
||||
file_read(file, size, buffer);
|
||||
|
@ -172,8 +209,12 @@ void OnFrameRefresh(void)
|
|||
mg_set_color(paddleColor);
|
||||
mg_rectangle_fill(paddle.x, paddle.y, paddle.w, paddle.h);
|
||||
|
||||
#ifdef TEST_IMAGE
|
||||
mg_image_draw(image, ball);
|
||||
#else
|
||||
mg_set_color(ballColor);
|
||||
mg_circle_fill(ball.x+ball.w/2, ball.y + ball.w/2, ball.w/2.);
|
||||
#endif
|
||||
|
||||
mg_matrix_pop();
|
||||
|
||||
|
|
Loading…
Reference in New Issue