From dab0553d558dbfc7d95dfeff63b1eb20cf21da5c Mon Sep 17 00:00:00 2001 From: Dwayne Harris Date: Thu, 23 Sep 2021 20:45:27 -0400 Subject: [PATCH] WIP --- .gitignore | 88 +++++++++++++++++++++++++++++++ Makefile | 2 +- README.md | 11 ++++ main.c | 151 ++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 203 insertions(+), 49 deletions(-) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6aa9aa9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,88 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/macos,c +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,c + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# End of https://www.toptal.com/developers/gitignore/api/macos,c diff --git a/Makefile b/Makefile index ea75145..11c8035 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: build build: - gcc -Wall main.c -lobs -lglut -lGL -o main + gcc -Wall main.c -lobs -lglut -lGL `pkg-config --cflags --libs gtk4` -o main run: build ./main diff --git a/README.md b/README.md new file mode 100644 index 0000000..841aaf9 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# obs-sample + + +### Install Dependencies + +`apt install libobs-dev libgtk-3-dev libsimde-dev mesa-common-dev freeglut3-dev` + + +### Build and Run + +`make run` diff --git a/main.c b/main.c index c97cb9f..7d94585 100644 --- a/main.c +++ b/main.c @@ -1,59 +1,114 @@ #include #include +#include +#include #include -void render() { - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT); - glFlush(); +const int window_width = 1280; +const int window_height = 720; +Window xw; + +void +print_obs_version_string() +{ + const char* version = obs_get_version_string(); + printf("OBS version: %s\n", version); } -int main(int argc, char** argv) { - const char* version; +void +obs_render (void* param, + uint32_t cx, + uint32_t cy) +{ + obs_render_main_texture (); +} - version = obs_get_version_string(); - printf("OBS version: %s\n", version); +static void +activate (GtkApplication* app, + gpointer user_data) +{ + GtkWidget* window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW(window), "OBS"); + gtk_window_set_default_size (GTK_WINDOW(window), window_width, window_height); + gtk_window_present (GTK_WINDOW(window)); + xw = gdk_x11_window_get_xid (gtk_widget_get_window(window)); +} + +void +render_sources(GtkApplication* app) +{ + GtkWidget* window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW(window), "OBS - Sources"); + gtk_window_set_default_size (GTK_WINDOW(window), 500, 500); + gtk_window_present (GTK_WINDOW(window)); +} + +int +main(int argc, char** argv) +{ + GtkApplication* app; + obs_display_t* display; + int status; + + app = gtk_application_new("xyz.dwayne.obs", G_APPLICATION_FLAGS_NONE); + g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); + + print_obs_version_string(); - if (!obs_initialized()) { - if (!obs_startup("en-US", NULL, NULL)) { - printf("Failed to start OBS...\n"); - return 1; + if (!obs_initialized()) + { + if (!obs_startup("en-US", NULL, NULL)) + { + printf("Failed to start OBS...\n"); + return 1; + } + + glutInit(&argc, argv); + + struct obs_video_info v; + struct obs_audio_info a; + + v.graphics_module = "libobs-opengl.so.0"; + v.fps_num = 30000; + v.fps_den = 1001; + v.base_width = window_width; + v.base_height = window_height; + v.output_width = window_width; + v.output_height = window_height; + v.output_format = VIDEO_FORMAT_NV12; + v.adapter = 0; + v.gpu_conversion = true; + v.colorspace = VIDEO_CS_601; + v.range = VIDEO_RANGE_PARTIAL; + v.scale_type = OBS_SCALE_BICUBIC; + + a.samples_per_sec = 44100; + a.speakers = SPEAKERS_STEREO; + + obs_reset_video (&v); + obs_reset_audio (&a); } - glutInit(&argc, argv); - - struct obs_video_info v; - struct obs_audio_info a; - - v.graphics_module = "libobs-opengl.so.0"; - v.fps_num = 30000; - v.fps_den = 1001; - v.base_width = 1280; - v.base_height = 720; - v.output_width = 1280; - v.output_height = 720; - v.output_format = VIDEO_FORMAT_NV12; - v.adapter = 0; - v.gpu_conversion = true; - v.colorspace = VIDEO_CS_601; - v.range = VIDEO_RANGE_PARTIAL; - v.scale_type = OBS_SCALE_BICUBIC; - - a.samples_per_sec = 44100; - a.speakers = SPEAKERS_STEREO; - - obs_reset_video(&v); - obs_reset_audio(&a); - } - - glutInitDisplayMode(GLUT_SINGLE); - glutInitWindowSize(500, 500); - glutInitWindowPosition(100, 100); - glutCreateWindow("OBS Window"); - glutDisplayFunc(render); - glutMainLoop(); - - obs_shutdown(); - - return 0; + // struct gs_init_data info; + // info.cx = window_width; + // info.cy = window_height; + // info.window = NULL; // xw?? + // info.format = GS_BGRA; + // info.zsformat = GS_ZS_NONE; + + // display = obs_display_create (&info, 0); + // if (display == NULL) + // { + // printf("error creating display!\n"); + // } + + // obs_display_add_draw_callback (display, obs_render, NULL); + + status = g_application_run (G_APPLICATION (app), argc, argv); + + // obs_display_destroy (display); + obs_shutdown (); + g_object_unref (app); + + return status; }