Skip to content

Create a window

Julien Tauran edited this page Dec 27, 2018 · 1 revision

A window is defined as an object named "bs_frame_t", so you will need to create one for each window that you want to create (main window, dialog window).

bs_frame_t *frame = bs_frame_create();

Now that you have your frame object, you will have to modify it to make it fits with your desires, like in the example it's a window which can be closed and with a size of 500 * 500.

bs_frame_t *frame = bs_frame_create();
sfVideoMode mode = {500, 500, 32};

if (frame == NULL)
	exit(84);
frame->width = 500;
frame->height = 500;
frame->window = sfRenderWindow_create(mode, "Billy Scene", sfClose, NULL);
frame->clock = sfClock_create();
sfRenderWindow_setFramerateLimit(frame->window, 60);

Great ! Now you have your window, but you will need to draw it and makes it listen to events.

bs_scene_t *scene = NULL;

while (sfRenderWindow_isOpen(frame->window)) {
	while (sfRenderWindow_pollEvent(frame->window, &(frame->event))) {
		bs_event_dispatcher(frame->event, frame);
	}
	if (sfClock_getElapsedTime(frame->clock).microseconds >= 50000) {
		scene = bs_scene_get_by_id(frame, frame->current_scene);
		sfRenderWindow_clear(frame->window, sfBlack);
		bs_scene_render(scene, frame);
		sfRenderWindow_display(frame->window);
		sfClock_restart(frame->clock);
	}
}
bs_frame_destroy(frame);

The window should be black because there is nothing to draw, we will see how to add components in the next page.

Clone this wiki locally