Created
December 2, 2019 18:19
-
-
Save alvatar/5930b5680909c21035cba0826f289f90 to your computer and use it in GitHub Desktop.
bgfx OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SDL.h" | |
#include "SDL2/SDL_syswm.h" | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include "bgfx/c99/bgfx.h" | |
int main(int argc, char* argv[]) { | |
SDL_Window *window; // Declare a pointer | |
if(SDL_Init( SDL_INIT_VIDEO ) < 0) { | |
printf("SDL could not initialize! SDL_Error: %s\n", | |
SDL_GetError()); | |
exit(1); | |
} | |
// Create an application window with the following settings: | |
window = SDL_CreateWindow( | |
"An SDL2 window", // window title | |
SDL_WINDOWPOS_UNDEFINED, // initial x position | |
SDL_WINDOWPOS_UNDEFINED, // initial y position | |
640, // width, in pixels | |
480, // height, in pixels | |
SDL_WINDOW_SHOWN // flags - see below | |
); | |
// Check that the window was successfully created | |
if (window == NULL) { | |
// In the case that the window could not be made... | |
printf("Could not create window: %s\n", SDL_GetError()); | |
return 1; | |
} | |
SDL_SysWMinfo wmi; | |
SDL_VERSION(&wmi.version); | |
if (!SDL_GetWindowWMInfo(window, &wmi)) { | |
return 1; | |
} | |
bgfx_platform_data_t pd; | |
// and give the pointer to the window to pd | |
pd.nwh = wmi.info.cocoa.window; | |
pd.ndt = NULL; | |
pd.context = NULL; | |
pd.backBuffer = NULL; | |
pd.backBufferDS = NULL; | |
// Tell bgfx about the platform and window | |
bgfx_set_platform_data(&pd); | |
// Render an empty frame | |
bgfx_render_frame(-1); | |
bgfx_init_t bgfxInit; | |
//bgfxInit.type = BGFX_RENDERER_TYPE_COUNT; // Automatically choose a renderer. | |
//bgfxInit.resolution.width = 640; | |
//bgfxInit.resolution.height = 480; | |
//bgfxInit.resolution.reset = BGFX_RESET_VSYNC; | |
bgfx_init(&bgfxInit); | |
bgfx_set_debug(BGFX_DEBUG_TEXT /*| BGFX_DEBUG_STATS*/); | |
/* bgfx_set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0f, 0); */ | |
/* bgfx_set_view_rect(0, 0, 0, 640, 480); */ | |
/* printf("HI\n"); */ | |
/* unsigned int counter = 0; */ | |
/* while(true) { */ | |
/* bgfx_frame(false); */ | |
/* counter++; */ | |
/* printf("HI\n"); */ | |
/* } */ | |
// Poll for events and wait till user closes window | |
bool quit = false; | |
SDL_Event currentEvent; | |
while(!quit) { | |
while(SDL_PollEvent(¤tEvent) != 0) { | |
if(currentEvent.type == SDL_QUIT) { | |
quit = true; | |
} | |
} | |
} | |
// Close and destroy the window | |
SDL_DestroyWindow(window); | |
// Clean up | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment