#ifndef MESHVIEWERWIDGET_H
#define MESHVIEWERWIDGET_H

#define GL_GLEXT_PROTOTYPES
#include "mymesh.h"
#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 MeshViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions {
    Q_OBJECT

public:
    MeshViewerWidget(QWidget* parent=nullptr);

    void initializeGL() override;
    void resizeGL(int w, int h) override;
    void paintGL() override;

	void add(size_t nverts, const GLfloat *verts, QMatrix4x4 mat=QMatrix4x4(), QColor col={153, 153, 153});
	void addFromMesh(MyMesh* _mesh, QMatrix4x4 mat=QMatrix4x4(), QColor col={153, 153, 153});

private:
	GLint pos_attr, proj_attr, view_attr, model_attr;
	GLint col_attr, alpha_attr;
	QMatrix4x4 proj;
	QMatrix4x4 rot, rot_start;
	GLfloat cam_dist = 1;
	QPoint mouse_pos;

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
