71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
#include "GlutRender.hpp"
|
|
|
|
#include <GL/gl.h>
|
|
#include <GL/glut.h>
|
|
#include <cstring>
|
|
|
|
GlutRender& GlutRender::get_instance() {
|
|
static GlutRender instance;
|
|
return instance;
|
|
}
|
|
|
|
GlutRender::GlutRender() { }
|
|
|
|
void GlutRender::init(int* argc, char** argv,
|
|
int wid, int hei, const char* win_name)
|
|
{
|
|
glutInit(argc, argv);
|
|
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
|
|
glutInitWindowSize(wid, hei);
|
|
glutCreateWindow(win_name);
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
|
glShadeModel(GL_FLAT);
|
|
|
|
glutDisplayFunc(display_handle);
|
|
glutReshapeFunc(reshape_handle);
|
|
}
|
|
|
|
void GlutRender::cleanup() {
|
|
}
|
|
|
|
void GlutRender::add_mesh(const Mesh* mesh) {
|
|
meshes.insert(mesh);
|
|
}
|
|
|
|
void GlutRender::remove_mesh(const Mesh* mesh) {
|
|
meshes.erase(mesh);
|
|
}
|
|
|
|
void GlutRender::run() {
|
|
}
|
|
|
|
void GlutRender::reshape(int wid, int hei) {
|
|
glViewport(0, 0, (GLsizei) wid, (GLsizei) hei);
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
gluOrtho2D(0.0, (GLdouble) wid, 0.0, (GLdouble) hei);
|
|
}
|
|
|
|
void GlutRender::display() {
|
|
for(const Mesh* mesh: meshes) {
|
|
const std::vector<Point>& points = mesh->get_vertices();
|
|
for(const Face& face: mesh->get_faces()) {
|
|
const Point& p0 = face.pt(0, points),
|
|
p1 = face.pt(2, points),
|
|
p2 = face.pt(2, points);
|
|
glBegin(GL_TRIANGLES);
|
|
glVertex3d(p0[0], p0[1], p0[2]);
|
|
glVertex3d(p1[0], p1[1], p1[2]);
|
|
glVertex3d(p2[0], p2[1], p2[2]);
|
|
glEnd();
|
|
}
|
|
}
|
|
}
|
|
|
|
void GlutRender::reshape_handle(int wid, int hei) {
|
|
get_instance().reshape(wid, hei);
|
|
}
|
|
void GlutRender::display_handle() {
|
|
get_instance().display();
|
|
}
|