natinusala / borealis

Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx)
Apache License 2.0
260 stars 83 forks source link

[Question] Application example with video player #59

Closed H0neyBadger closed 3 years ago

H0neyBadger commented 3 years ago

Hello, First, thank you for your amazing work. I would like to move my current GUI to borealis. My objective is to delegate video to my core FFMPEG application. Currently, the app is using SDL2(audio, video, gamepad, touchscreen) as main interface (but I can switch video to opengl easily).

I'm experiencing with borealis' view (StagedApplet) and nvgluCreateFramebuffer. But I think I misunderstood the project philosophy. Could you please give me some hints on how to implement video "player" (best practices)

My question are the following: How to integrate/delegate raw OpenGL app in borealis (in fullscreen) ? Any suggestion for audio/gamepad/touchscreen ?

I also searched across others borealis project without success. Thank you a lot

natinusala commented 3 years ago

Hey, thanks for using borealis for your project!

You should create your own view, in which you draw the video using raw GL calls.

If you disable the frame pacer (using Application::setFramerate(0);), you can then assume that draw() is called as fast as possible in your view (as if it was a while true in which every loop iteration is a call to draw()).

For audio, you should use whatever is available (so audren, or you can keep SDL).

For inputs, what do you want to do? You can bind actions to the video player view, if that suits your needs.

H0neyBadger commented 3 years ago

Thank you a lot for these advises. I assume that you are talking about the setDisplayFramerate function. I keep a good note of it

Basically I think about the chiaki (ps4 remote play) port. From the application point of view it's just like an interactive video player. My problem with controls is I need every switch's inputs to translate ps4 controller.

I planned to use nvgluCreateFramebuffer to render video. unfortunately nanovg_gl_utils.h's symbols are not available through the borealis lib. I had to include the following line in borealis project.

diff --git a/library/lib/application.cpp b/library/lib/application.cpp
index bfbe2ff..305a8ba 100644
--- a/library/lib/application.cpp
+++ b/library/lib/application.cpp
@@ -42,6 +42,7 @@
 #include <glm/vec4.hpp>
 #define NANOVG_GL3_IMPLEMENTATION
 #include <nanovg_gl.h>
+#include <nanovg_gl_utils.h>

 #ifdef __SWITCH__
 #include <switch.h>

I know that I'm doing something wrong but I don't know exactly how to do it correctly. I m not familiar with nanovg nor low level OpenGL. That's why I'm asking good start advises. Feel free to close this issue at any time since it might be out of borealis scope. Thank you a lot ;-)

natinusala commented 3 years ago

Well I certainly think the issues you are having with OpenGL are out of scope. But I can help you integrare your GL stuff inside the library if you want. You have to insert your GL code after the nvgFrameEnd() call if you want to draw above the borealis UI.

I have a list of all the GL state you need to clear after ending the nvg frame and before drawing your stuff if you want.

Why did you need to change application.cpp? Keep in mind that you can use regular OpenGL, you don't need to use the nvglu functions.

Considering inputs, you might as well just use the hid sysmodule directly then.

H0neyBadger commented 3 years ago

awesome the nvgEndFrame(vg); seems to do the trick!

I take any info that you have to share (I just do not what to bother you too much).

I changed the application.cpp to have nvgluCreateFramebuffer symbols in lib. nvgluCreateFramebuffer code definition is under nanovg_gl_utils.h and NANOVG_GL3_IMPLEMENTATION. if I import it from my project, the compiler raise method redefinition error. if I don't, the linker raise an error for missing nvgluCreateFramebuffer definition. but this is pointless if I do not need nvglu* anymore.

regarding inputs. the following method looks good.

    /**
      * Blocks any and all user inputs
      */
    static void blockInputs();

I will continue to use SDL2 (and change of method if I found a better solution).

thank you very much

natinusala commented 3 years ago

Oh I see.

I'll close the issue, but we can keep the conversation going if you want