ported the University CGI demo from WINDOWS + GLUT + GLEW + GLU + OpenGL 4 to LINUX WAYLAND + EGL + GLES 2 with minimal cuts
This commit is contained in:
40
GL_STUFF/HEADERS/SCENE/Camera.hpp
Executable file
40
GL_STUFF/HEADERS/SCENE/Camera.hpp
Executable file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
class Camera {
|
||||
|
||||
public:
|
||||
glm::vec3 cameraPos;
|
||||
glm::vec3 cameraFront;
|
||||
glm::vec3 cameraUp;
|
||||
|
||||
Camera();
|
||||
Camera( glm::vec3 position, glm::vec3 front, glm::vec3 up);
|
||||
glm::mat4 getViewMat();
|
||||
glm::vec3 getPosition();
|
||||
//exp
|
||||
void alignTo( glm::vec3 direction);
|
||||
void setPosition( glm::vec3 pos);
|
||||
};
|
||||
|
||||
class CameraController {
|
||||
|
||||
private:
|
||||
Camera *camera;
|
||||
float cameraSpeed = 0.5f;
|
||||
bool mouseUnlocked = true;
|
||||
float lastX;
|
||||
float lastY;
|
||||
float PHI = 0.0;
|
||||
float THETA = 270.0;
|
||||
unsigned int windowLeft;
|
||||
unsigned int windowTop;
|
||||
unsigned int windowWidth;
|
||||
unsigned int windowHeight;
|
||||
|
||||
public:
|
||||
CameraController(Camera *cam);
|
||||
Camera* getCamera();
|
||||
void setWindowData(int left, int width, int top, int height);
|
||||
void mouseMotion(int cursorX, int cursorY);
|
||||
void keyPress(unsigned char key);
|
||||
};
|
||||
21
GL_STUFF/HEADERS/SCENE/Instance3D.h
Executable file
21
GL_STUFF/HEADERS/SCENE/Instance3D.h
Executable file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
/*
|
||||
#include <GL/glew.h>
|
||||
*/
|
||||
#include <GLES2/gl2.h>
|
||||
#include "./Model3D.hpp"
|
||||
#include "../SCENE/ObjectInstance.hpp"
|
||||
|
||||
class Instance3D : public WorldInstanceable {
|
||||
|
||||
private:
|
||||
Model3D* mesh;
|
||||
|
||||
public:
|
||||
Instance3D(Model3D* mesh, vec3 position);
|
||||
Instance3D(Model3D* mesh, vec3 position, vec3 scale);
|
||||
Instance3D(Model3D* mesh, vec3 position, vec3 axis, float angle);
|
||||
Instance3D(Model3D* mesh, vec3 position, vec3 scale, vec3 axis, float angle);
|
||||
Model3D* getModel();
|
||||
};
|
||||
3
GL_STUFF/HEADERS/SCENE/InstancesLoader.h
Executable file
3
GL_STUFF/HEADERS/SCENE/InstancesLoader.h
Executable file
@@ -0,0 +1,3 @@
|
||||
#include "../SCENE/Instance3D.h"
|
||||
|
||||
bool loadInstances(std::string path, vector<Instance3D*>& instances, bool smoothNormals);
|
||||
29
GL_STUFF/HEADERS/SCENE/Model3D.hpp
Executable file
29
GL_STUFF/HEADERS/SCENE/Model3D.hpp
Executable file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std; //for vector
|
||||
using namespace glm; //vec3 and friends
|
||||
|
||||
class Model3D {
|
||||
|
||||
private:
|
||||
int nVertices;
|
||||
GLuint vao;
|
||||
vec3 boundingBoxLBN;
|
||||
vec3 boundingBoxRTF;
|
||||
vector<vec3> loadVertexData(const char* modelPath, bool smoothNormals);
|
||||
void computeBoundingBox(vector<vec3> points);
|
||||
|
||||
public:
|
||||
Model3D(const char* modelPath, bool smoothNormals);
|
||||
GLuint getVAO();
|
||||
int getTrisCount();
|
||||
void draw();
|
||||
vec3 getLBN();
|
||||
vec3 getRTF();
|
||||
};
|
||||
30
GL_STUFF/HEADERS/SCENE/ObjectInstance.hpp
Executable file
30
GL_STUFF/HEADERS/SCENE/ObjectInstance.hpp
Executable file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class WorldInstanceable {
|
||||
|
||||
private:
|
||||
glm::vec3 localFront, localUp;
|
||||
void setup(glm::vec3 position);
|
||||
|
||||
public:
|
||||
glm::mat4 scaleMat;
|
||||
glm::mat4 rotation;
|
||||
glm::vec3 position;
|
||||
WorldInstanceable(glm::vec3 position);
|
||||
WorldInstanceable(glm::vec3 position, glm::vec3 scale);
|
||||
WorldInstanceable(glm::vec3 position, glm::vec3 axis, float angle);
|
||||
WorldInstanceable(glm::vec3 position, glm::vec3 scale, glm::vec3 axis, float angle);
|
||||
void setPosition(glm::vec3 position);
|
||||
void rotate(glm::vec3 axis, float angle);
|
||||
void scale(float factor);
|
||||
void scale(glm::vec3 factors);
|
||||
glm::mat4 getLocalTransform();
|
||||
glm::mat4 getGlobalTransform();
|
||||
void alignTo(glm::vec3 direction);
|
||||
|
||||
};
|
||||
26
GL_STUFF/HEADERS/SCENE/ShadingHelper.h
Executable file
26
GL_STUFF/HEADERS/SCENE/ShadingHelper.h
Executable file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
/*
|
||||
#include <GL/glew.h>
|
||||
*/
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class ShadingHelper {
|
||||
GLuint program;
|
||||
public:
|
||||
ShadingHelper(GLuint program);
|
||||
void useProgram();
|
||||
GLuint getProgram();
|
||||
void bindTexture2D(GLuint texUnitIndex, GLuint texture, std::string uniform);
|
||||
void bindViewUniforms(glm::mat4 projection, glm::mat4 view);
|
||||
void bindLightUniforms(glm::vec3 lightPos, glm::vec3 lightCol, glm::vec3 eyePos);
|
||||
void bindModelUniforms(glm::mat4 locRotScl, glm::mat4 rotScl);
|
||||
};
|
||||
|
||||
class TextureHelper {
|
||||
public:
|
||||
GLuint texture;
|
||||
std::string uniformName;
|
||||
};
|
||||
20
GL_STUFF/HEADERS/SCENE/objloader.hpp
Executable file
20
GL_STUFF/HEADERS/SCENE/objloader.hpp
Executable file
@@ -0,0 +1,20 @@
|
||||
#ifndef OBJLOADER_H
|
||||
#define OBJLOADER_H
|
||||
|
||||
bool loadOBJ(
|
||||
const char* path,
|
||||
std::vector<glm::vec3>& out_vertices,
|
||||
std::vector<glm::vec2>& out_uvs,
|
||||
std::vector<glm::vec3>& out_normals,
|
||||
bool smoothNormals
|
||||
);
|
||||
|
||||
bool loadAssImp(
|
||||
const char* path,
|
||||
std::vector<unsigned short>& indices,
|
||||
std::vector<glm::vec3>& vertices,
|
||||
std::vector<glm::vec2>& uvs,
|
||||
std::vector<glm::vec3>& normals
|
||||
);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user