{
// Initialize new QImage to 8bit format
screenImage
= new QImage(desktop.
width(),desktop.
height(),
QImage::Format_Indexed8);
/* Initialize image array */
for (int i=0; i<BUFFERSIZE; i++) {
imageBuffer[i] = (unsigned char)(i % 256);
}
/* Start timer to repaintevent */
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
timer->start(10);
}
void GLWidget::animate()
{
update();
}
{
/* Memcopy pixel data into my QImage FRAMESIZE lines at a time */
for (int i=FRAMESIZE-1; i>=0; i--) {
memcpy(screenImage->scanLine(i),&imageBuffer[(imageLine*imageWidth)%BUFFERSIZE],imageWidth);
imageLine++;
}
// Draw the QImage to screen
painter.drawImage(0,0,*screenImage);
// Shift qimage down to look like it is streaming down the screen
memmove(screenImage->scanLine(FRAMESIZE),screenImage->scanLine(0),linesFilled*screenImage->bytesPerLine());
}
GLWidget::GLWidget(QGLWidget *parent)
:QGLWidget(parent)
{
// Initialize new QImage to 8bit format
screenImage = new QImage(desktop.width(),desktop.height(),QImage::Format_Indexed8);
/* Initialize image array */
for (int i=0; i<BUFFERSIZE; i++) {
imageBuffer[i] = (unsigned char)(i % 256);
}
/* Start timer to repaintevent */
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
timer->start(10);
}
void GLWidget::animate()
{
update();
}
void GLWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
/* Memcopy pixel data into my QImage FRAMESIZE lines at a time */
for (int i=FRAMESIZE-1; i>=0; i--) {
memcpy(screenImage->scanLine(i),&imageBuffer[(imageLine*imageWidth)%BUFFERSIZE],imageWidth);
imageLine++;
}
// Draw the QImage to screen
painter.drawImage(0,0,*screenImage);
// Shift qimage down to look like it is streaming down the screen
memmove(screenImage->scanLine(FRAMESIZE),screenImage->scanLine(0),linesFilled*screenImage->bytesPerLine());
}
To copy to clipboard, switch view to plain text mode
Bookmarks