Support for out-of-source builds.

Uses environment variable to tell the program where to find resource
files.
Sharder sources are still search for in the current workind directory.
This commit is contained in:
Marin Nilsson
2015-07-30 21:48:41 +02:00
parent eac76c9a50
commit a8a8d11f22
28 changed files with 189 additions and 118 deletions

View File

@@ -19,6 +19,7 @@
// Other Libs
#include <SOIL.h>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -28,7 +29,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void Do_Movement();
GLuint loadTexture(GLchar* path);
GLuint loadTexture(GLchar const * path);
// Camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
@@ -156,8 +157,8 @@ int main()
glBindVertexArray(0);
// Load textures
GLuint cubeTexture = loadTexture("../../../resources/textures/marble.jpg");
GLuint floorTexture = loadTexture("../../../resources/textures/metal.png");
GLuint cubeTexture = loadTexture(FileSystem::getPath("resources/textures/marble.jpg").c_str());
GLuint floorTexture = loadTexture(FileSystem::getPath("resources/textures/metal.png").c_str());
#pragma endregion
// Game loop
@@ -213,7 +214,7 @@ int main()
// This function loads a texture from file. Note: texture loading functions like these are usually
// managed by a 'Resource Manager' that manages all resources (like textures, models, audio).
// For learning purposes we'll just define it as a utility function.
GLuint loadTexture(GLchar* path)
GLuint loadTexture(GLchar const * path)
{
//Generate texture ID and load texture data
GLuint textureID;

View File

@@ -15,6 +15,8 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -67,8 +69,8 @@ int main()
Shader instanceShader("instanced_asteroids.vs", "instanced_asteroids.frag");
// Load models
Model rock("../../../resources/objects/rock/rock.obj");
Model planet("../../../resources/objects/planet/planet.obj");
Model rock(FileSystem::getPath("resources/objects/rock/rock.obj").c_str());
Model planet(FileSystem::getPath("resources/objects/planet/planet.obj").c_str());
// Set projection matrix
glm::mat4 projection = glm::perspective(45.0f, (GLfloat)screenWidth/(GLfloat)screenHeight, 1.0f, 10000.0f);

View File

@@ -19,6 +19,7 @@
// Other Libs
#include <SOIL.h>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -28,7 +29,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void Do_Movement();
GLuint loadTexture(GLchar* path);
GLuint loadTexture(GLchar const * path);
// Camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
@@ -160,8 +161,8 @@ int main()
glBindVertexArray(0);
// Load textures
GLuint cubeTexture = loadTexture("../../../resources/textures/marble.jpg");
GLuint floorTexture = loadTexture("../../../resources/textures/metal.png");
GLuint cubeTexture = loadTexture(FileSystem::getPath("resources/textures/marble.jpg").c_str());
GLuint floorTexture = loadTexture(FileSystem::getPath("resources/textures/metal.png").c_str());
#pragma endregion
// Game loop
@@ -260,7 +261,7 @@ void DrawScene()
// This function loads a texture from file. Note: texture loading functions like these are usually
// managed by a 'Resource Manager' that manages all resources (like textures, models, audio).
// For learning purposes we'll just define it as a utility function.
GLuint loadTexture(GLchar* path)
GLuint loadTexture(GLchar const * path)
{
//Generate texture ID and load texture data
GLuint textureID;

View File

@@ -19,6 +19,7 @@
// Other Libs
#include <SOIL.h>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -28,7 +29,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void Do_Movement();
GLuint loadTexture(GLchar* path, GLboolean alpha = false);
GLuint loadTexture(GLchar const * path, GLboolean alpha = false);
// Camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
@@ -177,9 +178,9 @@ int main()
glBindVertexArray(0);
// Load textures
GLuint cubeTexture = loadTexture("../../../resources/textures/marble.jpg");
GLuint floorTexture = loadTexture("../../../resources/textures/metal.png");
GLuint transparentTexture = loadTexture("../../../resources/textures/grass.png", true);
GLuint cubeTexture = loadTexture(FileSystem::getPath("resources/textures/marble.jpg").c_str());
GLuint floorTexture = loadTexture(FileSystem::getPath("resources/textures/metal.png").c_str());
GLuint transparentTexture = loadTexture(FileSystem::getPath("resources/textures/grass.png").c_str(), true);
#pragma endregion
std::vector<glm::vec3> vegetation;
@@ -252,7 +253,7 @@ int main()
// This function loads a texture from file. Note: texture loading functions like these are usually
// managed by a 'Resource Manager' that manages all resources (like textures, models, audio).
// For learning purposes we'll just define it as a utility function.
GLuint loadTexture(GLchar* path, GLboolean alpha)
GLuint loadTexture(GLchar const * path, GLboolean alpha)
{
//Generate texture ID and load texture data
GLuint textureID;

View File

@@ -20,6 +20,7 @@
// Other Libs
#include <SOIL.h>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -29,7 +30,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void Do_Movement();
GLuint loadTexture(GLchar* path, GLboolean alpha = false);
GLuint loadTexture(GLchar const * path, GLboolean alpha = false);
// Camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
@@ -180,9 +181,9 @@ int main()
glBindVertexArray(0);
// Load textures
GLuint cubeTexture = loadTexture("../../../resources/textures/marble.jpg");
GLuint floorTexture = loadTexture("../../../resources/textures/metal.png");
GLuint transparentTexture = loadTexture("../../../resources/textures/window.png", true);
GLuint cubeTexture = loadTexture(FileSystem::getPath("resources/textures/marble.jpg").c_str());
GLuint floorTexture = loadTexture(FileSystem::getPath("resources/textures/metal.png").c_str());
GLuint transparentTexture = loadTexture(FileSystem::getPath("resources/textures/window.png").c_str(), true);
#pragma endregion
std::vector<glm::vec3> windows;
@@ -263,7 +264,7 @@ int main()
// This function loads a texture from file. Note: texture loading functions like these are usually
// managed by a 'Resource Manager' that manages all resources (like textures, models, audio).
// For learning purposes we'll just define it as a utility function.
GLuint loadTexture(GLchar* path, GLboolean alpha)
GLuint loadTexture(GLchar const * path, GLboolean alpha)
{
//Generate texture ID and load texture data
GLuint textureID;

View File

@@ -21,6 +21,7 @@ using namespace std;
// Other Libs
#include <SOIL.h>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -30,7 +31,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void Do_Movement();
GLuint loadTexture(GLchar* path, GLboolean alpha = false);
GLuint loadTexture(GLchar const * path, GLboolean alpha = false);
GLuint generateAttachmentTexture(GLboolean depth, GLboolean stencil);
// Camera
@@ -182,8 +183,8 @@ int main()
glBindVertexArray(0);
// Load textures
GLuint cubeTexture = loadTexture("../../../resources/textures/container.jpg");
GLuint floorTexture = loadTexture("../../../resources/textures/metal.png");
GLuint cubeTexture = loadTexture(FileSystem::getPath("resources/textures/container.jpg").c_str());
GLuint floorTexture = loadTexture(FileSystem::getPath("resources/textures/metal.png").c_str());
#pragma endregion
// Framebuffers
@@ -291,7 +292,7 @@ int main()
// This function loads a texture from file. Note: texture loading functions like these are usually
// managed by a 'Resource Manager' that manages all resources (like textures, models, audio).
// For learning purposes we'll just define it as a utility function.
GLuint loadTexture(GLchar* path, GLboolean alpha)
GLuint loadTexture(GLchar const * path, GLboolean alpha)
{
//Generate texture ID and load texture data
GLuint textureID;

View File

@@ -21,6 +21,7 @@ using namespace std;
// Other Libs
#include <SOIL.h>
#include <learnopengl/filesystem.h>
// Properties
GLuint screenWidth = 800, screenHeight = 600;
@@ -30,7 +31,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void Do_Movement();
GLuint loadTexture(GLchar* path);
GLuint loadTexture(GLchar const * path);
GLuint loadCubemap(std::vector<const GLchar*> faces);
// Camera
@@ -198,12 +199,12 @@ int main()
// Cubemap (Skybox)
std::vector<const GLchar*> faces;
faces.push_back("../../../resources/textures/skybox/right.jpg");
faces.push_back("../../../resources/textures/skybox/left.jpg");
faces.push_back("../../../resources/textures/skybox/top.jpg");
faces.push_back("../../../resources/textures/skybox/bottom.jpg");
faces.push_back("../../../resources/textures/skybox/back.jpg");
faces.push_back("../../../resources/textures/skybox/front.jpg");
faces.push_back(FileSystem::getPath("resources/textures/skybox/right.jpg").c_str());
faces.push_back(FileSystem::getPath("resources/textures/skybox/left.jpg").c_str());
faces.push_back(FileSystem::getPath("resources/textures/skybox/top.jpg").c_str());
faces.push_back(FileSystem::getPath("resources/textures/skybox/bottom.jpg").c_str());
faces.push_back(FileSystem::getPath("resources/textures/skybox/back.jpg").c_str());
faces.push_back(FileSystem::getPath("resources/textures/skybox/front.jpg").c_str());
GLuint skyboxTexture = loadCubemap(faces);
// Draw as wireframe
@@ -300,7 +301,7 @@ GLuint loadCubemap(std::vector<const GLchar*> faces)
// This function loads a texture from file. Note: texture loading functions like these are usually
// managed by a 'Resource Manager' that manages all resources (like textures, models, audio).
// For learning purposes we'll just define it as a utility function.
GLuint loadTexture(GLchar* path)
GLuint loadTexture(GLchar const * path)
{
//Generate texture ID and load texture data
GLuint textureID;