2020-03-06 06:06:54 +00:00
|
|
|
#include <MiniFB.h>
|
|
|
|
#include <stdio.h>
|
2020-09-15 09:35:11 +00:00
|
|
|
#include <stdlib.h>
|
2020-03-06 06:06:54 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-09-15 09:35:11 +00:00
|
|
|
static uint32_t g_width = 800;
|
|
|
|
static uint32_t g_height = 600;
|
|
|
|
static uint32_t *g_buffer = 0x0;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
resize(struct mfb_window *window, int width, int height) {
|
2020-09-16 11:32:27 +00:00
|
|
|
(void) window;
|
2020-09-15 09:35:11 +00:00
|
|
|
g_width = width;
|
|
|
|
g_height = height;
|
|
|
|
g_buffer = realloc(g_buffer, g_width * g_height * 4);
|
|
|
|
}
|
2020-03-06 06:06:54 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2020-09-15 09:35:11 +00:00
|
|
|
uint32_t i, noise, carry, seed = 0xbeef;
|
2020-03-06 06:06:54 +00:00
|
|
|
|
2020-09-15 09:35:11 +00:00
|
|
|
struct mfb_window *window = mfb_open_ex("Noise Test", g_width, g_height, WF_RESIZABLE);
|
2020-03-06 06:06:54 +00:00
|
|
|
if (!window)
|
|
|
|
return 0;
|
|
|
|
|
2020-09-15 09:35:11 +00:00
|
|
|
g_buffer = (uint32_t *) malloc(g_width * g_height * 4);
|
|
|
|
mfb_set_resize_callback(window, resize);
|
|
|
|
|
2020-09-16 09:38:05 +00:00
|
|
|
mfb_set_viewport(window, 50, 50, g_width - 50 - 50, g_height - 50 - 50);
|
|
|
|
resize(window, g_width - 100, g_height - 100); // to resize buffer
|
|
|
|
|
2020-04-25 21:16:35 +00:00
|
|
|
mfb_update_state state;
|
2020-04-22 11:00:15 +00:00
|
|
|
do {
|
2020-09-15 09:35:11 +00:00
|
|
|
for (i = 0; i < g_width * g_height; ++i) {
|
2020-03-06 06:06:54 +00:00
|
|
|
noise = seed;
|
|
|
|
noise >>= 3;
|
|
|
|
noise ^= seed;
|
|
|
|
carry = noise & 1;
|
|
|
|
noise >>= 1;
|
|
|
|
seed >>= 1;
|
|
|
|
seed |= (carry << 30);
|
|
|
|
noise &= 0xFF;
|
|
|
|
g_buffer[i] = MFB_RGB(noise, noise, noise);
|
|
|
|
}
|
|
|
|
|
2020-09-15 09:35:11 +00:00
|
|
|
state = mfb_update_ex(window, g_buffer, g_width, g_height);
|
2020-03-06 06:06:54 +00:00
|
|
|
if (state != STATE_OK) {
|
|
|
|
window = 0x0;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-22 11:00:15 +00:00
|
|
|
} while(mfb_wait_sync(window));
|
2020-03-06 06:06:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|