Skip to content

Instantly share code, notes, and snippets.

@alvatar
Last active December 2, 2019 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvatar/f3ae8053c643e7eb1379d49c98d73b03 to your computer and use it in GitHub Desktop.
Save alvatar/f3ae8053c643e7eb1379d49c98d73b03 to your computer and use it in GitHub Desktop.
BGFX OSX
#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(&currentEvent) != 0) {
if(currentEvent.type == SDL_QUIT) {
quit = true;
}
}
}
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();
return 0;
}
@alvatar
Copy link
Author

alvatar commented Dec 2, 2019

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00000001002f17ec libbgfx-shared-libDebug.dylib`bgfx::CallbackC99::traceVargs(this=0x000000010045b970, _filePath="../../../src/bgfx.cpp", _line=3393, _format="BGFX Init...\n", _argList=0x00007ffeefbff490) at bgfx.cpp:5260:4
    frame #1: 0x00000001002b775c libbgfx-shared-libDebug.dylib`bgfx::trace(_filePath="../../../src/bgfx.cpp", _line=3393, _format="BGFX Init...\n") at bgfx.cpp:451:16
    frame #2: 0x00000001002c8986 libbgfx-shared-libDebug.dylib`bgfx::init(_init=0x00007ffeefbff598) at bgfx.cpp:3393:3
    frame #3: 0x00000001002e5bd4 libbgfx-shared-libDebug.dylib`bgfx_init(_init=0x00007ffeefbff630) at bgfx.idl.inl:1198:9
    frame #4: 0x0000000100000daa main`main(argc=1, argv=0x00007ffeefbff788) at sdl.c:62:5
    frame #5: 0x00007fff6a4322e5 libdyld.dylib`start + 1
    frame #6: 0x00007fff6a4322e5 libdyld.dylib`start + 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment