forked from Milez213/CityTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlatShader.h
129 lines (91 loc) · 2.71 KB
/
FlatShader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef FLAT_SHADER_H
#define FLAT_SHADER_H
#include <stdlib.h>
#include <stdio.h>
#include "glm/glm.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "Shader.h"
#include "defines.h"
using glm::vec3;
using glm::mat4;
using glm::value_ptr;
struct PhongMaterial {
vec3 aColor;
vec3 dColor;
vec3 sColor;
GLfloat shine;
};
struct LightInfo {
vec3 pos;
vec3 color;
};
class FlatShader : public Shader {
public:
// Constructor calls parent
FlatShader() : Shader("shaders/flat_vert.glsl", "shaders/flat_frag.glsl") {
if (m_installed) {
// matrices
h_uProjMatrix = safe_glGetUniformLocation(m_shaderProg, "uProjMatrix");
h_uViewMatrix = safe_glGetUniformLocation(m_shaderProg, "uViewMatrix");
h_uModelMatrix = safe_glGetUniformLocation(m_shaderProg, "uModelMatrix");
h_aPosition = safe_glGetAttribLocation(m_shaderProg, "aPosition");
} else {
fprintf(stderr, "FlatShader(): Couldn't install shaders\n");
exit(1);
}
}
GLint getPosLocation() {
return h_aPosition;
}
void setModelMatrix(mat4 mat) {
safe_glUniformMatrix4fv(h_uModelMatrix, value_ptr(mat));
}
void setViewMatrix(mat4 mat) {
safe_glUniformMatrix4fv(h_uViewMatrix, value_ptr(mat));
}
void setProjMatrix(mat4 mat) {
safe_glUniformMatrix4fv(h_uProjMatrix, value_ptr(mat));
}
/* DOesn't have these
void setShowNormals(int show) {
safe_glUniform1i(h_uShowNormals, show);
}
void setMaterial(PhongMaterial &mat) {
safe_glUniform3f(h_uMatAmb, mat.aColor);
safe_glUniform3f(h_uMatDif, mat.dColor);
safe_glUniform3f(h_uMatSpec, mat.sColor);
safe_glUniform1f(h_uMatShine, mat.shine);
}
void setLight(const LightInfo &l) {
safe_glUniform3f(h_uLightPos, l.pos);
safe_glUniform3f(h_uLightColor, l.color);
}
void setCamPos(vec3 pos) {
safe_glUniform3f(h_uCamPos, pos);
}
void setTexture(GLuint textureName) {
GLint location = safe_glGetUniformLocation(m_shaderProg, "uTexUnit");
safe_glUniform1i(location, textureName);
}
void setNormTexture(GLuint textureName) {
GLint location = safe_glGetUniformLocation(m_shaderProg, "uNormTexUnit");
safe_glUniform1i(location, textureName);
}
*/
private:
// vertex
GLint h_aPosition;
GLint h_aColor;
GLint h_aNormal;
// matrices
GLint h_uModelMatrix;
GLint h_uViewMatrix;
GLint h_uProjMatrix;
// light info - not used here
GLint h_uLightPos;
GLint h_uLightColor;
GLint h_uMatAmb, h_uMatDif, h_uMatSpec, h_uMatShine;
GLint h_uShowNormals;
GLint h_uCamPos;
};
#endif