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 "vec.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <SDL_log.h>
|
||||||
|
#include <SDL_video.h>
|
||||||
#include <SDL_vulkan.h>
|
#include <SDL_vulkan.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.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() {
|
int main() {
|
||||||
vector *vec = vec_create(sizeof(int));
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
for (int x = 0; x < 110; x++) {
|
printf("Failed to initialize the SDL2 library\n");
|
||||||
vec_push_back(vec, &x);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
int i = 99999999;
|
SDL_Vulkan_LoadLibrary(NULL);
|
||||||
vec_insert(vec, &i, 5);
|
SDL_Window *window = SDL_CreateWindow(
|
||||||
vec_push_front(vec, &i);
|
"SDL2 Vulkan Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 680,
|
||||||
printf("Capacity before shrink: %zu | ", vec_capacity(vec));
|
480, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN);
|
||||||
vec_shrink_to_fit(vec);
|
if (!window) {
|
||||||
printf("Capacity after: %zu\n", vec_capacity(vec));
|
printf("Failed to create window\n");
|
||||||
vec_erase(vec, 0);
|
return EXIT_FAILURE;
|
||||||
vec_erase(vec, 101);
|
|
||||||
for (int x = 0; x < 110; x++) {
|
|
||||||
printf("%d ", *(int *)vec_get(vec, x));
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
vec_destroy(vec);
|
|
||||||
|
|
||||||
// if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
initVulkan(window);
|
||||||
// printf("Failed to initialize the SDL2 library\n");
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// SDL_Window *window =
|
bool running = true;
|
||||||
// SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_CENTERED,
|
while (running) {
|
||||||
// SDL_WINDOWPOS_CENTERED, 680, 480, SDL_WINDOW_VULKAN);
|
SDL_Event input;
|
||||||
// if (!window) {
|
while (SDL_PollEvent(&input) > 0) {
|
||||||
// printf("Failed to create window\n");
|
if (input.type == SDL_QUIT) {
|
||||||
// return -1;
|
running = false;
|
||||||
// }
|
}
|
||||||
|
switch (input.type) {
|
||||||
// SDL_Surface *window_surface = SDL_GetWindowSurface(window);
|
case SDL_QUIT:
|
||||||
// if (!window_surface) {
|
running = false;
|
||||||
// printf("Failed to get the surface from the window\n");
|
case SDL_KEYDOWN: {
|
||||||
// return -1;
|
const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
||||||
// }
|
if (keys[SDL_SCANCODE_ESCAPE])
|
||||||
|
running = false;
|
||||||
// bool running = true;
|
}
|
||||||
// while (running) {
|
}
|
||||||
// SDL_Event input;
|
}
|
||||||
// while (SDL_PollEvent(&input) > 0) {
|
}
|
||||||
// if (input.type == SDL_QUIT) {
|
SDL_DestroyWindow(window);
|
||||||
// running = false;
|
SDL_Quit();
|
||||||
// }
|
return EXIT_SUCCESS;
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,3 +101,8 @@ size_t vec_capacity(vector *vec) {
|
||||||
assert(vec != NULL);
|
assert(vec != NULL);
|
||||||
return vec->capacity;
|
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);
|
void *vec_get(vector *vec, uint index);
|
||||||
size_t vec_size(vector *vec);
|
size_t vec_size(vector *vec);
|
||||||
size_t vec_capacity(vector *vec);
|
size_t vec_capacity(vector *vec);
|
||||||
|
void* vec_data(vector *vec);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue