Starting to move into setting up vulkan
This commit is contained in:
parent
02d792ab12
commit
5076e4609a
3 changed files with 78 additions and 53 deletions
125
src/main.c
125
src/main.c
|
|
@ -1,65 +1,84 @@
|
|||
#include "vec.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_log.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL_vulkan.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
VkInstance create_instance(SDL_Window *window) {
|
||||
VkApplicationInfo app_info;
|
||||
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
app_info.pApplicationName = "Hello Triangle";
|
||||
app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
app_info.pEngineName = "No Engine";
|
||||
app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
app_info.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
uint32_t sdl_extension_count = 0;
|
||||
const char **sdl_extensions;
|
||||
if (!SDL_Vulkan_GetInstanceExtensions(window, &sdl_extension_count,
|
||||
sdl_extensions)) {
|
||||
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
|
||||
printf("Couldn't get required Vulkan Extentions for window\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
VkInstanceCreateInfo create_info;
|
||||
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
create_info.pApplicationInfo = &app_info;
|
||||
create_info.enabledExtensionCount = sdl_extension_count;
|
||||
create_info.ppEnabledExtensionNames = sdl_extensions;
|
||||
create_info.enabledLayerCount = 0;
|
||||
|
||||
VkInstance instance;
|
||||
if (vkCreateInstance(&create_info, NULL, &instance)) {
|
||||
printf("failed to create vulkan instance!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void initVulkan(SDL_Window *window) { create_instance(window); }
|
||||
|
||||
int main() {
|
||||
vector *vec = vec_create(sizeof(int));
|
||||
for (int x = 0; x < 110; x++) {
|
||||
vec_push_back(vec, &x);
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("Failed to initialize the SDL2 library\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int i = 99999999;
|
||||
vec_insert(vec, &i, 5);
|
||||
vec_push_front(vec, &i);
|
||||
printf("Capacity before shrink: %zu | ", vec_capacity(vec));
|
||||
vec_shrink_to_fit(vec);
|
||||
printf("Capacity after: %zu\n", vec_capacity(vec));
|
||||
vec_erase(vec, 0);
|
||||
vec_erase(vec, 101);
|
||||
for (int x = 0; x < 110; x++) {
|
||||
printf("%d ", *(int *)vec_get(vec, x));
|
||||
SDL_Vulkan_LoadLibrary(NULL);
|
||||
SDL_Window *window = SDL_CreateWindow(
|
||||
"SDL2 Vulkan Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 680,
|
||||
480, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN);
|
||||
if (!window) {
|
||||
printf("Failed to create window\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("\n");
|
||||
vec_destroy(vec);
|
||||
|
||||
// if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
// printf("Failed to initialize the SDL2 library\n");
|
||||
// return -1;
|
||||
// }
|
||||
initVulkan(window);
|
||||
|
||||
// SDL_Window *window =
|
||||
// SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_CENTERED,
|
||||
// SDL_WINDOWPOS_CENTERED, 680, 480, SDL_WINDOW_VULKAN);
|
||||
// if (!window) {
|
||||
// printf("Failed to create window\n");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// SDL_Surface *window_surface = SDL_GetWindowSurface(window);
|
||||
// if (!window_surface) {
|
||||
// printf("Failed to get the surface from the window\n");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// bool running = true;
|
||||
// while (running) {
|
||||
// SDL_Event input;
|
||||
// while (SDL_PollEvent(&input) > 0) {
|
||||
// if (input.type == SDL_QUIT) {
|
||||
// running = false;
|
||||
// }
|
||||
// switch (input.type) {
|
||||
// case SDL_QUIT:
|
||||
// running = false;
|
||||
// case SDL_KEYDOWN: {
|
||||
// const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
||||
// if (keys[SDL_SCANCODE_ESCAPE])
|
||||
// running = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// SDL_UpdateWindowSurface(window);
|
||||
bool running = true;
|
||||
while (running) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input) > 0) {
|
||||
if (input.type == SDL_QUIT) {
|
||||
running = false;
|
||||
}
|
||||
switch (input.type) {
|
||||
case SDL_QUIT:
|
||||
running = false;
|
||||
case SDL_KEYDOWN: {
|
||||
const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
||||
if (keys[SDL_SCANCODE_ESCAPE])
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,3 +101,8 @@ size_t vec_capacity(vector *vec) {
|
|||
assert(vec != NULL);
|
||||
return vec->capacity;
|
||||
}
|
||||
|
||||
void* vec_data(vector *vec) {
|
||||
assert(vec != NULL);
|
||||
return vec->elements;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,3 +22,4 @@ void vec_pop_back(vector *vec);
|
|||
void *vec_get(vector *vec, uint index);
|
||||
size_t vec_size(vector *vec);
|
||||
size_t vec_capacity(vector *vec);
|
||||
void* vec_data(vector *vec);
|
||||
|
|
|
|||
Loading…
Reference in a new issue