ld33_umonster

view src/scene.cc @ 4:7b1fa527b51b

added torus mesh gen
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 23 Aug 2015 04:31:29 +0300
parents 35349df5392d
children
line source
1 #include "scene.h"
2 #include "opengl.h"
3 #include "opt.h"
4 #include "game.h"
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_lights(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 for(size_t i=0; i<lights.size(); i++) {
44 lights[i]->setup(i);
45 }
47 for(size_t i=0; i<objects.size(); i++) {
48 unsigned int mask = objects[i]->rop.transparent ? DRAW_TRANSPARENT : DRAW_SOLID;
49 if(mask & flags) {
50 if(dbg_wireframe) {
51 objects[i]->draw_wire();
52 } else {
53 objects[i]->draw();
54 }
55 }
56 }
57 }