OpenGLController.h 2.8 KB
Newer Older
1
#pragma once
Anakin's avatar
Anakin committed
2 3
#include <gl\glew.h>
#include <gl\glfw3.h>
Anakin's avatar
Anakin committed
4
#include "Object.h"
Anakin's avatar
Anakin committed
5 6
#include <vector>

7

8 9 10 11
#define VERTEX_INDEX_XYZ		0
#define VERTEX_INDEX_UV			1

#define VERTEX_COMPONENTS_XYZ	3
12
#define VERTEX_COMPONENTS_UV	2
13 14 15 16 17 18 19 20 21 22 23 24

#define VERTEX_SIZE_XYZ			(sizeof(float) * VERTEX_COMPONENTS_XYZ)
#define VERTEX_SIZE_UV			(sizeof(float) * VERTEX_COMPONENTS_UV)

#define VERTEX_OFFSET_XYZ		0
#define VERTEX_OFFSET_UV		(VERTEX_SIZE_XYZ)

struct Vertex {
	GLfloat position[3];
	GLfloat uv[2];
};

25 26 27 28
struct textureData {
	bool alpha;
	std::uint32_t width;
	std::uint32_t height;
Anakin's avatar
Anakin committed
29
	std::vector<std::uint8_t>* data;
30 31
};

32 33
class OpenGLController
{
Anakin's avatar
Anakin committed
34 35
////////////////////////////////////////////////////////////////////////////////////////////
// constructor/destructor
36
public:
Anakin's avatar
Anakin committed
37
	static OpenGLController* getInstance(int oglMajor = 4, int oglMinor = 5);
38 39
	~OpenGLController();

Anakin's avatar
Anakin committed
40 41 42 43
private:
	OpenGLController() {};
	OpenGLController(int oglMajor, int oglMinor);

Anakin's avatar
Anakin committed
44 45
////////////////////////////////////////////////////////////////////////////////////////////
// member
46
private:
Anakin's avatar
Anakin committed
47
	// window
48 49 50 51
	GLFWwindow* pWindow			= NULL;
	std::string sWindowName		= "MeshViewer 2.0 pre-alpha";
	int iWidth					= 640;
	int iHeight					= 480;
52

Anakin's avatar
Anakin committed
53
	// init glfw
54 55 56
	int iOglMajorVersion		= 4;
	int iOglMinorVersion		= 5;
	int iAntiAliasingLevel		= 4;
57

58
// IDs ====================================
Anakin's avatar
Anakin committed
59
	//object data
60 61
	GLuint gluiVertexArrayID	= 0;
	GLuint gluiVertexBufferID	= 0;
Anakin's avatar
Anakin committed
62 63

	//obj color
64 65 66
	GLuint gluiTextureID		= 0;
	GLuint gluiShaderPrgmID		= 0;
	GLuint gluiSamplerID		= 0;
67

Anakin's avatar
Anakin committed
68
	//obj transformation
69 70
	GLuint gluiMatrixID			= 0;
// ========================================
Anakin's avatar
Anakin committed
71 72

	// data
73
	std::vector<Modl*>* vModels = NULL;
74
	std::vector<textureData*> vTextures;
Anakin's avatar
Anakin committed
75
	Bbox sceneBoundingBox;
Anakin's avatar
Anakin committed
76

77
// transformation =========================
Anakin's avatar
Anakin committed
78
	//values
79 80 81 82 83
	float fRotationX			= 0;
	float fRotationY			= 0;
	float fRotationZ			= 0;
	double dTranslationX		= 0;
	double dTranslationY		= 0;
Anakin's avatar
Anakin committed
84
	double dTranslationZ		= 3;
Anakin's avatar
Anakin committed
85

86
// ========================================
87

Anakin's avatar
Anakin committed
88
	// camera
89 90 91
	float fFOV					= 45.0f;
	float fMinView				= 0.1f;
	float fMaxView				= 100.0f;
92 93


Anakin's avatar
Anakin committed
94 95
////////////////////////////////////////////////////////////////////////////////////////////
// private functions
96 97
private:
	void processInit();
Anakin's avatar
Anakin committed
98
	void deleteVectors();
Anakin's avatar
Anakin committed
99

100 101
	void startGLFW();
	void createWindow();
Anakin's avatar
Anakin committed
102
	void startGLEW();
103 104
	void setCallbackFunctions();

Anakin's avatar
Anakin committed
105
	glm::mat4 getModelMatrix(unsigned int index);
Anakin's avatar
Anakin committed
106
	glm::mat4 getMVPMatrix(unsigned int index);
107

Anakin's avatar
Anakin committed
108 109 110 111 112 113

////////////////////////////////////////////////////////////////////////////////////////////
// public functions
public:

	// callback
114 115 116 117 118 119
	void resize(int width, int height);
	void addRotX(float value);
	void addRotY(float value);
	void addTransX(double value);
	void addTransY(double value);
	void addTransZ(double value);
Anakin's avatar
Anakin committed
120
	void resetView();
121

Anakin's avatar
Anakin committed
122 123
	// main routine
	GLFWwindow* getWindow() const;
124
	void updateScene();
Anakin's avatar
Anakin committed
125
	void loadMsh(const char* path);
126 127 128

};