|
|
@@ -0,0 +1,56 @@ |
|
|
|
#include <png.h> |
|
|
|
#include <vulkan/vulkan.h> |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
const uint32_t kWidth = 16; |
|
|
|
const uint32_t kHeight = 16; |
|
|
|
|
|
|
|
int main() { |
|
|
|
// Example code for creating a VkInstance. |
|
|
|
VkApplicationInfo app_info = {}; |
|
|
|
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
|
|
|
app_info.apiVersion = VK_API_VERSION_1_1; |
|
|
|
|
|
|
|
VkInstanceCreateInfo create_info = {}; |
|
|
|
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
|
|
|
create_info.pApplicationInfo = &app_info; |
|
|
|
create_info.enabledExtensionCount = 0; |
|
|
|
create_info.ppEnabledExtensionNames = nullptr; |
|
|
|
create_info.enabledLayerCount = 0; |
|
|
|
create_info.ppEnabledLayerNames = nullptr; |
|
|
|
|
|
|
|
VkInstance instance; |
|
|
|
VkResult res = vkCreateInstance(&create_info, nullptr, &instance); |
|
|
|
if (res != VK_SUCCESS) { |
|
|
|
std::cerr << "Error creating VkInstance: " << res; |
|
|
|
} |
|
|
|
|
|
|
|
// Example code for exporting a PNG. |
|
|
|
FILE *f = fopen("triangle.png", "wb"); |
|
|
|
|
|
|
|
std::vector<uint8_t> pixels(kWidth * kHeight * 4); |
|
|
|
for (size_t i = 0; i < kHeight; i++) { |
|
|
|
for (size_t j = 0; j < kWidth; j++) { |
|
|
|
uint32_t base_index = (i * kWidth * 4) + (j * 4); |
|
|
|
pixels[base_index] = 255; |
|
|
|
pixels[base_index + 1] = 255; |
|
|
|
pixels[base_index + 2] = 0; |
|
|
|
pixels[base_index + 3] = 255; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
png_image image_info = {}; |
|
|
|
image_info.version = PNG_IMAGE_VERSION; |
|
|
|
image_info.width = kWidth; |
|
|
|
image_info.height = kHeight; |
|
|
|
image_info.format = PNG_FORMAT_RGBA; |
|
|
|
if (png_image_write_to_stdio(&image_info, f, 0, pixels.data(), kWidth * 4, nullptr) == 0) { |
|
|
|
std::cout << "Error writing PNG: " << image_info.message << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
fclose(f); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |