Last active
December 2, 2019 23:31
-
-
Save alvatar/f3ae8053c643e7eb1379d49c98d73b03 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; | |
pd.nwh = wmi.info.cocoa.window; | |
bgfx_set_platform_data(&pd); | |
// Render an empty frame | |
bgfx_render_frame(-1); | |
bgfx_init_t bgfxInit; | |
bgfx_init(&bgfxInit); | |
// 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; | |
} |
Author
alvatar
commented
Dec 2, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment