Application development

Environment

The main purpose of the VkCV framework is to ease application development. But how would you start once your IDE is all setup? First of all, here is the general directory structure of the framework and what the specific folders contain:

  • config/ - CMake configuration and custom functions for the build process
  • doc/ - All sorts of documentation
  • include/ - The headers of the VkCV framework API
  • lib/ - The dependencies of the framework as submodules
  • modules/ - All current modules provided by the framework itself
  • projects - The example application using the framework and its modules
  • resources/ - The list with the recommended extensions for example
  • scripts/ - Useful shell/bash scripts to interact with the command line
  • src/ - The source code of the framework

Generation

As you might have noticed the subdirectory called "projects" contains all example applications and it is easiest to create a new application in there integrated into the existing build process with CMake. All you need to do is to run the following script from a terminal inside the frameworks directory and pass the new projects location as parameter (in this example "projects/my_application"):

./scripts/generate.sh projects/my_application

After that open the "CMakeLists" file in the projects subdirectory and add another line similar to the other ones in there containing your project's name (in the example here "my_application"). The line should look like this:

add_subdirectory(my_application)

You should notice that all the lines in there just add other projects as subdirectories for the overall build configuration in CMake. The actual build for your project can be configured in the generated "CMakeLists.txt" inside the new folder generated for your project (in this example "my_application"). The file should look similar to this:

cmake_minimum_required(VERSION 3.16)
project(my_application)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(my_application src/main.cpp)

target_include_directories(my_application SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes})
target_link_libraries(my_application vkcv ${vkcv_libraries})

It will also contain a "src" subdirectory with a generated "main.cpp" file to create and show an empty window. If you follow the next parts you will learn to understand that code. But it should look similar to this:

#include <vkcv/Core.hpp>

int main(int argc, const char** argv) {
  vkcv::Core core = vkcv::Core::create(
    "my_application",
    VK_MAKE_VERSION(0, 0, 1),
    { vk::QueueFlagBits::eTransfer,vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute },
    { VK_KHR_SWAPCHAIN_EXTENSION_NAME }
  );
  
  vkcv::WindowHandle windowHandle = core.createWindow(
    "my_application",
    800,
    600,
    true
  );
  
  while (vkcv::Window::hasOpenWindow()) {
    vkcv::Window::pollEvents();
  }
}

Runtime

You should now be able to build and run the generated new project. Depending on your IDE, select your new project as launch target and start it to build it automatically or build the project manually to run it afterwards. Your project's build target and launch target should have the same name as its generated folder (so that will be "my_application" in this example).


In case your project won't build for an unknown reason. There has been a potential issue with the CMake configuration at times. This caused the projects to not build even if that should be enabled. In that case only the framework will build or only that and its modules. So what you can do is enforce to build projects anyway with the framework by going in the "CMakeLists.txt" file in the top directory of the framework. You will find following lines after the cmake options:

# uncomment the following line if cmake will refuse to build projects
#set(BUILD_PROJECTS ON)

Uncommenting the line to set the variable BUILD_PROJECTS to ON should do the trick and the example projects as well as your new generated project should finally build without issues. Hopefully this won't be necessary.


Once your application launches, an empty window should appear with your application's name as its title. You can think of this as your little "Hello world" project with the VkCV framework.

Previous

Next

Popular posts from this blog

Introduction

First setup