X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fvideoglwidget.cpp;h=3da19948159ba2cb78ab9f571bfdb7e814c67f95;hb=c3302003093710ee247ad84c0fe2ef3c579d417f;hp=dffa495b6dab2829012ed0021f527a80816b2674;hpb=8ed5579a186a7dacf363c074b42be8997624f0da;p=kdenlive diff --git a/src/videoglwidget.cpp b/src/videoglwidget.cpp index dffa495b..3da19948 100644 --- a/src/videoglwidget.cpp +++ b/src/videoglwidget.cpp @@ -1,7 +1,11 @@ #include #include +#ifdef Q_WS_MAC +#include +#else #include +#endif #include "videoglwidget.h" #ifndef GL_TEXTURE_RECTANGLE_EXT @@ -10,12 +14,16 @@ VideoGLWidget::VideoGLWidget(QWidget *parent) : QGLWidget(parent) + , x(0) + , y(0) + , w(width()) + , h(height()) , m_image_width(0) , m_image_height(0) , m_texture(0) , m_display_ratio(4.0 / 3.0) , m_backgroundColor(Qt::gray) -{ +{ setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_OpaquePaintEvent); } @@ -37,6 +45,12 @@ QSize VideoGLWidget::sizeHint() const return QSize(400, 300); } +void VideoGLWidget::setImageAspectRatio(double ratio) +{ + m_display_ratio = ratio; + resizeGL(width(), height()); +} + void VideoGLWidget::initializeGL() { qglClearColor(m_backgroundColor); @@ -53,9 +67,9 @@ void VideoGLWidget::resizeEvent(QResizeEvent* event) { resizeGL(event->size().width(),event->size().height()); } + void VideoGLWidget::resizeGL(int width, int height) { - double this_aspect = (double) width / height; // Special case optimisation to negate odd effect of sample aspect ratio @@ -83,6 +97,17 @@ void VideoGLWidget::resizeGL(int width, int height) glClear(GL_COLOR_BUFFER_BIT); } +void VideoGLWidget::activateMonitor() +{ + makeCurrent(); + glViewport(0, 0, width(), height()); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, width(), height(), 0); + glMatrixMode(GL_MODELVIEW); + glClear(GL_COLOR_BUFFER_BIT); +} + void VideoGLWidget::paintGL() { if (m_texture) { @@ -104,11 +129,10 @@ void VideoGLWidget::paintGL() } } -void VideoGLWidget::showImage(QImage image) +void VideoGLWidget::showImage(const QImage &image) { m_image_width = image.width(); m_image_height = image.height(); - makeCurrent(); if (m_texture) glDeleteTextures(1, &m_texture); @@ -118,7 +142,7 @@ void VideoGLWidget::showImage(QImage image) glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture); glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA, + glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, image.bits()); updateGL(); } @@ -170,3 +194,5 @@ void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event) event->accept(); } + +#include "videoglwidget.moc"