mirror of
https://github.com/lostjared/Acid.Cam.v2.Qt.git
synced 2025-12-05 22:40:16 +01:00
got video working with gl
This commit is contained in:
@@ -30,13 +30,13 @@ void DisplayWindow::createControls() {
|
||||
img_label->setGeometry(0,0,640, 480);
|
||||
}
|
||||
void DisplayWindow::displayImage(const QImage &img) {
|
||||
gl_display->setNewFrame(img);
|
||||
QRect src(QPoint(0, 0), size());
|
||||
gl_display->setNewFrame(img.copy());
|
||||
/*QRect src(QPoint(0, 0), size());
|
||||
QPixmap p = QPixmap::fromImage(img).scaled(size(),Qt::KeepAspectRatio, Qt::FastTransformation);
|
||||
QRect dst(QPoint(0,0),p.size());
|
||||
dst.moveCenter(src.center());
|
||||
img_label->setGeometry(dst);
|
||||
img_label->setPixmap(p);
|
||||
img_label->setPixmap(p); */
|
||||
}
|
||||
|
||||
void DisplayWindow::paintEvent(QPaintEvent *) {
|
||||
|
||||
@@ -13,7 +13,7 @@ glDisplayWindow::glDisplayWindow(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_animating(false)
|
||||
, m_context(0)
|
||||
, m_device(0)
|
||||
, m_device(0), updated(false)
|
||||
{
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
}
|
||||
@@ -27,6 +27,8 @@ void glDisplayWindow::render(QPainter *painter) {
|
||||
}
|
||||
|
||||
void glDisplayWindow::initialize() {
|
||||
resize(1280, 720);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glClearDepth(1.0f);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@@ -35,35 +37,61 @@ void glDisplayWindow::initialize() {
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void glDisplayWindow::setNewFrame(const QImage &new_one) {
|
||||
frame_copy = new_one;
|
||||
void glDisplayWindow::setNewFrame(QImage image) {
|
||||
frame = image;
|
||||
updated = true;
|
||||
}
|
||||
|
||||
unsigned int texID;
|
||||
void glDisplayWindow::updateTexture(QImage image) {
|
||||
static int lazy = 0;
|
||||
QImage new_one = image.mirrored();
|
||||
if(lazy == 0) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glGenTextures(1, &tex);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, new_one.width(), new_one.height(), 0, GL_BGR, GL_UNSIGNED_BYTE, new_one.bits());
|
||||
lazy = 1;
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, new_one.width(), new_one.height(), GL_BGR, GL_UNSIGNED_BYTE, new_one.bits());
|
||||
}
|
||||
}
|
||||
|
||||
void glDisplayWindow::render() {
|
||||
|
||||
if (!m_device)
|
||||
m_device = new QOpenGLPaintDevice;
|
||||
if(frame_copy.width()>100 && isVisible()) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
float aspect=(float)width()/(float)height();
|
||||
|
||||
if(width() <= height())
|
||||
glOrtho ( -5.0, 5.0, -5.0/aspect, 5.0/aspect, -5.0, 5.0);
|
||||
else
|
||||
glOrtho (-5.0*aspect, 5.0*aspect, -5.0, 5.0, -5.0, 5.0);
|
||||
if(frame_copy.width() > 25 && frame_copy.height() > 25) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glDrawPixels(frame_copy.width(), frame_copy.height(), GL_RGB,GL_UNSIGNED_BYTE,(unsigned char*)frame_copy.bits());
|
||||
glFlush();
|
||||
}
|
||||
|
||||
if(updated == true && frame.width()>100 && frame.height()>100) {
|
||||
updateTexture(frame);
|
||||
updated = false;
|
||||
}
|
||||
m_device->setPaintFlipped(true);
|
||||
m_device->setSize(size() * devicePixelRatio());
|
||||
m_device->setDevicePixelRatio(devicePixelRatio());
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 1280, 0, 720, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2i(0, 0); glVertex2i(0, 0);
|
||||
glTexCoord2i(0, 1); glVertex2i(0, 720);
|
||||
glTexCoord2i(1, 1); glVertex2i(1280, 720);
|
||||
glTexCoord2i(1, 0); glVertex2i(1280, 0);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
//m_device->setSize(size() * devicePixelRatio());
|
||||
//m_device->setDevicePixelRatio(devicePixelRatio());
|
||||
QPainter painter(m_device);
|
||||
render(&painter);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public:
|
||||
virtual void initialize();
|
||||
|
||||
void setAnimating(bool animating);
|
||||
void setNewFrame(const QImage &image);
|
||||
|
||||
void setNewFrame(QImage image);
|
||||
void updateTexture(QImage image);
|
||||
public slots:
|
||||
void renderLater();
|
||||
void renderNow();
|
||||
@@ -37,9 +37,11 @@ protected:
|
||||
|
||||
private:
|
||||
bool m_animating;
|
||||
QImage frame_copy;
|
||||
QOpenGLContext *m_context;
|
||||
QOpenGLPaintDevice *m_device;
|
||||
GLuint tex;
|
||||
QImage frame;
|
||||
bool updated;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user