#include <QtGui>
#include <QtOpenGL>
-#ifndef __APPLE__
+#ifdef Q_WS_MAC
+#include <OpenGL/glu.h>
+#else
#include <GL/glu.h>
#endif
#include "videoglwidget.h"
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);
}
return QSize(400, 300);
}
+void VideoGLWidget::setImageAspectRatio(double ratio)
+{
+ m_display_ratio = ratio;
+ resizeGL(width(), height());
+}
+
void VideoGLWidget::initializeGL()
{
qglClearColor(m_backgroundColor);
{
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
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) {
}
}
-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);
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();
}
event->accept();
}
+
+#include "videoglwidget.moc"