Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QT-OpenGL example now builds with Qt6 #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libmpv/qml/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QOpenGLContext>
#include <QGuiApplication>

#include <QtGui/QOpenGLFramebufferObject>
#include <QOpenGLFramebufferObject>

#include <QtQuick/QQuickWindow>
#include <QtQuick/QQuickView>
Expand Down Expand Up @@ -75,7 +75,7 @@ class MpvRenderer : public QQuickFramebufferObject::Renderer

void render()
{
obj->window()->resetOpenGLState();
obj->window()->beginExternalCommands();

QOpenGLFramebufferObject *fbo = framebufferObject();
mpv_opengl_fbo mpfbo{.fbo = static_cast<int>(fbo->handle()), .w = fbo->width(), .h = fbo->height(), .internal_format = 0};
Expand All @@ -95,7 +95,7 @@ class MpvRenderer : public QQuickFramebufferObject::Renderer
// other API details.
mpv_render_context_render(obj->mpv_gl, params);

obj->window()->resetOpenGLState();
obj->window()->endExternalCommands();
}
};

Expand Down Expand Up @@ -152,7 +152,7 @@ void MpvObject::setProperty(const QString& name, const QVariant& value)

QQuickFramebufferObject::Renderer *MpvObject::createRenderer() const
{
window()->setPersistentOpenGLContext(true);
window()->setPersistentGraphics(true);
window()->setPersistentSceneGraph(true);
return new MpvRenderer(const_cast<MpvObject *>(this));
}
Expand Down
8 changes: 4 additions & 4 deletions libmpv/qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Controls 2.0

import mpvtest 1.0

Expand All @@ -13,7 +13,7 @@ Item {

MouseArea {
anchors.fill: parent
onClicked: renderer.command(["loadfile", "test.mkv"])
onClicked: renderer.command(["loadfile", "C:/Users/Siddhant/Downloads/orig cut.mp4"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this as a generic test.mkv instead of a file on your own computer.

}
}

Expand Down Expand Up @@ -61,8 +61,8 @@ Item {
anchors.margins: 10
anchors.left: checkbox.left
anchors.right: checkbox.right
minimumValue: -100
maximumValue: 100
from: -100
to: 100
value: 0
onValueChanged: renderer.setProperty("gamma", slider.value | 0)
}
Expand Down
2 changes: 1 addition & 1 deletion libmpv/qml/mpvtest.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += qml quick
QT += qml quick quickcontrols2

HEADERS += main.h
SOURCES += main.cpp
Expand Down
45 changes: 45 additions & 0 deletions libmpv/qt_opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.16)
project(qt_opengl VERSION 1.0 LANGUAGES C CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui OpenGLWidgets)

find_package(PkgConfig REQUIRED)
pkg_check_modules(MPV REQUIRED IMPORTED_TARGET mpv)

qt_standard_project_setup()

qt_add_executable(qt_opengl WIN32 MACOSX_BUNDLE
main.cpp
mainwindow.cpp mainwindow.h
mpvwidget.cpp mpvwidget.h
)


target_include_directories(qt_opengl PUBLIC ${MPV_INCLUDE_DIRS})
target_compile_options(qt_opengl PUBLIC ${MPV_CFLAGS_OTHER})
#target_link_libraries(qt_opengl ${MPV_LIBRARIES})

target_link_libraries(qt_opengl
#PUBLIC {MPV_LIBRARIES}
PUBLIC PkgConfig::MPV
PRIVATE
Qt::Core
Qt::Gui
Qt::OpenGLWidgets
)


install(TARGETS qt_opengl
BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

qt_generate_deploy_app_script(
TARGET qt_opengl
FILENAME_VARIABLE deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file is unncessary. The .pro file should be updated instead.

3 changes: 2 additions & 1 deletion libmpv/qt_opengl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
// Qt sets the locale in the QApplication constructor, but libmpv requires
// the LC_NUMERIC category to be set to "C", so change it back.
setlocale(LC_NUMERIC, "C");
//setlocale(LC_NUMERIC, "C");
// Commented because it's not compiling on macOS
Comment on lines -9 to +10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use #ifndef Q_OS_MAC so that other platforms will work as expected. Don't comment out the correct way of running libmpv.

MainWindow w;
w.show();
return a.exec();
Expand Down
2 changes: 1 addition & 1 deletion libmpv/qt_opengl/mpvwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void MpvWidget::initializeGL()

void MpvWidget::paintGL()
{
mpv_opengl_fbo mpfbo{static_cast<int>(defaultFramebufferObject()), width(), height(), 0};
mpv_opengl_fbo mpfbo{static_cast<int>(defaultFramebufferObject()), (int) (width() * devicePixelRatio()), (int) (height() * devicePixelRatio()), 0};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use qreal dpr = devicePixelRatio() once and refer to that variable instead of calling devicePixelRatio twice.

Use new-style casts such as int(width()*dpr), not C-style casts.

int flip_y{1};

mpv_render_param params[] = {
Expand Down
4 changes: 2 additions & 2 deletions libmpv/qt_opengl/mpvwidget.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PLAYERWINDOW_H
#define PLAYERWINDOW_H

#include <QtWidgets/QOpenGLWidget>
#include <QOpenGLWidget>
#include <mpv/client.h>
#include <mpv/render_gl.h>
#include "../common/qthelper.hpp"
Expand All @@ -10,7 +10,7 @@ class MpvWidget Q_DECL_FINAL: public QOpenGLWidget
{
Q_OBJECT
public:
MpvWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
MpvWidget(QWidget *parent = 0, Qt::WindowFlags f = Qt::WindowFlags());
~MpvWidget();
void command(const QVariant& params);
void setProperty(const QString& name, const QVariant& value);
Expand Down
2 changes: 1 addition & 1 deletion libmpv/qt_opengl/qt_opengl.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG -= app_bundle
QT += widgets
QT += openglwidgets

QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig debug
Expand Down