From 01d4548988eff9726fd0078bf262338e86a63e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katharina=20Kr=C3=A4mer?= <kkraemer4@uni-koblenz.de> Date: Tue, 13 Jul 2021 17:27:30 +0200 Subject: [PATCH] [#94] worked on texture loading --- projects/saf_r/CMakeLists.txt | 4 ++-- projects/saf_r/src/main.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/saf_r/CMakeLists.txt b/projects/saf_r/CMakeLists.txt index a9dbbd77..401c611d 100644 --- a/projects/saf_r/CMakeLists.txt +++ b/projects/saf_r/CMakeLists.txt @@ -23,7 +23,7 @@ if(MSVC) endif() # including headers of dependencies and the VkCV framework -target_include_directories(saf_r SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include}) +target_include_directories(saf_r SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_asset_loader_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include}) # linking with libraries from all dependencies and the VkCV framework -target_link_libraries(saf_r vkcv vkcv_testing vkcv_camera vkcv_shader_compiler) +target_link_libraries(saf_r vkcv vkcv_testing vkcv_asset_loader ${vkcv_asset_loader_libraries} vkcv_camera vkcv_shader_compiler) diff --git a/projects/saf_r/src/main.cpp b/projects/saf_r/src/main.cpp index a9864c7f..d683a01b 100644 --- a/projects/saf_r/src/main.cpp +++ b/projects/saf_r/src/main.cpp @@ -2,6 +2,7 @@ #include <vkcv/Core.hpp> #include <GLFW/glfw3.h> #include <vkcv/camera/CameraManager.hpp> +#include <vkcv/asset/asset_loader.hpp> #include <vkcv/shader/GLSLCompiler.hpp> #include <chrono> #include <limits> @@ -11,8 +12,6 @@ #include <vector> #include <glm/glm.hpp> -#define STB_IMAGE_IMPLEMENTATION - struct Light { Light(const glm::vec3 &p, const float &i) : position(p), intensity(i) {} @@ -113,9 +112,11 @@ void render(const std::vector<Sphere> &spheres, const std::vector<Light> &lights } } + std::vector<int> img; std::ofstream ofs; // save the framebuffer to file ofs.open(path + "./texture.ppm"); ofs << "P3\n" << width << " " << height << "\n255\n"; + for (size_t i = 0; i < height*width; ++i) { glm::vec3 &c = framebuffer[i]; float max = std::max(c[0], std::max(c[1], c[2])); @@ -152,13 +153,12 @@ int main(int argc, const char** argv) { { "VK_KHR_swapchain" } ); - /* - const void* data = NULL; + vkcv::asset::TextureData texData = vkcv::asset::loadTexture("textures/texture.ppm"); vkcv::Image texture = core.createImage(vk::Format::eR8G8B8A8Srgb, 800, 600); - texture.fill(data); + texture.fill( texData.data.data()); texture.generateMipChainImmediate(); texture.switchLayout(vk::ImageLayout::eShaderReadOnlyOptimal); - */ + const auto& context = core.getContext(); -- GitLab