aboutsummaryrefslogtreecommitdiff
path: root/window.c
blob: 2128f1c253eec89fbde887db997a40190248a4c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "window.h"

#include <SDL.h>

int display_init(struct window *wobj)
{
	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0)
	{
		fprintf(stderr,"Couldn't init SDL: %s\n", SDL_GetError());
		return EXIT_FAILURE;
	}

	/* Create run-of-the-mill window at specified size */
	wobj->window = SDL_CreateWindow(
			wobj->title,
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			wobj->width, wobj->height,
			SDL_WINDOW_SHOWN
		);
	if (wobj->window == NULL)
	{
		fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
		return EXIT_FAILURE;
	}

	/* Grab window surface */
	wobj->surface = SDL_GetWindowSurface(wobj->window);
	if (wobj->surface == NULL)
	{
		fprintf(stderr, "Couldn't grab window surface: %s\n", SDL_GetError());
		return EXIT_FAILURE;
	}

	/* Clear/blank surface with grey, and update it */
	SDL_FillRect(wobj->surface, NULL, SDL_MapRGB(wobj->surface->format, 0x33, 0x33, 0x33));
	SDL_UpdateWindowSurface(wobj->window);
	return EXIT_SUCCESS;
}

void display_stop(struct window *wobj)
{
	SDL_DestroyWindow(wobj->window);
	SDL_Quit();
}