Window creation

Creating the window

So now that the Core is created and the required extensions and features are selected, the application can start becoming visual. Because the goal is to draw a triangle and that will need some kind of surface to present the triangle on. Therefore a window needs to be created:

const int windowWidth = 800;
const int windowHeight = 600;
const bool isWindowResizable = false; // for our goal resizing is not necessary

vkcv::WindowHandle windowHandle = core.createWindow(
  applicationName,  // reuse the application name as title of the window
  windowWidth,      // initial width of the window
  windowHeight,     // intiial height of the window
  isWindowResizable // whether the window can be resized by the user
);

So that's it. The window is created and can be used. However you might have noticed that the code states it has created a window handle. What's a handle?


Handles

In the VkCV framework most resources will be provided and used as handles. You can think of handles as identifiers without any own methods or functionality. However you can copy, reference or store them in memory as you like without causing any segmentation faults or access violations well known to C++ developers. Because in the background the framework will take care of all the memory and actual objects to make the handle work as intended.

So in most cases you will just write code using those handles and pass them to methods from the Core instance. The benefit is the automatic memory management you would usually need to write on your own with the Vulkan resources and more. In the framework all resources linked to such a handle will automatically be set free once you have no active references left in scope to the handle.


Using the window

As mentioned handles don't have any own functionality by their own. So how do you use the window handle to get the current title or resolution for example since it could be resizable?

vkcv::Window& window = core.getWindow(windowHandle);

// Print the title and its current size:
std::cout << window.getTitle() << std::endl;
std::cout << window.getWidth() << ", "
          << window.getHeight() << std::endl;

In this code example the standard output stream will be used to print information as text.

Previous

Next

Popular posts from this blog

Introduction

Application development

First setup