# libobs - need 'the big picture'.



## Steve Baker (Sep 22, 2015)

So I need to stream the output of a large/complex OpenGL application using libobs.

My plan (possibly naive) is to stick some kind of libobs initialization code into my initialization.  Then to maybe make some kind of an OBS API call every frame (maybe just before or just after my SwapBuffers call) and have everything magically stream someplace.

Given the lack of documentation - or any example programs that would give me "the big picture" here, I'm working to understand whether this is even The Right Thing or not...so;

1) I take an existing glfw program that renders a spinning cube.
2) I create my OpenGL rendering context, I make it current.
3) I do an obs_startup("en-US").
4) I populate an obs_video_info structure (using "libobs-opengl") and pass it into obs_reset_video().
5) I loop around rendering my spinning cube and swapping the buffers to display it.
6) At the end, I do obs_shutdown(), then close my window and exit.

I presume that I'll be able to figure out what I put inside the loop to grab video and stream it...but because I like to work carefully, I compile and run my program "as is" and run it...expecting good OBS initialisation, then a spinning cube (but no streaming until I write more code).

Both obs_* calls seem to work OK and return no errors.  I can see "libobs-opengl" being dlopen'ed successfully...but unfortunately, the next time I do an OpenGL buffer swap, the program crashes somewhere deep inside OpenGL...if I remove the obs_* calls, it all works OK - if I comment out the buffer swap, it runs to completion (but of course displays nothing) and exits cleanly.

So evidently the OBS stuff is somehow actively DOING SOMETHING to OpenGL in the initialization/reset stuff.  Given my 'big picture' concept - I can't guess what that might be.

Any ideas?


----------



## Steve Baker (Sep 22, 2015)

Hmmmm....if I wrap my graphics calls between an "obs_enter_graphics()" and an "obs_leave_graphics()" call, it doesn't crash anymore - but it's not displaying any picture either.


----------



## Steve Baker (Sep 22, 2015)

(I may answer all my own questions before anyone gets here to help!)

Evidently, OBS API requires that I do all of my rendering in a "draw callback"...this is pretty amazingly inconvenient...but it is what it is.

So now I have a basic "Hello World" program in OBS:

void myRenderingFunction ( void *params, uint32 cx, uint32 cy )
{
  obs_enter_graphics () ;
  ...draw stuff in OpenGL
  obs_leave_graphics () ;
}

int main ()
{
   ...Initialise my window ;
   ...Get an OpenGL rendering context ;
   obs_startup ( "en-US" ) ;
   ...Populate an obs_video_info structure ;
   obs_reset_video ( & myVIdeoInfo ) ;
   obs_add_draw_callback ( myRenderingFunction, 0 ) ;
   while ( the user isn't exiting the program ) /* Do Nothing */ ;
   obs_shutdown () ;
   ...Clean up my window ;
}

Everything runs and looks right...but how do I get a video stream out of this?


----------

