I'm probably NOT the founder of the I.O.G.L.N.U.S.A.H.A.
Tthe International Open GL NEVER Ugonna SLEEP AGAIN ha ha ha Society.
Decided to go ahead and do the QOpenGLWindow on Strawberry.
Its worse than just the standalone program. Much more bugs. But the few that works are incredible. We are close. Here's what I've been messing around with my IogLnusaha association (I'm on Gnomes)
// Create and setup the QOpenGLWindow
auto *openGLWindow_ = new VisualizationOpenGLWidget(projectm_visualization_);
QSurfaceFormat format;
format.setVersion(3, 3); // Set OpenGL version to 3.3
format.setProfile(QSurfaceFormat::CoreProfile); // Use the core profile
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
openGLWindow_->setFormat(format);
openGLWindow_->resize(1280, 720); // Default size for the OpenGL window
// Wrap the QOpenGLWindow in a QWidget container
auto *glContainer = QWidget::createWindowContainer(openGLWindow_);
glContainer->setFocusPolicy(Qt::TabFocus);
glContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
glContainer->setParent(this);
glContainer->setVisible(true);
////////////setCentralWidget(glContainer);
// Add the overlay as a child of the container and set its visibility
////////////////overlay_->setParent(glContainer);
/////////////////overlay_->resize(320, 200); // Resize the overlay
//////////////////overlay_->setVisible(true);
}
#ifndef VISUALIZATIONOPENGLWIDGET_H
#define VISUALIZATIONOPENGLWIDGET_H
#include "config.h"
#include <QOpenGLWindow>
#include <QOpenGLFunctions>
class ProjectMVisualization;
class VisualizationOpenGLWidget : public QOpenGLWindow, protected QOpenGLFunctions {
Q_OBJECT
public:
explicit VisualizationOpenGLWidget(ProjectMVisualization* projectm_visualization, QWindow* parent = nullptr);
//explicit VisualizationOpenGLWidget(ProjectMVisualization *projectm_visualization, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
//explicit OpenGLWidgetContainer(QOpenGLWindow* openGLWindow, QWidget* parent = nullptr);
void initializeGL() override;
protected:
void paintGL() override;
void resizeGL(const int width, const int height) override;
private:
void Setup(const int width, const int height);
private:
ProjectMVisualization *projectm_visualization_;
};
#endif // VISUALIZATIONOPENGLWIDGET_H
.cpp
#include "config.h"
#include <QPainter>
#include "core/logging.h"
#include "visualizationopenglwidget.h"
#include "projectmvisualization.h"
VisualizationOpenGLWidget::VisualizationOpenGLWidget(ProjectMVisualization *projectm_visualization, QWindow *parent)
: QOpenGLWindow(NoPartialUpdate, parent),
projectm_visualization_(projectm_visualization) {
}
void VisualizationOpenGLWidget::initializeGL() {
QOpenGLWindow::initializeGL();
QOpenGLFunctions::initializeOpenGLFunctions();
projectm_visualization_->Init();
}
void VisualizationOpenGLWidget::paintGL() {
QPainter p(this);
//////////resizeGL(width(), height());
p.beginNativePainting();
projectm_visualization_->RenderFrame(width(), height());
p.endNativePainting();
update();
qLog(Debug) << __PRETTY_FUNCTION__ << glGetError();
}
void VisualizationOpenGLWidget::resizeGL(const int width, const int height) {
Setup(width, height);
projectm_visualization_->Resize(width, height);
}
void VisualizationOpenGLWidget::Setup(const int width, const int height) {
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 0);
glViewport(0, 0, width, height);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
glLineStipple(2, 0xAAAA);
}
ConsumeBuffer:
void ProjectMVisualization::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) {
Q_UNUSED(pipeline_id);
Q_UNUSED(format);
GstMapInfo map;
gst_buffer_map(buffer, &map, GST_MAP_READ);
#ifdef HAVE_PROJECTM4
if (projectm_instance_) {
const unsigned int samples_per_channel = static_cast<unsigned int> (map.size / sizeof(size_t)) / 2;
const int16_t *data = reinterpret_cast<int16_t*>(map.data);
projectm_pcm_add_int16(projectm_instance_, data, samples_per_channel, PROJECTM_STEREO);
}
#else
if (projectm_) {
const short samples_per_channel = static_cast<short>(map.size) / sizeof(short) / 2;
const short *data = reinterpret_cast<short*>(map.data);
projectm_->pcm()->addPCM16Data(data, samples_per_channel);
}
#endif // HAVE_PROJECTM4
gst_buffer_unmap(buffer, &map);
gst_buffer_unref(buffer);
}
InitprojectM
// Create projectM settings
#ifdef HAVE_PROJECTM4
Q_ASSERT(projectm_instance_ == nullptr);
Q_ASSERT(projectm_playlist_instance_ == nullptr);
projectm_instance_ = projectm_create();
projectm_set_preset_duration(projectm_instance_, duration_);
// Set initial window size
projectm_set_window_size(projectm_instance_, 1280, 720);
// Additional ProjectM setup
projectm_set_mesh_size(projectm_instance_, 32, 24);
projectm_set_fps(projectm_instance_, 60);
projectm_set_aspect_correction(projectm_instance_, true);
projectm_set_hard_cut_enabled(projectm_instance_, true);
projectm_set_hard_cut_duration(projectm_instance_, 10);
projectm_set_hard_cut_sensitivity(projectm_instance_, 1.0);
projectm_set_beat_sensitivity(projectm_instance_, 0.5);
projectm_set_soft_cut_duration(projectm_instance_, 10);
//projectm_set_window_size(projectm_instance_, 512, 512);
const char *texture_search_paths[] = { "/usr/local/share/projectM/textures" };
projectm_set_texture_search_paths(projectm_instance_, texture_search_paths, 1);
projectm_playlist_instance_ = projectm_playlist_create(projectm_instance_);
projectm_playlist_set_shuffle(projectm_playlist_instance_, false);
"patched" SetImmediatePreset (FOR TESTING, but works on v3)
void ProjectMVisualization::SetImmediatePreset(const int index) {
#ifdef HAVE_PROJECTM4
if (projectm_playlist_instance_) {
projectm_playlist_set_position(projectm_playlist_instance_, index, true);
/* projectm_playlist_play_previous(projectm_playlist_instance_, true);
projectm_set_preset_duration(projectm_instance_, 1);
projectm_set_preset_locked(projectm_instance_, false);
QTimer::singleShot(1500, this, [index,this]() {
projectm_set_preset_locked(projectm_instance_, true);
projectm_set_preset_duration(projectm_instance_, duration_);
}); */
}
#else
if (projectm_) {
projectm_->selectPreset(index, true);
}
#endif // HAVE_PROJECTM4
}
It appears that when it wraps to a QWidget, the shader codes don't like and start to stop doing its things. ITs not a matter of context, but its like a corruption happens when you wrap.
I could manage to bind key_S to open the visualizations selector, when setting as central, because I could not figure out why the overlay and interface don't work