#ifndef MESH_VIEWER_H
#define MESH_VIEWER_H

#define GL_GLEXT_PROTOTYPES
#include "my_mesh.h"
#include "mesh_view.h"
#include <list>
#include <QMatrix4x4>
#include <QColor>
#include <QDebug>
#include <QOpenGLWidget>
#include <QOpenGLShaderProgram>
#include <QOpenGLFunctions>
#include <QMouseEvent>


#define WIREFRAME_COLOR 0, 0, 0
#define FOV 70


using namespace OpenMesh;


class MeshViewer : public QOpenGLWidget {
    Q_OBJECT

	std::list<MeshView> meshes;
	QOpenGLShaderProgram program;
	QMatrix4x4 proj;
	QMatrix4x4 rot, rot_start;
	GLfloat cam_dist = 1;
	QPoint mouse_pos;

public:
    MeshViewer(QWidget *parent=nullptr);
	virtual QSize sizeHint() const override;
    void initializeGL() override;
    void resizeGL(int w, int h) override;
    void paintGL() override;

public slots:
	void addMesh(const MyMesh &mesh);
	void removeMesh(const MyMesh &mesh);

protected:
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseReleaseEvent(QMouseEvent *e);
    virtual void mouseMoveEvent(QMouseEvent *e);
    virtual void wheelEvent(QWheelEvent *e);

signals:
	void initialized();
};


#endif
