SWBF2-Classic-Msh-Viewer/MshViewer/Header/OpenGLController.h

120 lines
2.4 KiB
C++

#pragma once
#include <string>
#include <gl\glew.h>
#include <gl\glfw3.h>
#include <glm\glm.hpp>
#include <vector>
#include "Object.h"
#define VERTEX_INDEX_XYZ 0
#define VERTEX_INDEX_UV 1
#define VERTEX_COMPONENTS_XYZ 3
#define VERTEX_COMPONENTS_UV 4
#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];
};
class OpenGLController
{
////////////////////////////////////////////////////////////////////////////////////////////
// constructor/destructor
public:
static OpenGLController* getInstance(int oglMajor = 4, int oglMinor = 5);
~OpenGLController();
private:
OpenGLController() {};
OpenGLController(int oglMajor, int oglMinor);
////////////////////////////////////////////////////////////////////////////////////////////
// member
private:
// window
GLFWwindow* pWindow;
std::string sWindowName;
int iWidth;
int iHeight;
// init glfw
int iOglMajorVersion;
int iOglMinorVersion;
int iAntiAliasingLevel;
// IDs ==========================
//object data
GLuint gluiVertexArrayID;
GLuint gluiInstanceBufferID;
GLuint gluiVertexBufferID;
//obj color
GLuint gluiTextureID;
GLuint gluiShaderPrgmID;
GLuint gluiSamplerID;
//obj transformation
GLuint gluiMatrixID;
// ==============================
// data
std::vector<Modl*> vModels;
// transformation ===============
//values
float fRotationX;
float fRotationY;
float fRotationZ;
double dTranslationX;
double dTranslationY;
double dTranslationZ;
// ==============================
// camera
float fFOV;
float fMinView;
float fMaxView;
////////////////////////////////////////////////////////////////////////////////////////////
// private functions
private:
void processInit();
void initDefault();
void startGLFW();
void createWindow();
void startGLEW();
void setCallbackFunctions();
glm::mat4 getMVPMatrix();
////////////////////////////////////////////////////////////////////////////////////////////
// public functions
public:
// callback
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);
// main routine
GLFWwindow* getWindow() const;
void updateScene();
void loadMsh(const char* path);
};