Minor additions
This commit is contained in:
19
OpenGL/playground/.vscode/settings.json
vendored
19
OpenGL/playground/.vscode/settings.json
vendored
@@ -35,6 +35,23 @@
|
|||||||
"type_traits": "cpp",
|
"type_traits": "cpp",
|
||||||
"tuple": "cpp",
|
"tuple": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"utility": "cpp"
|
"utility": "cpp",
|
||||||
|
"csignal": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"strstream": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"complex": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"thread": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"typeindex": "cpp",
|
||||||
|
"variant": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -9,7 +9,7 @@ vec3 viewPos = vec3(0.0, 0.0, 0.0);
|
|||||||
out vec4 outColour;
|
out vec4 outColour;
|
||||||
|
|
||||||
vec3 objectColour = vec3(0.58, 0.61, 0.627);
|
vec3 objectColour = vec3(0.58, 0.61, 0.627);
|
||||||
vec3 lightColour = vec3(0.0, 1.0, 1.0);
|
vec3 lightColour = vec3(1.0, 0.0, 1.0);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float ambientStrength = 0.5;
|
float ambientStrength = 0.5;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ int main(int argc, char** argv) {
|
|||||||
window = SDL_CreateWindow("OpenGL Playground V1.0",
|
window = SDL_CreateWindow("OpenGL Playground V1.0",
|
||||||
SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
640, 480,
|
1280, 720,
|
||||||
SDL_WINDOW_OPENGL);
|
SDL_WINDOW_OPENGL);
|
||||||
glContext = SDL_GL_CreateContext(window);
|
glContext = SDL_GL_CreateContext(window);
|
||||||
SDL_GL_SetSwapInterval(0);
|
SDL_GL_SetSwapInterval(0);
|
||||||
@@ -128,7 +128,7 @@ int main(int argc, char** argv) {
|
|||||||
glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
|
glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
|
||||||
|
|
||||||
// Projection matrice
|
// Projection matrice
|
||||||
glm::mat4 proj = glm::perspective(glm::radians(45.0f), 640.0f / 480.0f, 1.0f, 1000.0f);
|
glm::mat4 proj = glm::perspective(glm::radians(45.0f), 1280.0f / 720.0f, 1.0f, 1000.0f);
|
||||||
// Get uniform and send it to the GPU
|
// Get uniform and send it to the GPU
|
||||||
GLint uniProj = glGetUniformLocation(simpleShader.getProgram(), "proj");
|
GLint uniProj = glGetUniformLocation(simpleShader.getProgram(), "proj");
|
||||||
glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj));
|
glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj));
|
||||||
|
|||||||
@@ -39,3 +39,20 @@ void LoadOBJ(Logger& logger, std::string file, std::vector<glm::vec3>& vertices,
|
|||||||
|
|
||||||
logger << LOGGER_INFO << "Loaded OBJ: " << file << LOGGER_ENDL;
|
logger << LOGGER_INFO << "Loaded OBJ: " << file << LOGGER_ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlatShade(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& normals, std::vector<GLushort>& elements) {
|
||||||
|
std::vector<glm::vec3> shared_vertices;
|
||||||
|
for (int i = 0; i < elements.size(); i++) {
|
||||||
|
vertices.push_back(shared_vertices[elements[i]]);
|
||||||
|
if ((i % 3) == 2) {
|
||||||
|
GLushort ia = elements[i-2];
|
||||||
|
GLushort ib = elements[i-1];
|
||||||
|
GLushort ic = elements[i];
|
||||||
|
glm::vec3 normal = glm::normalize(glm::cross(
|
||||||
|
shared_vertices[ic] - shared_vertices[ia],
|
||||||
|
shared_vertices[ib] - shared_vertices[ia]));
|
||||||
|
for (int n = 0; n < 3; n++)
|
||||||
|
normals.push_back(normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,4 +26,8 @@ void LoadOBJ(Logger& logger,
|
|||||||
std::vector<glm::vec3>& normals,
|
std::vector<glm::vec3>& normals,
|
||||||
std::vector<GLushort>& elements);
|
std::vector<GLushort>& elements);
|
||||||
|
|
||||||
|
void FlatShade(std::vector<glm::vec3>& vertices,
|
||||||
|
std::vector<glm::vec3>& normals,
|
||||||
|
std::vector<GLushort>& elements);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user