]> git.sesse.net Git - kdenlive/blobdiff - src/videoglwidget.cpp
Fix Coverity #980702
[kdenlive] / src / videoglwidget.cpp
index cbe08e3838c19826384e6d1870fedbef15787535..af6527ad2191af451b93f1395b8d73af7d5c899d 100644 (file)
@@ -1,6 +1,11 @@
 
 #include <QtGui>
 #include <QtOpenGL>
+#ifdef Q_WS_MAC
+#include <OpenGL/glu.h>
+#else
+#include <GL/glu.h>
+#endif
 #include "videoglwidget.h"
 
 #ifndef GL_TEXTURE_RECTANGLE_EXT
 
 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);
 }
@@ -36,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);
@@ -48,6 +63,11 @@ void VideoGLWidget::initializeGL()
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 }
 
+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;
@@ -74,12 +94,26 @@ void VideoGLWidget::resizeGL(int width, int height)
     glLoadIdentity();
     gluOrtho2D(0, width, height, 0);
     glMatrixMode(GL_MODELVIEW);
-    glClear(GL_COLOR_BUFFER_BIT); // | GL_DEPTH_BUFFER_BIT // Depth is disabled, so shouldn'b be necessary to clear DEPTH_BUFFER
+    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) {
+#ifdef Q_WS_MAC
+               glClear(GL_COLOR_BUFFER_BIT);
+#endif
         glEnable(GL_TEXTURE_RECTANGLE_EXT);
         glBegin(GL_QUADS);
         glTexCoord2i(0, 0);
@@ -99,7 +133,6 @@ void VideoGLWidget::showImage(QImage image)
 {
     m_image_width = image.width();
     m_image_height = image.height();
-
     makeCurrent();
     if (m_texture)
         glDeleteTextures(1, &m_texture);