// TODO: add some fancy rendering to the buffer of size 800 * 600
state = mfb_update_ex(buffer, 800, 600);
if (state <0){
window = NULL;
break;
}
} while(mfb_wait_sync(window));
```
1. First the application creates a **window** calling **mfb_open** or **mfb_open_ex**.
2. Next it's the application responsibility to allocate a buffer to work with.
3. Next calling **mfb_update** or **mfb_update_ex** the buffer will be copied over to the window and displayed. If this function return a value lower than 0 the window will have been destroyed internally and cannot be used anymore.
4. Last the code waits to synchronize with the monitor calling **mfb_wait_sync**.
Note that, by default, if ESC key is pressed **mfb_update** / **mfb_update_ex** will return -1 (and the window will have been destroyed internally).
See https://github.com/emoon/minifb/blob/master/tests/noise.c for a complete example.
MiniFB has been tested on Windows, Mac OS X, Linux and iOS but may of course have trouble depending on your setup. Currently the code will not do any converting of data if not a proper 32-bit display can be created.
int mfb_get_mouse_x(struct mfb_window *window); // Last mouse pos X
int mfb_get_mouse_y(struct mfb_window *window); // Last mouse pos Y
float mfb_get_mouse_scroll_x(struct mfb_window *window); // Mouse wheel X as a sum. When you call this function it resets.
float mfb_get_mouse_scroll_y(struct mfb_window *window); // Mouse wheel Y as a sum. When you call this function it resets.
const uint8_t * mfb_get_mouse_button_buffer(struct mfb_window *window); // One byte for every button. Press (1), Release 0. (up to 8 buttons)
const uint8_t * mfb_get_key_buffer(struct mfb_window *window); // One byte for every key. Press (1), Release 0.
```
Additionally you can _set per window data and recover it_:
```c
mfb_set_user_data(window, (void *) myData);
...
myData = (someCast *) mfb_get_user_data(window);
```
**Extra: Timers and target FPS**
You can create timers for your own purposes.
```c
struct mfb_timer * mfb_timer_create();
void mfb_timer_destroy(struct mfb_timer *tmr);
void mfb_timer_reset(struct mfb_timer *tmr);
double mfb_timer_now(struct mfb_timer *tmr);
double mfb_timer_delta(struct mfb_timer *tmr);
double mfb_timer_get_frequency();
double mfb_timer_get_resolution();
```
Furthermore you can set a target fps for the application. The default is 60 frames per second.
```c
void mfb_set_target_fps(uint32_t fps);
```
This avoid the problem of update too fast the window collapsing the redrawing in fast processors.
To use this you need to call the function:
```c
bool mfb_wait_sync(struct mfb_window *window);
```
Note that if you have several windows running on the same thread it makes no sense to wait them all...
## Build instructions
The current build system is **CMake**.
Initially MiniFB used tundra [https://github.com/deplinenoise/tundra](https://github.com/deplinenoise/tundra) as build system and it was required to build the code (but now is not maintained).
In any case, not many changes should be needed if you want to use MiniFB directly in your own code.
### Mac
Cocoa and clang is assumed to be installed on the system (downloading latest XCode + installing the command line tools should do the trick).
Note that MacOS X Mojave+ does not support Cocoa framework as expected. For that reason you can switch to Metal API.
To enable it just compile defining the preprocessor macro USE_METAL_API.
and you should be able to run noise in t2-output/win32-msvc-debug-default/noise.exe
#### **NEW**: OpenGL API backend
Now, by default, OpenGL backend is used, instead of Windows GDI, because it is faster. To maintain compatibility with old computers an OpenGL 1.5 context is created (no shaders needed).
To enable or disable OpenGL just use a CMake flag:
```
cmake .. -DUSE_OPENGL_API=ON
or
cmake .. -DUSE_OPENGL_API=OFF
```
### x11 (FreeBSD, Linux, *nix)
gcc and x11-dev libs needs to be installed.
If you use **CMake** just disable the flag:
```
mkdir build
cd build
cmake .. -DUSE_WAYLAND_API=OFF
```
If you use **tundra**:
To build the code run:
```
tundra2 x11-gcc-debug
```
and you should be able to run t2-output/x11-gcc-debug-default/noise
#### **NEW**: OpenGL API backend
Now, by default, OpenGL backend is used instead of X11 XImages because it is faster. To maintain compatibility with old computers an OpenGL 1.5 context is created (no shaders needed).
To enable or disable OpenGL just use a CMake flag: