mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-08 01:33:22 +08:00
@@ -2,6 +2,7 @@
|
|||||||
#define FILESYSTEM_H
|
#define FILESYSTEM_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdlib>
|
||||||
#include "root_directory.h" // This is a configuration file generated by CMake.
|
#include "root_directory.h" // This is a configuration file generated by CMake.
|
||||||
|
|
||||||
class FileSystem
|
class FileSystem
|
||||||
|
|||||||
@@ -141,29 +141,26 @@ private:
|
|||||||
indices.push_back(face.mIndices[j]);
|
indices.push_back(face.mIndices[j]);
|
||||||
}
|
}
|
||||||
// process materials
|
// process materials
|
||||||
if(mesh->mMaterialIndex >= 0)
|
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
|
||||||
{
|
// we assume a convention for sampler names in the shaders. Each diffuse texture should be named
|
||||||
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
|
// as 'texture_diffuseN' where N is a sequential number ranging from 1 to MAX_SAMPLER_NUMBER.
|
||||||
// we assume a convention for sampler names in the shaders. Each diffuse texture should be named
|
// Same applies to other texture as the following list summarizes:
|
||||||
// as 'texture_diffuseN' where N is a sequential number ranging from 1 to MAX_SAMPLER_NUMBER.
|
// diffuse: texture_diffuseN
|
||||||
// Same applies to other texture as the following list summarizes:
|
// specular: texture_specularN
|
||||||
// diffuse: texture_diffuseN
|
// normal: texture_normalN
|
||||||
// specular: texture_specularN
|
|
||||||
// normal: texture_normalN
|
|
||||||
|
|
||||||
// 1. diffuse maps
|
// 1. diffuse maps
|
||||||
vector<Texture> diffuseMaps = loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse");
|
vector<Texture> diffuseMaps = loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse");
|
||||||
textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());
|
textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());
|
||||||
// 2. specular maps
|
// 2. specular maps
|
||||||
vector<Texture> specularMaps = loadMaterialTextures(material, aiTextureType_SPECULAR, "texture_specular");
|
vector<Texture> specularMaps = loadMaterialTextures(material, aiTextureType_SPECULAR, "texture_specular");
|
||||||
textures.insert(textures.end(), specularMaps.begin(), specularMaps.end());
|
textures.insert(textures.end(), specularMaps.begin(), specularMaps.end());
|
||||||
// 3. normal maps
|
// 3. normal maps
|
||||||
std::vector<Texture> normalMaps = loadMaterialTextures(material, aiTextureType_HEIGHT, "texture_normal");
|
std::vector<Texture> normalMaps = loadMaterialTextures(material, aiTextureType_HEIGHT, "texture_normal");
|
||||||
textures.insert(textures.end(), normalMaps.begin(), normalMaps.end());
|
textures.insert(textures.end(), normalMaps.begin(), normalMaps.end());
|
||||||
// 4. height maps
|
// 4. height maps
|
||||||
std::vector<Texture> heightMaps = loadMaterialTextures(material, aiTextureType_AMBIENT, "texture_height");
|
std::vector<Texture> heightMaps = loadMaterialTextures(material, aiTextureType_AMBIENT, "texture_height");
|
||||||
textures.insert(textures.end(), heightMaps.begin(), heightMaps.end());
|
textures.insert(textures.end(), heightMaps.begin(), heightMaps.end());
|
||||||
}
|
|
||||||
|
|
||||||
// return a mesh object created from the extracted mesh data
|
// return a mesh object created from the extracted mesh data
|
||||||
return Mesh(vertices, indices, textures);
|
return Mesh(vertices, indices, textures);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ unsigned int loadTexture(const char *path, bool gammaCorrection);
|
|||||||
// settings
|
// settings
|
||||||
const unsigned int SCR_WIDTH = 1280;
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
const unsigned int SCR_HEIGHT = 720;
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
bool gamma = false;
|
bool gammaEnabled = false;
|
||||||
bool gammaKeyPressed = false;
|
bool gammaKeyPressed = false;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
@@ -160,14 +160,14 @@ int main()
|
|||||||
glUniform3fv(glGetUniformLocation(shader.ID, "lightPositions"), 4, &lightPositions[0][0]);
|
glUniform3fv(glGetUniformLocation(shader.ID, "lightPositions"), 4, &lightPositions[0][0]);
|
||||||
glUniform3fv(glGetUniformLocation(shader.ID, "lightColors"), 4, &lightColors[0][0]);
|
glUniform3fv(glGetUniformLocation(shader.ID, "lightColors"), 4, &lightColors[0][0]);
|
||||||
shader.setVec3("viewPos", camera.Position);
|
shader.setVec3("viewPos", camera.Position);
|
||||||
shader.setInt("gamma", gamma);
|
shader.setInt("gamma", gammaEnabled);
|
||||||
// floor
|
// floor
|
||||||
glBindVertexArray(planeVAO);
|
glBindVertexArray(planeVAO);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, gamma ? floorTextureGammaCorrected : floorTexture);
|
glBindTexture(GL_TEXTURE_2D, gammaEnabled ? floorTextureGammaCorrected : floorTexture);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
std::cout << (gamma ? "Gamma enabled" : "Gamma disabled") << std::endl;
|
std::cout << (gammaEnabled ? "Gamma enabled" : "Gamma disabled") << std::endl;
|
||||||
|
|
||||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
@@ -202,7 +202,7 @@ void processInput(GLFWwindow *window)
|
|||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS && !gammaKeyPressed)
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS && !gammaKeyPressed)
|
||||||
{
|
{
|
||||||
gamma = !gamma;
|
gammaEnabled = !gammaEnabled;
|
||||||
gammaKeyPressed = true;
|
gammaKeyPressed = true;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_RELEASE)
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_RELEASE)
|
||||||
|
|||||||
Reference in New Issue
Block a user