Bladeren bron

V0.7
1、添加了使用OpenGL的demo

Apple 1 maand geleden
bovenliggende
commit
a0502c20a4
2 gewijzigde bestanden met toevoegingen van 31 en 13 verwijderingen
  1. 20 12
      demo/VideoPlayerGL/CMakeLists.txt
  2. 11 1
      demo/VideoPlayerGL/main.cpp

+ 20 - 12
demo/VideoPlayerGL/CMakeLists.txt

@@ -2,6 +2,8 @@
 
 set(this_exe PlayerGL)
 
+# 添加 OpenGL 和 Qt 配置选项
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_OPENGL_LIB -DQT_WIDGETS_LIB")
 
 #包含源文件
 file(GLOB LOCAL_SRC
@@ -54,34 +56,40 @@ target_include_directories(${this_exe} PRIVATE
     ${spdlog_INCLUDE_DIR}
 )
 
+find_package(OpenGL REQUIRED)
+
 target_link_libraries(${this_exe} PRIVATE
     Qt6::Widgets
     Qt6::Core
     Qt6::Network
+    Qt6::Gui
+    Qt6::OpenGL
     Qt6::OpenGLWidgets
-    # Qt5::Multimedia
-    # Qt5::Xml
-    # Qt5::Sql
+    ${OPENGL_LIBRARIES}
 )
 
+
+# 确保正确的 Qt 配置
+set(QT_QPA_PLATFORM "cocoa" CACHE STRING "Qt Platform")
+set(QT_QPA_PLATFORM_PLUGIN_PATH "${CMAKE_PREFIX_PATH}/plugins/platforms" CACHE STRING "Qt Platform Plugin Path")
+
 target_link_libraries(${this_exe} PRIVATE 
     # fmt::fmt
     # spdlog::spdlog
     # ${CURL_LIBRARY}
     # ${FFMPEG_LIBRARY}
     ${spdlog_LIBRARY}
-    # opengl32
-    # glu32
+    
 )
 
-# find_package(OpenGL REQUIRED)
-# target_link_libraries(${this_exe} PRIVATE ${OPENGL_LIBRARIES})
 
-if(CMAKE_CXX_COMPILER_VERSION LESS 9.0)
-    target_link_libraries(${this_exe} PRIVATE
-        stdc++fs
-    )
-endif()
+# if(CMAKE_CXX_COMPILER_VERSION LESS 9.0)
+#     target_link_libraries(${this_exe} PRIVATE
+#         stdc++fs
+#     )
+# endif()
+
+
 
 # target_link_libraries(${this_exe} PRIVATE
 #     GL

+ 11 - 1
demo/VideoPlayerGL/main.cpp

@@ -1,9 +1,11 @@
 #include "widget.h"
 
 #include <QApplication>
+#include <QSurfaceFormat>
 #include "Logs/loginit.h"
 #include "spdlog/spdlog.h"
 #include "FmtLog/fmtlog.h"
+#include <QProcessEnvironment>
 
 // extern "C" {
 // #include <libavcodec/avcodec.h>
@@ -15,9 +17,17 @@ int main(int argc, char *argv[])
     QApplication a(argc, argv);
     init_log();
 
-    SPDLOG_INFO("********** VideoPlayer **********");
+    // 设置 QT_QPA_PLATFORM 环境变量
+    qputenv("QT_QPA_PLATFORM", "cocoa");
 
+    QSurfaceFormat format;
+    format.setDepthBufferSize(24);
+    format.setStencilBufferSize(8);
+    format.setVersion(3, 3);
+    format.setProfile(QSurfaceFormat::CoreProfile);
+    QSurfaceFormat::setDefaultFormat(format);
 
+    SPDLOG_INFO("********** VideoPlayer **********");
 
     Widget w;
     w.show();