diff options
Diffstat (limited to 'src')
| -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 |
4 files changed, 182 insertions, 53 deletions
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); |
