diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2438dcd Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 6e7349f..78428e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .vs out +build + *.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2239a30..c9b04d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ if(WIN32) set(EXPOSE_OPENGL OFF CACHE BOOL "If you want to use raw OpenGL functions in your app (e.g. to use ImGui) check this") endif() -if(${build_documentation}) +if(${BUILD_DOCUMENTATION}) find_package(Doxygen REQUIRED) endif() @@ -49,7 +49,7 @@ target_include_directories(openglu PUBLIC vendor/include ) -if(${build_documentation}) +if(${BUILD_DOCUMENTATION}) configure_file(doxyfile.in ${CMAKE_BINARY_DIR}/doxyfile @ONLY) add_custom_target(openglu_doc ALL COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxyfile" @@ -58,7 +58,7 @@ if(${build_documentation}) ) endif() -if(${build_examples}) +if(${BUILD_EXAMPLES}) macro(subdirlist result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) set(dirlist "") diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000..326a155 Binary files /dev/null and b/examples/.DS_Store differ diff --git a/examples/debug/CMakeLists.txt b/examples/debug/CMakeLists.txt index a48be0d..dcdeb24 100644 --- a/examples/debug/CMakeLists.txt +++ b/examples/debug/CMakeLists.txt @@ -7,12 +7,26 @@ target_include_directories(debug PRIVATE ) target_link_libraries(debug PRIVATE - "$/$.lib" glfw ) +if(WIN32) + target_link_libraries(debug PRIVATE + "$/$.lib" + ) +else() + target_link_libraries(debug PRIVATE + $ + ) +endif() + add_custom_command(TARGET debug POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ $ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shaders $/shaders COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $/assets -) \ No newline at end of file +) + +if(WIN32) + add_custom_command(TARGET debug POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif() \ No newline at end of file diff --git a/examples/debug/main.cpp b/examples/debug/main.cpp index 30f368b..b086498 100644 --- a/examples/debug/main.cpp +++ b/examples/debug/main.cpp @@ -118,8 +118,8 @@ int main(int argc, char** argv) camera.LookAt(0.0f, 0.0f, 0.0f); shader->Use(); - shader->SetUniform("texture1", crate, 0); - shader->SetUniform("texture2", opengl, 1); + shader->SetUniformTexture("texture1", crate, 0); + shader->SetUniformTexture("texture2", opengl, 1); shader->SetUniform("model", square); shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(camera.GetMatrix())); shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(camera.GetProjection())); diff --git a/examples/movement/CMakeLists.txt b/examples/movement/CMakeLists.txt index 80b1081..e57babf 100644 --- a/examples/movement/CMakeLists.txt +++ b/examples/movement/CMakeLists.txt @@ -14,12 +14,26 @@ target_include_directories(movement PRIVATE ) target_link_libraries(movement PRIVATE - "$/$.lib" glfw ) +if(WIN32) + target_link_libraries(movement PRIVATE + "$/$.lib" + ) +else() + target_link_libraries(movement PRIVATE + $ + ) +endif() + add_custom_command(TARGET movement POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ $ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shaders $/shaders COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $/assets -) \ No newline at end of file +) + +if(WIN32) + add_custom_command(TARGET movement POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif() \ No newline at end of file diff --git a/examples/movement/main.cpp b/examples/movement/main.cpp index 9669111..e8155fb 100644 --- a/examples/movement/main.cpp +++ b/examples/movement/main.cpp @@ -220,8 +220,8 @@ int main(int argc, char** argv) ImGui::NewFrame(); shader->Use(); - shader->SetUniform("texture1", crate, 0); - shader->SetUniform("texture2", opengl, 1); + shader->SetUniformTexture("texture1", crate, 0); + shader->SetUniformTexture("texture2", opengl, 1); shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(camera.GetMatrix())); shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(camera.GetProjection())); diff --git a/include/shader.hpp b/include/shader.hpp index 91d13ab..8325df5 100644 --- a/include/shader.hpp +++ b/include/shader.hpp @@ -19,6 +19,10 @@ namespace oglu typedef std::shared_ptr Texture; + class AbstractShader; + + typedef std::shared_ptr Shader; + /** * @brief An object representing an OpenGL Shader Program. * @@ -40,7 +44,7 @@ namespace oglu * * @return A shared pointer to the shader program. */ - friend std::shared_ptr OGLU_API MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile); + friend Shader OGLU_API MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile); /** * @brief Copy constructor. @@ -294,7 +298,7 @@ namespace oglu * @param[in] v0 Value to set the uniform to * @param[in] index Index of the texture unit */ - void SetUniform(const GLchar* name, const Texture& v0, GLbyte index = 0); + void SetUniformTexture(const GLchar* name, const Texture& v0, GLbyte index = 0); /** * @brief Set uniform color. @@ -308,7 +312,7 @@ namespace oglu * @param[in] v0 Value to set the uniform to * @param[in] index Index of the texture unit */ - void SetUniform(GLint location, const Texture& v0, GLbyte index = 0); + void SetUniformTexture(GLint location, const Texture& v0, GLbyte index = 0); /** * @brief Set uniform mat4. @@ -318,6 +322,7 @@ namespace oglu * * @param[in] name Name of the uniform * @param[in] v0 Value to set the uniform to + * @param[in] transpose Transpose matrix before setting the uniform */ void SetUniform(const GLchar* name, Transformable& v0, GLboolean transpose = GL_FALSE); @@ -329,6 +334,7 @@ namespace oglu * * @param[in] location Location of the uniform * @param[in] v0 Value to set the uniform to + * @param[in] transpose Transpose matrix before setting the uniform */ void SetUniform(GLint location, Transformable& v0, GLboolean transpose = GL_FALSE); @@ -754,7 +760,7 @@ namespace oglu GLuint program; ///< Handle to the Shader program }; - typedef std::shared_ptr Shader; + Shader OGLU_API MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile); } #endif \ No newline at end of file diff --git a/include/texture.hpp b/include/texture.hpp index 31afb5e..5883197 100644 --- a/include/texture.hpp +++ b/include/texture.hpp @@ -21,6 +21,10 @@ namespace oglu */ void OGLU_API ActiveTexture(GLubyte index); + class AbstractTexture; + + typedef std::shared_ptr Texture; + /** * @brief An object representing an OpenGL Texture. * @@ -41,7 +45,7 @@ namespace oglu * * @return A shared pointer to the texture. */ - friend std::shared_ptr OGLU_API MakeTexture(const char* filename); + friend Texture OGLU_API MakeTexture(const char* filename); /** * @brief Copy constructor. @@ -93,7 +97,7 @@ namespace oglu GLuint texture; ///< OpenGL handle to the texture }; - typedef std::shared_ptr Texture; + Texture OGLU_API MakeTexture(const char* filename); } #endif \ No newline at end of file diff --git a/include/vertexArray.hpp b/include/vertexArray.hpp index 40e6c27..bab315c 100644 --- a/include/vertexArray.hpp +++ b/include/vertexArray.hpp @@ -27,6 +27,10 @@ namespace oglu /*@}*/ }; + class AbstractVertexArray; + + typedef std::shared_ptr VertexArray; + /** * @brief An object representing an OpenGL VAO. * @@ -52,7 +56,7 @@ namespace oglu * * @return A shared pointer to the texture. */ - friend std::shared_ptr OGLU_API MakeVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize); + friend VertexArray OGLU_API MakeVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize); /** * @brief Constructs a new VAO. @@ -61,7 +65,7 @@ namespace oglu * * @param[in] filepath Path to the .obj file */ - friend std::shared_ptr OGLU_API MakeVertexArray(const char* filepath); + friend VertexArray OGLU_API MakeVertexArray(const char* filepath); /** * @brief Copy constructor. @@ -127,7 +131,8 @@ namespace oglu GLsizei count; ///< Amount of indices }; - typedef std::shared_ptr VertexArray; + VertexArray OGLU_API MakeVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize); + VertexArray OGLU_API MakeVertexArray(const char* filepath); } #endif diff --git a/src/object.cpp b/src/object.cpp index 8980081..cff1799 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -2,9 +2,10 @@ namespace oglu { - Object::Object(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize) : - VAO(MakeVertexArray(vertices, verticesSize, indices, indicesSize, topology, topologySize)) + Object::Object(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize) //: + // VAO(MakeVertexArray(vertices, verticesSize, indices, indicesSize, topology, topologySize)) { + VAO = MakeVertexArray(vertices, verticesSize, indices, indicesSize, topology, topologySize); } Object::Object(const VertexArray& vao) : diff --git a/src/shader.cpp b/src/shader.cpp index 03f88de..5bfc247 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -238,12 +238,12 @@ namespace oglu glUniform4f(location, v0.r, v0.g, v0.b, v0.a); } - void AbstractShader::SetUniform(const GLchar* name, const Texture& v0, GLbyte index) + void AbstractShader::SetUniformTexture(const GLchar* name, const Texture& v0, GLbyte index) { - SetUniform(glGetUniformLocation(program, name), v0, index); + SetUniformTexture(glGetUniformLocation(program, name), v0, index); } - void AbstractShader::SetUniform(GLint location, const Texture& v0, GLbyte index) + void AbstractShader::SetUniformTexture(GLint location, const Texture& v0, GLbyte index) { v0->BindAs(index); glUniform1i(location, index);