OpenGL(角度)和#x2B;XAML(UWP)

OpenGL(角度)和#x2B;XAML(UWP),uwp,opengl-es,uwp-xaml,c++-cx,egl,Uwp,Opengl Es,Uwp Xaml,C++ Cx,Egl,我正在尝试在UWP XAML应用程序上运行OpenGL代码。 我找到了一些关于这方面的信息,但似乎没有什么能比得上完整的演练。 我是UPW、XAML和EGL的完全初学者,因此我从各种教程中创建了以下代码: #include <Windows.h> #include <EGL/egl.h> #include <GLES/gl.h> #include <angle_windowsstore.h> using namespace Windows::UI

我正在尝试在UWP XAML应用程序上运行OpenGL代码。 我找到了一些关于这方面的信息,但似乎没有什么能比得上完整的演练。 我是UPW、XAML和EGL的完全初学者,因此我从各种教程中创建了以下代码:

#include <Windows.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <angle_windowsstore.h>

using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Platform;
using Windows::ApplicationModel::SuspendingEventArgs;
using Windows::ApplicationModel::Activation::LaunchActivatedEventArgs;
using Windows::Foundation::Collections::PropertySet;
using Windows::Foundation::EventHandler;

static EGLint const openGlAttributes[] = {
    EGL_RED_SIZE, 1,
    EGL_GREEN_SIZE, 1,
    EGL_BLUE_SIZE, 1,
    EGL_NONE
};

ref class MyApp sealed : Application {
private:
    SwapChainPanel^ swapChainPanel;
    CoreWindow^ coreWindow;
    EGLDisplay display;
    EGLSurface surface;
    bool stopped;

public:
    MyApp() {
        stopped = false;
    }

    virtual void OnLaunched(LaunchActivatedEventArgs^ e) override {
        auto canvas = ref new Canvas();

        auto swapChainPanel = ref new SwapChainPanel();
        swapChainPanel->Width = 800;
        swapChainPanel->Width = 600;
        canvas->Children->Append(swapChainPanel);
        canvas->SetLeft(swapChainPanel, 0);
        canvas->SetTop(swapChainPanel, 0);


        Window::Current->Content = canvas;
        Window::Current->Activate();

        coreWindow = Window::Current->CoreWindow;
        InitGL(Window::Current);

        WeakReference selfRef(this);
        Suspending += ref new SuspendingEventHandler([selfRef](Object^ sender, SuspendingEventArgs^ args) {
            auto self = selfRef.Resolve<MyApp>();
            self->stopped = true;
        });
        Resuming += ref new EventHandler<Object^>([selfRef](Object^ sender, Object^ args) {
            auto self = selfRef.Resolve<MyApp>();
            self->stopped = false;
        });

        ScheduleRendering();
    }

private:

    void InitGL(Window^ window) {
        display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        eglInitialize(display, NULL, NULL);

        EGLConfig config;
        EGLint numConfig;
        eglChooseConfig(display, openGlAttributes, &config, 1, &numConfig);

        auto surfaceCreationProperties = ref new PropertySet();
        surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), swapChainPanel);

        auto context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
        surface = eglCreateWindowSurface(display, config, reinterpret_cast<EGLNativeWindowType>(surfaceCreationProperties), NULL);
        eglMakeCurrent(display, surface, surface, context);
    }

    void RenderScene() {
        glClearColor(1.0, 0, 0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glFlush();

        eglSwapBuffers(display, surface);

        ScheduleRendering();
    }

    void ScheduleRendering() {
        if (stopped) {
            return;
        }
        WeakReference selfRef(this);
        coreWindow->Dispatcher->RunIdleAsync(ref new IdleDispatchedHandler([selfRef](IdleDispatchedHandlerArgs^ args) {
            auto self = selfRef.Resolve<MyApp>();
            self->RenderScene();
        }));
    }
};

int main(Array<String^>^ args) {
    Application::Start(ref new ApplicationInitializationCallback([](ApplicationInitializationCallbackParams^ p) {
        ref new MyApp();
    }));
    return 0;
}
#包括
#包括
#包括
#包括,还是为我做这个
  • 我应该在空闲状态下执行渲染,还是有类似于绘制事件的功能

  • 看来我写的所有东西都正确初始化是错的。 此调用返回了
    EGL\u NO\u SOURCE

    eglMakeCurrent(显示、表面、表面、上下文);
    
    我想这是因为我们必须等待
    SwapChainPanel
    初始化,所以当我从
    SwapChainPanel
    Load
    事件调用
    eglMakeCurrent
    时,一切都开始工作了。 此外,还有一些事情是不明显的,比如
    swapChainPanel
    可能会意外地丢失GL上下文,因此当出现问题时,您必须重新创建它。
    我在微软的角度分叉中找到它,并用它作为灵感来源。

    我在VS2019中用C++创建了一个空白的应用程序,并从NuGET安装了“角度.WieldsSt店”,但仍然不能包含“”。你能告诉我你采取了哪些步骤来帮助我复制它吗?我没有从VS创建项目,而是我编写了CMakeLists.txt并从中生成了sln文件。我包括了vcpkg中的角度依赖性。