summaryrefslogtreecommitdiffstats
path: root/src/viewport.c
blob: e9082680dc502bc7607e403d0c2f42cb62fffda6 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (C) 2013  Patrick "P. J." McDermott
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include <SDL.h>
#include <lua.h>
#include "viewport.h"
#include "logging.h"

struct viewport *
init_viewport(Uint16 width, Uint16 height, int bpp)
{
	struct viewport *vp;

	vp = malloc(sizeof(*vp));
	if (vp == NULL) {
		err(1, "Failed to allocate viewport");
	}

	vp->x = 0;
	vp->y = 0;
	vp->w= width;
	vp->h= height;

	debug("Setting video mode...");
	vp->screen = SDL_SetVideoMode(width, height, bpp,
			SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWPALETTE);
	if (vp->screen == NULL) {
		err(1, "Failed to set video mode (%s)", SDL_GetError());
	}

	return vp;
}

int
init_viewport_lua(lua_State *L)
{
	Uint16 width;
	Uint16 height;

	width = lua_tointeger(L, 1);
	height = lua_tointeger(L, 2);

	init_viewport(width, height, 8);

	return 0;
}