dbf-halloween2015
view src/scene.cc @ 0:50683c78264e
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 00:09:12 +0200 |
parents | |
children |
line source
1 #include "scene.h"
2 #include "opengl.h"
3 #include "opt.h"
5 extern bool wireframe;
6 static int max_lights = -1;
8 Scene::~Scene()
9 {
10 clear();
11 }
13 void Scene::clear()
14 {
15 for(size_t i=0; i<objects.size(); i++) {
16 delete objects[i];
17 }
18 objects.clear();
20 for(size_t i=0; i<lights.size(); i++) {
21 delete lights[i];
22 }
23 lights.clear();
24 }
26 void Scene::add_object(Object *obj)
27 {
28 objects.push_back(obj);
29 }
31 void Scene::add_light(Light *lt)
32 {
33 lights.push_back(lt);
34 }
36 void Scene::draw(unsigned int flags) const
37 {
38 if(max_lights == -1) {
39 glGetIntegerv(GL_MAX_LIGHTS, &max_lights);
40 printf("max lights: %d\n", max_lights);
41 }
43 int num_lt = lights.size();
44 for(int i=0; i<max_lights; i++) {
45 if(i < num_lt) {
46 glEnable(GL_LIGHT0 + i);
47 lights[i]->setup(i);
48 } else {
49 glDisable(GL_LIGHT0 + i);
50 }
51 }
53 for(size_t i=0; i<objects.size(); i++) {
54 unsigned int mask = objects[i]->rop.transparent ? DRAW_TRANSPARENT : DRAW_SOLID;
55 if(mask & flags) {
56 if(wireframe) {
57 objects[i]->draw_wire();
58 } else {
59 objects[i]->draw();
60 }
61 }
62 }
63 }