1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
32 /* comparison functions:
34 * return 1 to insert later
35 * return -1 to not insert at all
37 static int light_insert_cmp(void *e1
, void *e2
)
50 int light_add(colour_t
*colour
, v3_t
*pos
, v3_t
*att
)
53 if (light_data
.ids
< 0)
54 array_init(&light_data
.lights
,ARRAY_TYPE_PTR
);
56 l
= malloc(sizeof(light_t
));
64 l
->colour
.r
= colour
->r
;
65 l
->colour
.g
= colour
->g
;
66 l
->colour
.b
= colour
->b
;
67 l
->colour
.a
= colour
->a
;
79 l
->id
= ++light_data
.ids
;
81 array_push_ptr(&light_data
.lights
,l
);
86 void light_remove(int id
)
90 void light_bind_near(shader_t
*s
, v3_t
*pos
)
94 light_t
*nearby
= NULL
;
96 if (light_data
.ids
< 0)
99 for (i
=0; i
<light_data
.lights
.length
; i
++) {
100 l
= array_get_ptr(&light_data
.lights
,i
);
103 l
->d
= math_distance(pos
,&l
->pos
);
104 nearby
= list_insert_cmp(&nearby
,l
,light_insert_cmp
);
109 shader_uniform_light(s
,i
,l
);
113 shader_uniform_light(s
,i
,NULL
);