dbf-halloween2015
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/scene.cc Sun Nov 01 00:09:12 2015 +0200 1.3 @@ -0,0 +1,63 @@ 1.4 +#include "scene.h" 1.5 +#include "opengl.h" 1.6 +#include "opt.h" 1.7 + 1.8 +extern bool wireframe; 1.9 +static int max_lights = -1; 1.10 + 1.11 +Scene::~Scene() 1.12 +{ 1.13 + clear(); 1.14 +} 1.15 + 1.16 +void Scene::clear() 1.17 +{ 1.18 + for(size_t i=0; i<objects.size(); i++) { 1.19 + delete objects[i]; 1.20 + } 1.21 + objects.clear(); 1.22 + 1.23 + for(size_t i=0; i<lights.size(); i++) { 1.24 + delete lights[i]; 1.25 + } 1.26 + lights.clear(); 1.27 +} 1.28 + 1.29 +void Scene::add_object(Object *obj) 1.30 +{ 1.31 + objects.push_back(obj); 1.32 +} 1.33 + 1.34 +void Scene::add_light(Light *lt) 1.35 +{ 1.36 + lights.push_back(lt); 1.37 +} 1.38 + 1.39 +void Scene::draw(unsigned int flags) const 1.40 +{ 1.41 + if(max_lights == -1) { 1.42 + glGetIntegerv(GL_MAX_LIGHTS, &max_lights); 1.43 + printf("max lights: %d\n", max_lights); 1.44 + } 1.45 + 1.46 + int num_lt = lights.size(); 1.47 + for(int i=0; i<max_lights; i++) { 1.48 + if(i < num_lt) { 1.49 + glEnable(GL_LIGHT0 + i); 1.50 + lights[i]->setup(i); 1.51 + } else { 1.52 + glDisable(GL_LIGHT0 + i); 1.53 + } 1.54 + } 1.55 + 1.56 + for(size_t i=0; i<objects.size(); i++) { 1.57 + unsigned int mask = objects[i]->rop.transparent ? DRAW_TRANSPARENT : DRAW_SOLID; 1.58 + if(mask & flags) { 1.59 + if(wireframe) { 1.60 + objects[i]->draw_wire(); 1.61 + } else { 1.62 + objects[i]->draw(); 1.63 + } 1.64 + } 1.65 + } 1.66 +}