I am trying to init Vulkan on Linux. I do pass SDL_WINDOW_VULKAN
flag to SDL_CreateWindow
and call to SDL_Vulkan_GetInstanceExtensions
fails with error "The specified window isn't a Vulkan window".
I cannot find any specific info on what is the cause of this error, because in sources of SDL2 the cause of this error message is absence of SDL_WINDOW_VULKAN
flag. See SDL_video.c#L4810 and SDL_video.c#L4830.
I have tried to create a Vulkan window with GLFW and it worked just fine.
I expect that Vulkan window should be possible to create with SDL2 as well.
Code to repro.
Makefile:
CC=gcc
CFLAGS= -c -g -Wall
LDLIBS= -lvulkan -lSDL2
all: prog
prog: app.o
$(CC) $(LDLIBS) app.o -o app
app.o: app.c
$(CC) $(CFLAGS) app.c
clean:
rm -rf *.o
app.c:
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <vulkan/vulkan.h>
int main()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Window* win = SDL_CreateWindow("Hello World!", 100, 100, 620, 387, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN);
if (win == NULL) {
fprintf(stderr, "ERROR: Failed to create window. %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Surface *surface = SDL_GetWindowSurface(win);
if (!surface) {
fprintf(stderr, "ERROR: Failed to get window surface. %s\n", SDL_GetError());
return EXIT_FAILURE;
}
unsigned int count = 0;
bool ret = SDL_Vulkan_GetInstanceExtensions(win, &count, NULL);
if (!ret) {
fprintf(stderr, "ERROR: Failed to get instance extensions count. %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Event event = {0};
bool quit = false;
while (!quit) {
while(SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
break;
}
if (event.type == SDL_KEYDOWN) {
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
quit = true;
break;
default:
break;
}
}
}
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255, 90, 120));
SDL_UpdateWindowSurface(win);
}
SDL_DestroyWindow(win);
SDL_Quit();
return EXIT_SUCCESS;
}