dbf-halloween2015

annotate src/scene.cc @ 4:4316c0c879e9

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