diff options
| author | realtradam <[email protected]> | 2023-01-03 02:09:17 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-01-03 02:09:17 -0500 |
| commit | e38a5adeccdde8def46b6aa03d99d0b16bf15a60 (patch) | |
| tree | 4b208bd6bd33d9379c9cd889a6f7e11f89ed44ac | |
| parent | a7473499c197835fd49f040bda89b91176418bb0 (diff) | |
| download | RodeoKit-e38a5adeccdde8def46b6aa03d99d0b16bf15a60.tar.gz RodeoKit-e38a5adeccdde8def46b6aa03d99d0b16bf15a60.zip | |
working bgfx and SDL integration
| -rw-r--r-- | .gitmodules | 9 | ||||
| -rw-r--r-- | .vimrc | 2 | ||||
| -rw-r--r-- | CMakeLists.txt | 21 | ||||
| m--------- | external/bgfx | 0 | ||||
| m--------- | external/bimg | 0 | ||||
| m--------- | external/bx | 0 | ||||
| -rw-r--r-- | src/compile_flags.txt | 2 | ||||
| -rw-r--r-- | src/main.c | 66 | ||||
| -rw-r--r-- | src/rodeo.c | 125 | ||||
| -rw-r--r-- | src/rodeo.h | 42 |
10 files changed, 213 insertions, 54 deletions
diff --git a/.gitmodules b/.gitmodules index 993223c..d15c2d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,12 @@ [submodule "external/SDL"] path = external/SDL url = https://github.com/libsdl-org/SDL.git +[submodule "external/bx"] + path = external/bx + url = https://github.com/bkaradzic/bx.git +[submodule "external/bimg"] + path = external/bimg + url = https://github.com/bkaradzic/bimg.git +[submodule "external/bgfx"] + path = external/bgfx + url = https://github.com/bkaradzic/bgfx.git @@ -0,0 +1,2 @@ +" press F5 to compile and execute the project code +map <f5> :AsyncRun -save=1 -cwd=<root> ./build ; ./run <CR> diff --git a/CMakeLists.txt b/CMakeLists.txt index c771530..fb32fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,11 @@ cmake_minimum_required(VERSION 3.25.1) +include(ExternalProject) project(space_squad) file(GLOB SOURCES "src/main.c" - "src/lib/lib.c" + "src/rodeo.c" ) #add_library(lib src/lib.c) @@ -13,16 +14,34 @@ add_executable(${PROJECT_NAME} ${SOURCES}) add_subdirectory(external/SDL) +ExternalProject_Add(project_bgfx + #BUILD_IN_SOURCE true # this just doesn't work + SOURCE_DIR "external/bgfx" + BINARY_DIR "../external/bgfx" + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND "" + #BUILD_ALWAYS true + BUILD_COMMAND make linux + INSTALL_COMMAND "" + ) + + target_include_directories(${PROJECT_NAME} PUBLIC external/SDL/include + PUBLIC external/bgfx/include + PUBLIC external/bx/include ) target_link_directories(${PROJECT_NAME} PRIVATE external/SDL + PRIVATE external/bgfx ) +ExternalProject_Get_Property(project_bgfx BINARY_DIR) +#message("++" ${BINARY_DIR}) target_link_libraries(${PROJECT_NAME} SDL2::SDL2 # dynamic lib #SDL3::SDL3 # dynamic lib #SDL3::SDL3-static # static lib + ${BINARY_DIR}/.build/linux64_gcc/bin/libbgfx-shared-libRelease.so ) diff --git a/external/bgfx b/external/bgfx new file mode 160000 +Subproject 5f435ea56b29c3dd3ebdf9fab1a8f408681ff91 diff --git a/external/bimg b/external/bimg new file mode 160000 +Subproject 1395f4e969fa0aac6158fb3caf0873eaed38d77 diff --git a/external/bx b/external/bx new file mode 160000 +Subproject 340000754fe3fcf63c16841d228c33a461c335a diff --git a/src/compile_flags.txt b/src/compile_flags.txt index 268f070..90e041f 100644 --- a/src/compile_flags.txt +++ b/src/compile_flags.txt @@ -1,2 +1,4 @@ -I./ -I../external/SDL/include +-I../external/bgfx/include +-I../external/bx/include @@ -1,69 +1,29 @@ #include <stdio.h> #include <stdbool.h> -#include "lib/lib.h" #include "SDL2/SDL.h" +#include "SDL2/SDL_syswm.h" +#include "bgfx/c99/bgfx.h" -const int SCREEN_WIDTH = 640; -const int SCREEN_HEIGHT = 480; +#include "rodeo.h" + +Rodeo__Data_t _state = {0}; +Rodeo__Data_t* state = &_state; int main() { - SDL_Window* window = NULL; - - SDL_Surface* screenSurface = NULL; + Rodeo__init_window(state, 480, 640, "Rodeo Window"); - if(SDL_Init(SDL_INIT_VIDEO) < 0) - { - printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); - } - else + while(!state->quit) { - window = SDL_CreateWindow( - "SDL Tutorial", - SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, - SCREEN_WIDTH, - SCREEN_HEIGHT, - SDL_WINDOWEVENT_SHOWN - ); - if(window == NULL) - { - printf("Window could not be created! SDL_Error %s\n", SDL_GetError()); - } - else - { - screenSurface = SDL_GetWindowSurface(window); + Rodeo__begin(state); - SDL_FillRect( - screenSurface, - NULL, - SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF) - ); + bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Initialization and debug text."); - SDL_UpdateWindowSurface(window); - - SDL_Event e; - bool quit = false; - while(quit == false) - { - while(SDL_PollEvent(&e)) - { - if(e.type == SDL_QUIT) - { - quit = true; - } - } - } - } + Rodeo__end(state); } - SDL_DestroyWindow(window); - - SDL_Quit(); - - printf("number: %d\n", add(1, 3)); - printf("Hello World"); - + Rodeo__deinit_window(state); + Rodeo__quit(); return 0; } diff --git a/src/rodeo.c b/src/rodeo.c new file mode 100644 index 0000000..46ed014 --- /dev/null +++ b/src/rodeo.c @@ -0,0 +1,125 @@ +#include "SDL2/SDL.h" +#include "SDL2/SDL_syswm.h" +#include "bgfx/c99/bgfx.h" + +#include "rodeo.h" + +//static Rodeo__Data_t Rodeo__State = { 0 }; + +void +Rodeo__\ +init_window( + Rodeo__Data_t* state, + int screen_height, + int screen_width, + char* title + ) +{ + state->window = NULL; + state->screen_surface = NULL; + state->screen_height = screen_height; + state->screen_width = screen_width; + + if(SDL_Init(SDL_INIT_VIDEO) < 0) + { + printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + state->window = SDL_CreateWindow( + title, + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + screen_width, + screen_height, + SDL_WINDOW_SHOWN + ); + + if(state->window == NULL) + { + printf("Window could not be created! SDL_Error %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + SDL_VERSION(&state->wmi.version); + if( + !SDL_GetWindowWMInfo( + state->window, + &state->wmi + ) + ) + { + printf("SDL_Error %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + bgfx_render_frame(-1); + + bgfx_platform_data_t pd; + memset(&pd, 0, sizeof(bgfx_platform_data_t)); + + pd.ndt = state->wmi.info.x11.display; + pd.nwh = (void*)(uintptr_t)state->wmi.info.x11.window; + + bgfx_init_t init = {0}; + bgfx_init_ctor(&init); + init.type = BGFX_RENDERER_TYPE_COUNT; // auto determine renderer + init.resolution.width = state->screen_width; + init.resolution.height = state->screen_height; + init.resolution.reset = BGFX_RESET_VSYNC; + init.platformData = pd; + bgfx_init(&init); + + bgfx_reset(state->screen_width, state->screen_height, BGFX_RESET_VSYNC, init.resolution.format); + + bgfx_set_debug(BGFX_DEBUG_TEXT); + + bgfx_set_view_clear( + 0, + BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, + 0x443355FF, + 1.0f, + 0 + ); + bgfx_set_view_rect(0, 0, 0, state->screen_width, state->screen_height); + + bgfx_touch(0); + + bgfx_frame(false); +} + +void +Rodeo__\ +deinit_window(Rodeo__Data_t* state) +{ + bgfx_shutdown(); + SDL_DestroyWindow(state->window); +} + +void +Rodeo__\ +quit() +{ + SDL_Quit(); +} + +void +Rodeo__\ +begin(Rodeo__Data_t* state) +{ +} + +void +Rodeo__\ +end(Rodeo__Data_t* state) +{ + while(SDL_PollEvent(&state->sdl_event)) + { + if(state->sdl_event.type == SDL_QUIT) + { + state->quit = true; + } + } + bgfx_touch(0); + bgfx_frame(false); +} diff --git a/src/rodeo.h b/src/rodeo.h new file mode 100644 index 0000000..e468c11 --- /dev/null +++ b/src/rodeo.h @@ -0,0 +1,42 @@ +#include <stdbool.h> +#include "SDL2/SDL.h" +#include "SDL2/SDL_syswm.h" + +typedef +struct +Rodeo__\ +Data_t +{ + SDL_Window* window; + SDL_Surface* screen_surface; + SDL_SysWMinfo wmi; + int screen_width; + int screen_height; + SDL_Event sdl_event; + bool quit; +} Rodeo__Data_t; + +void +Rodeo__\ +init_window( + Rodeo__Data_t* state, + int screen_height, + int screen_width, + char* title + ); + +void +Rodeo__\ +deinit_window(Rodeo__Data_t* state); + +void +Rodeo__\ +quit(); + +void +Rodeo__\ +begin(Rodeo__Data_t* state); + +void +Rodeo__\ +end(Rodeo__Data_t* state); |
