-
#include <bgfx.h>
#include <SDL3/SDL.h>
#include <stdio.h>
int main(){
printf("checkpoint A\n");
if(!SDL_Init(SDL_INIT_VIDEO)){
printf("sdl init error");
return 1;
}
SDL_Window* window = SDL_CreateWindow("SDL3 and BGFX and VULKAN", 1280, 720, SDL_WINDOW_VULKAN);
if(window == NULL){
printf("window error");
return 1;
}
bgfx_platform_data_t pd;
printf("::%s\n", SDL_GetCurrentVideoDriver());
pd.ndt = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
pd.nwh = (void*) SDL_GetNumberProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx_set_platform_data(&pd);
bgfx_init_t init;
init.type = BGFX_RENDERER_TYPE_VULKAN;
init.vendorId = BGFX_PCI_ID_NONE;
init.platformData.nwh = pd.nwh;
init.platformData.ndt = pd.ndt;
init.resolution.width = 1280;
init.resolution.height = 720;
printf("checkpoint B\n");
bgfx_init(&init);
printf("checkpoint C\n");
bgfx_set_debug(BGFX_DEBUG_TEXT);
bgfx_set_view_clear( 0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030FF, 1.0f, 0 );
bool exit = false;
SDL_Event event;
int counter = 0;
while(!exit){
bgfx_set_view_rect(0, 0, 0, 1280, 720);
bgfx_touch(0);
bgfx_dbg_text_clear(0, false);
bgfx_dbg_text_printf(0,1,0x4f, "Counter: %d", counter);
counter++;
bgfx_frame(false);
while(SDL_PollEvent(&event)){
switch(event.type){
case SDL_EVENT_QUIT:
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
exit = true;
break;
}
}
}
} $ gcc test.c -o bin/test2 bin/libbgfx.so -lSDL3 -Ilib/bgfx/include/bgfx/c99 -Ilib/bx/include -Ilib/bimg/include
$ bin/test2
checkpoint A
::x11
checkpoint B
Segmentation fault (core dumped)
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Perhaps you defined the init variable with the wrong type: |
Beta Was this translation helpful? Give feedback.
-
I missed |
Beta Was this translation helpful? Give feedback.
I missed
bgfx_init_ctor(&init);
It is not mention in API docs.
It is mentioned in C99 example but it is a needle in the sea (haystack) of C++ example so I missed when I looked for it early.