2018-01-27 18:33:50 +01:00
|
|
|
/** The most basic renderer — a stupid glut application */
|
|
|
|
|
2018-02-06 19:07:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-01-27 18:33:50 +01:00
|
|
|
#include "../Mesh.hpp"
|
2018-02-12 18:40:05 +01:00
|
|
|
#include "../Implicit.hpp"
|
2018-01-27 18:33:50 +01:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
class GlutRender {
|
|
|
|
public:
|
|
|
|
static GlutRender& get_instance();
|
|
|
|
|
|
|
|
GlutRender(GlutRender const&) = delete;
|
|
|
|
void operator=(GlutRender const&) = delete;
|
|
|
|
|
|
|
|
void init(int* argc, char** argv,
|
|
|
|
int wid, int hei, const char* win_name);
|
|
|
|
void cleanup();
|
2018-02-06 21:05:45 +01:00
|
|
|
void add_mesh(Mesh* mesh);
|
|
|
|
void remove_mesh(Mesh* mesh);
|
2018-02-12 18:40:05 +01:00
|
|
|
void add_surface(ImplicitSurface* surf, const Cuboid& box);
|
|
|
|
void remove_surface(ImplicitSurface* surf);
|
2018-01-27 18:33:50 +01:00
|
|
|
void run();
|
|
|
|
|
2018-02-12 18:40:05 +01:00
|
|
|
void set_idle_func(void (*func)(void));
|
|
|
|
|
2018-01-27 18:33:50 +01:00
|
|
|
private:
|
2018-02-12 18:40:05 +01:00
|
|
|
struct SurfaceDetails {
|
|
|
|
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box):
|
|
|
|
surface(surf), box(box) {}
|
|
|
|
|
|
|
|
ImplicitSurface* surface;
|
|
|
|
Cuboid box;
|
|
|
|
|
|
|
|
bool operator<(const SurfaceDetails& oth) const {
|
|
|
|
return surface < oth.surface;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-13 14:47:51 +01:00
|
|
|
|
|
|
|
private: //meth
|
|
|
|
GlutRender();
|
|
|
|
|
|
|
|
void display_mesh(Mesh& mesh) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void reshape(int wid, int hei);
|
|
|
|
void display();
|
|
|
|
|
|
|
|
static void reshape_handle(int wid, int hei);
|
|
|
|
static void display_handle();
|
|
|
|
|
|
|
|
private: //attr
|
2018-02-12 18:40:05 +01:00
|
|
|
std::function<double()> rand_color;
|
|
|
|
|
2018-02-06 21:05:45 +01:00
|
|
|
std::set<Mesh*> meshes;
|
2018-02-12 18:40:05 +01:00
|
|
|
std::set<SurfaceDetails> surfaces;
|
2018-01-27 18:33:50 +01:00
|
|
|
};
|