ld33_umonster
diff src/scene.cc @ 0:4a6683050e29
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 22 Aug 2015 07:15:00 +0300 |
parents | |
children | 35349df5392d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/scene.cc Sat Aug 22 07:15:00 2015 +0300 1.3 @@ -0,0 +1,57 @@ 1.4 +#include "scene.h" 1.5 +#include "opengl.h" 1.6 +#include "opt.h" 1.7 +#include "game.h" 1.8 + 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_lights(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 + for(size_t i=0; i<lights.size(); i++) { 1.47 + lights[i]->setup(i); 1.48 + } 1.49 + 1.50 + for(size_t i=0; i<objects.size(); i++) { 1.51 + unsigned int mask = objects[i]->rop.transparent ? DRAW_TRANSPARENT : DRAW_SOLID; 1.52 + if(mask & flags) { 1.53 + if(dbg_wireframe) { 1.54 + objects[i]->draw_wire(); 1.55 + } else { 1.56 + objects[i]->draw(); 1.57 + } 1.58 + } 1.59 + } 1.60 +}