private static void InitObs() { try { Debug.WriteLine("libobs version: " + Obs.GetVersion()); // forward OBS logging messages to debugger Obs.SetLogHandler((lvl, msg, p) => { Debug.WriteLine(msg); }); if (!Obs.Startup("en-US")) throw new ApplicationException("Startup failed."); // initialize video libobs.obs_video_info ovi = new libobs.obs_video_info { adapter = 0, base_width = (uint)MainWidth, base_height = (uint)MainHeight, fps_num = 30000, fps_den = 1001, graphics_module = "libobs-d3d11", output_format = libobs.video_format.VIDEO_FORMAT_RGBA, output_width = (uint)MainWidth, output_height = (uint)MainHeight, }; if (!Obs.ResetVideo(ovi)) throw new ApplicationException("ResetVideo failed."); // initialize audio libobs.obs_audio_info avi = new libobs.obs_audio_info { samples_per_sec = 44100, speakers = libobs.speaker_layout.SPEAKERS_STEREO, //buffer_ms = 1000 }; if (!Obs.ResetAudio(avi)) throw new ApplicationException("ResetAudio failed."); // load all plugins and modules Obs.LoadAllModules(); } catch (BadImageFormatException exp) { MessageBox.Show("Platform target mismatch: " + (Environment.Is64BitProcess ? "Loading 32-bit OBS with 64-bit executable is not supported." : "Loading 64-bit OBS with 32-bit executable is not supported.") + "\n\n" + exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } }
private void RenderPreview(IntPtr data, uint cx, uint cy) { libobs.obs_video_info ovi = Obs.GetVideoInfo(); int newW = (int)cx; int newH = (int)cy; uint baseWidth = ovi.base_width; uint baseHeight = ovi.base_height; float previewAspect = (float)cx / cy; float baseAspect = (float)baseWidth / baseHeight; //calculate new width and height for source to make it fit inside the preview area if (previewAspect > baseAspect) { newW = (int)(cy * baseAspect); } else { newH = (int)(cx / baseAspect); } int centerX = ((int)cx - newW) / 2; int centerY = ((int)cy - newH) / 2; previewScale = (float)newW / baseWidth; GS.ViewportPush(); GS.ProjectionPush(); //setup orthographic projection of the whole scene to be presented on viewport GS.Ortho(0.0f, baseWidth, 0.0f, baseHeight, -100.0f, 100.0f); GS.SetViewport(centerX, centerY, newW, newH); //draw scene background ClearBackground(baseWidth, baseHeight); //render all visible sources Obs.RenderMainView(); //calculate bottom-right corner on scene space int right = (int)cx - centerX; int bottom = (int)cy - centerY; //ortho for the outer area which would normally not appear on scene GS.Ortho(-centerX, right, -centerY, bottom, -100.0f, 100.0f); GS.ResetViewport(); //render editing overlays RenderSceneEditing(data); GS.ProjectionPop(); GS.ViewportPop(); GS.LoadVertexBuffer(null); }
private Vector2 GetPositionInScene(Vector2 position) { libobs.obs_video_info ovi = Obs.GetVideoInfo(); int baseWidth = (int)ovi.base_width; int baseHeight = (int)ovi.base_height; int scaledWidth = (int)(Width / previewScale); int scaledHeight = (int)(Height / previewScale); int left = (scaledWidth - baseWidth) / 2; int top = (scaledHeight - baseHeight) / 2; return(new Vector2((int)((position.x / previewScale) - left), (int)((position.y / previewScale) - top))); }
private static void InitObs() { try { Debug.WriteLine("libobs version: " + Obs.GetVersion()); // forward OBS logging messages to debugger Obs.SetLogHandler((lvl, msg, p) => { Debug.WriteLine(msg); }); if (!Obs.Startup("en-US")) { throw new ApplicationException("Startup failed."); } // initialize video libobs.obs_video_info ovi = new libobs.obs_video_info { adapter = 0, base_width = (uint)MainWidth, base_height = (uint)MainHeight, fps_num = 30000, fps_den = 1001, graphics_module = "libobs-d3d11", output_format = libobs.video_format.VIDEO_FORMAT_RGBA, output_width = (uint)MainWidth, output_height = (uint)MainHeight, }; if (!Obs.ResetVideo(ovi)) { throw new ApplicationException("ResetVideo failed."); } // initialize audio libobs.obs_audio_info avi = new libobs.obs_audio_info { samples_per_sec = 44100, speakers = libobs.speaker_layout.SPEAKERS_STEREO, //buffer_ms = 1000 }; if (!Obs.ResetAudio(avi)) { throw new ApplicationException("ResetAudio failed."); } // load all plugins and modules Obs.LoadAllModules(); } catch (BadImageFormatException exp) { MessageBox.Show("Platform target mismatch: " + (FX35Helper.Is64BitProcess() ? "Loading 32-bit OBS with 64-bit executable is not supported." : "Loading 64-bit OBS with 32-bit executable is not supported.") + "\n\n" + exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } }
public static libobs.obs_video_info GetVideoInfo() { libobs.obs_video_info ovi = new libobs.obs_video_info(); bool ret = libobs.obs_get_video_info(ref ovi); if (!ret) throw new ApplicationException("obs_get_video_info failed"); return ovi; }